PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Apr 24, 2024 7:17 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Issue with Watermark
PostPosted: Thu Mar 06, 2008 1:48 pm 
Offline
User avatar

Joined: Thu Mar 06, 2008 11:30 am
Posts: 10
Location: Tech-Tips-Now.com
Hi,

Today I downloaded PDFsharp and was trying to add watermark to PDFs. However, it works on few PDFs (which is supplied as sample PDFs) but not on the PDFs I use.

Please check the PDF:

rapidshare.com/files/97482847/13.zip

I tried that PDF with the sample code provided in PDFSharp (watermark). I haven't changed any code except the PDF file name. If I use the PDFs supplied with samples it works fine not with the file I use. I also copied my PDF to the PDFs folder.

It doesn't throw any error.

Please let me know how to fix the problem at the earliest.

Thank you

_________________
Subi


Top
 Profile  
Reply with quote  
 Post subject: Re: Issue with Watermark
PostPosted: Thu Mar 06, 2008 2:06 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
dpsubi1 wrote:
Today I downloaded PDFsharp and was trying to add watermark to PDFs. However, it works on few PDFs (which is supplied as sample PDFs) but not on the PDFs I use.

What you say ain't true - it's working as intended and it works with your document, too.
Just look at page 3 - there is a watermark.

The Watermark sample shows three different methods of adding watermarks. On pages 1 and 2 these watermarks are below the page contents. Since the pages in your document have no transparent areas, the watermarks are not visible.
Page 3 draws the watermark on top of the contents - this works with your file, too.

Create documents with transparent pages or use method 3 to add watermarks.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 06, 2008 2:09 pm 
Offline
User avatar

Joined: Thu Mar 06, 2008 11:30 am
Posts: 10
Location: Tech-Tips-Now.com
I do not know how to create pdf with transparent areas (not sure what it means). I just created PDFs with Acrobat 6.0

I will give a try with 3rd method and will let you know.

Thanks for your immediate help.

_________________
Subi


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 06, 2008 2:29 pm 
Offline
User avatar

Joined: Thu Mar 06, 2008 11:30 am
Posts: 10
Location: Tech-Tips-Now.com
Thanks a lot. It worked great :D

_________________
Subi


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 10, 2008 8:43 am 
Offline
User avatar

Joined: Thu Mar 06, 2008 11:30 am
Posts: 10
Location: Tech-Tips-Now.com
Hello,

Thanks for fixing my previous problem.

it worked great. I have been using the third method as you said.

Now i was trying to add the watermark on landscape page. however once the output is generated the page is cut off.

please try the files from the link and use the third method to replicate the problem.

rapidshare.com/files/98386054/14-15.zip

I am not sure how i can fix this problem.

please help.

thanks

_________________
Subi


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Mar 11, 2008 5:50 pm 
Offline

Joined: Tue Mar 11, 2008 5:39 pm
Posts: 2
I dont know very much about this libary (started yesterday with it), but maybe I can help you anyway.

Have you tried to turn your pdf-page before watermarking it?

Something like this:

if (page.Orientation == PdfSharp.PageOrientation.Landscape)
{
page.Orientation = PdfSharp.PageOrientation.Portrait;
}

But dont forget to turn it back again after you have added the watermark. If I understood you wrong please post again.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Mar 12, 2008 1:51 am 
Offline
User avatar

Joined: Thu Mar 06, 2008 11:30 am
Posts: 10
Location: Tech-Tips-Now.com
nope. It doesn't work. I already tried.

Thanks anyway.

_________________
Subi


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 26, 2008 2:56 am 
Offline

Joined: Thu Jun 26, 2008 2:34 am
Posts: 1
Hi,

Ran into this same issue - watermarking an existing pdf with mixed portrait & landscape pages.

One quick solution is to rotate each landscape page, eg:
Code:
page.Orientation = PdfSharp.PageOrientation.Portrait;
page.Rotate = 0;

I also managed to get to the source of the problem, the following workaround allowed me to retain the rotated landscape pages as they were in the original document. The page.Size property was undefined for each page, and it needs to be set with the current PageSize value for the landscape pages to be saved correctly. A quick-fix function to find the correct PageSize value for the given page is:
Code:
 private void SetPageSize(PdfPage page)
{
    PageSize result = PageSize.Undefined;

    PageSize[] pageSizes = (PageSize[])Enum.GetValues(typeof(PageSize));
    foreach (PageSize pageSize in pageSizes)
    {
        if (pageSize == PageSize.Undefined)
            continue;

        try
        {
            XSize size = PageSizeConverter.ToSize(pageSize);
            if (page.Orientation == PageOrientation.Portrait)
            {
                if (size.Width == page.Width.Point && size.Height == page.Height.Point)
                {
                    result = pageSize;
                    break;
                }
            }
            else
            {
                if (size.Width == page.Height.Point && size.Height == page.Width.Point)
                {
                    result = pageSize;
                    break;
                }
            }
        }
        catch
        {
            //swallow argument exception - the PageSizeConverter does not define an actual size for this PageSize (eg. PageSize.Undefined)
        }
    }
    if (result != PageSize.Undefined)
        page.Size = result;
}

And call this function at the end of the watermarking loop passing the current page. I call it at the end of the loop as setting the page.Size property modifies the page rectangle, and this can mess up the page size if you call it at the start of the loop.

I think this qualifies as a bug - the saving of pages is dependent on the current page.Size value, but the value is not set when pages are loaded in - when the Size is Undefined, it seems like it defaults to Portrait sizes.

hth,

woody


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 218 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group