I have a pdf document that contain pages of different orientation. I'm trying to add logo to all pages in a range and it's placed correctly only on the pages that have the same dimensions as the first one. I presume this has something to do with the PdfFileStamp object. It seems that it assume that all pages have the same dimensions as the first one (It occures so because of its PageHight and PageWidth properties).
If you want to add stamp on a PDF file containing pages with different orientations then you’ll have to loop through all the pages and then add the stamp on each page according to its particular size. You may find a related code snippet on this link.
I help this helps. If you have any further questions, please do let us know. Regards,
This didn't solve the problem unfortunately. I use the same exact way to apply the watermark on pages, except that I use a logo instead of an image. The watermarks are placed in the same location on all of the pages as if the stamp origin was taken from the first page. Here is the code I'm using:
public MemoryStream ApplyTextWatermark(Watermark watermark, int[] pages) { Stream outputStream = new MemoryStream(); PdfFileStamp stamper = new PdfFileStamp(_pdfFile.InputStream, outputStream); Stamp stamp = null; foreach (int pageNumber in pages) { stamp = PrepareStamp(watermark, pageNumber); stamper.AddStamp(stamp); } stamper.Close(); return (MemoryStream)outputStream; }
private Stamp PrepareStamp(Watermark watermark, int pageNumber) { Stamp stamp = new Stamp(); stamp.Pages = new int[] { pageNumber }; stamp.IsBackground = watermark.IsBackground; stamp.Opacity = watermark.Opacity;
FormattedText logo = new FormattedText(watermark.Text, watermark.FontColor, watermark.Font, EncodingType.Winansi, false, fontSize); stamp.BindLogo(logo);
Please share the PDF file you’re trying to add the stamp to, so we could investigate the issue at our end. Also, please mention the .NET framework version you’re using at your end. We’ll look into this problem and guide you accordingly.