View previous topic :: View next topic |
Author |
Message |
dpsubi1
Joined: 06 Mar 2008 Posts: 10 Location: Tech-Tips-Now.com
|
Posted: Thu Mar 06, 2008 1:48 pm Post subject: Issue with Watermark |
|
|
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 |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Thu Mar 06, 2008 2:06 pm Post subject: Re: Issue with Watermark |
|
|
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 |
|
Back to top |
|
|
dpsubi1
Joined: 06 Mar 2008 Posts: 10 Location: Tech-Tips-Now.com
|
Posted: Thu Mar 06, 2008 2:09 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
dpsubi1
Joined: 06 Mar 2008 Posts: 10 Location: Tech-Tips-Now.com
|
Posted: Thu Mar 06, 2008 2:29 pm Post subject: |
|
|
Thanks a lot. It worked great _________________ Subi |
|
Back to top |
|
|
dpsubi1
Joined: 06 Mar 2008 Posts: 10 Location: Tech-Tips-Now.com
|
Posted: Mon Mar 10, 2008 8:43 am Post subject: new problem with landscape pages |
|
|
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 |
|
Back to top |
|
|
trih
Joined: 11 Mar 2008 Posts: 2
|
Posted: Tue Mar 11, 2008 5:50 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
dpsubi1
Joined: 06 Mar 2008 Posts: 10 Location: Tech-Tips-Now.com
|
Posted: Wed Mar 12, 2008 1:51 am Post subject: |
|
|
nope. It doesn't work. I already tried.
Thanks anyway. _________________ Subi |
|
Back to top |
|
|
woody3k
Joined: 26 Jun 2008 Posts: 1
|
Posted: Thu Jun 26, 2008 2:56 am Post subject: |
|
|
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 |
|
Back to top |
|
|
|