PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Image Watermark
http://forum.pdfsharp.de/viewtopic.php?f=2&t=373
Page 1 of 1

Author:  cschrenk [ Wed Apr 16, 2008 10:05 am ]
Post subject:  Image Watermark

Hello,

I need your help :)

We get invoices from a customer in PDF format and need to add images (in German: Falzmarken) on the pages. A cutter reads those images and cuts the invoices at specific points. The printer works with continous paper and the cutter cuts the single pages.

My problem is that I cannot simply add images to a specific existing page without creating a new page. Maybe I do something wrong, but whenever I try to add something to an existing PDF, PDFSharp creates a new page.

I tried watermarking. With text it works fine, but with images it compiles and the output PDF is the same as the input PDF.


The questions are:
- (How) is it possible to do watermarking with images at a specific position and page?
- (How) is it possible to add images to existing pages without adding new pages?

Thanks in advance!

Christoph

Author:  Thomas Hoevel [ Mon Apr 21, 2008 2:23 pm ]
Post subject: 

Hello!

I'm not sure what's the problem.

Adding watermarks to an existing file is quite simple:
Code:
PdfDocument document = PdfReader.Open(pdfFileName);
foreach (PdfPage page in document.Pages)
{
  XGraphics gfx = XGraphics.FromPdfPage(page);
[... do some drawing here ...]
}
document.Save(pdfFileName);


HTH

Author:  sam [ Tue Nov 02, 2010 6:22 pm ]
Post subject:  Re: Image Watermark

[code][/code]

Author:  Thomas Hoevel [ Wed Nov 03, 2010 8:40 am ]
Post subject:  Re: Image Watermark

sam wrote:
PDF is showing the image which looks so bad with few errors. Please help me.

If it looks bad, make it look good.

Or serious: how do you expect anybody to help you with the information you provide?
No image, no PDF, no error messages ...

Author:  sam [ Wed Nov 03, 2010 2:02 pm ]
Post subject:  Re: Image Watermark

Thomas,

I tried attaching doc file with error message and it says extension is not allowed and wasn't sure how to show that screen shot.

Anyways now my watermark is working but the problem is it is showing Assersion failed error. If I click the ignore button on it (almost 4 times) my PDF is opening up with the watermark.

Message is Object type transformation must not be done with direct objects.

Author:  Thomas Hoevel [ Wed Nov 03, 2010 2:15 pm ]
Post subject:  Re: Image Watermark

sam wrote:
Message is Object type transformation must not be done with direct objects.

You can ignore that message (you can comment that Debug.Assert out).

You can attach images and ZIP files.

You can paste text into the message (e. g. using Quote or Code tags).

Author:  sam [ Wed Nov 03, 2010 3:00 pm ]
Post subject:  Re: Image Watermark

Thanks.

Author:  sam [ Thu Nov 04, 2010 4:56 am ]
Post subject:  Re: Image Watermark

Hi,
I am trying to add jpeg images to header and footer in migradoc.
I know how to scale the img. In pdfsharp using xgraphics and ximage. But not sure how to do in migradoc.

Thanks in advance for your reply.

Author:  Thomas Hoevel [ Thu Nov 04, 2010 8:15 am ]
Post subject:  Re: Image Watermark

sam wrote:
But not sure how to do in migradoc.

When using MigraDoc, you specify the position, Width and Height.

Author:  sam [ Thu Nov 04, 2010 1:54 pm ]
Post subject:  Re: Image Watermark

I tried this. I can see the Image but the resolution is not good enough. Same case with the footer too. Is tehre a way that we can measure height and width width out loosing its resolution like the way we do in pdfsharp.

Code:
 Paragraph paragraph = section.Headers.Primary.AddParagraph();
            string HeaderPage1 =@"c/files/Images/header.jpeg";
            Image HeaderImage = section.Headers.Primary.AddImage(HeaderPage1);
             HeaderImage.RelativeHorizontal = RelativeHorizontal.Margin;
            HeaderImage.RelativeVertical = RelativeVertical.Margin;
            HeaderImage.LockAspectRatio = false;
            HeaderImage.ScaleWidth = 0.8;
           // HeaderImage.Height = new Unit(500, UnitType.Point);
          //  HeaderImage.Width = new Unit(500, UnitType.Point);
           // HeaderImage.Height = new Unit(15, UnitType.Centimeter);
            HeaderImage.Top = ShapePosition.Top;
            HeaderImage.Left = ShapePosition.Center;
            HeaderImage.WrapFormat.Style = WrapStyle.Through;
            paragraph.Format.Alignment = ParagraphAlignment.Center;


Thanks,

Author:  Thomas Hoevel [ Thu Nov 04, 2010 2:32 pm ]
Post subject:  Re: Image Watermark

sam wrote:
I can see the Image but the resolution is not good enough.

The image is used unaltered with all its pixels. Resolution depends on the size you draw it.
If you don't specify size then AFAIK size will be determined from the resolution.

Sorry, but I have no idea what your problem is.

Author:  sam [ Thu Nov 04, 2010 2:57 pm ]
Post subject:  Re: Image Watermark

Thomas,

I used the same code that showed you above and getting the PDF that I attached. Please compare 1st and 2nd page. The Image is not clear in the 1st one. Iam generating the 1st one and the 2nd page is the uploaded file from DB. You can also check the footer on the 1st page which is not clear.

Thanks

Author:  Thomas Hoevel [ Thu Nov 04, 2010 3:24 pm ]
Post subject:  Re: Image Watermark

sam wrote:
Please compare 1st and 2nd page. The Image is not clear in the 1st one.

The pig on the second page has a higher resolution than the pig on the first page (DPI is double, so there are four times as many pixels).

Text in a bitmap looks ugly when you zoom in, text in PDF will always be smooth even at 6400 % zoom.

The Partner logo on the second page also has a higher resolution than the logo on the first page. So it seems you're comparing a page that PDFsharp created from low resolution images with a page that was created from higher resolution images. You can't blame that on PDFsharp.

Adobe's smoothing made no difference on my computer, so I presume this thread is completely unrelated:
viewtopic.php?p=2459#p2459

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/