Subject: Watermarking each page in a loaded PDF document sometimes blanks pages in the document (Except the watermark)
Date: 2020-02-27 17:55:31
From: Lonnie Watson
Source: watermarking-page-loaded-pdf-document-sometimes-blanks-pages-document-except-watermark
----------------------------------------------------------------------

I am iterating over each page in a loaded PDF document using the latest version of the PDF library.

    foreach (PdfPageBase lPage in lDoc.Pages)
    {
    try
      {   
       PdfGraphics g = lPage.Graphics;
       PdfGraphicsState state = g.Save();

       var pw = lPage.Graphics.Size.Width;
       var ph = lPage.Graphics.Size.Height;

       var ss = font.MeasureString(stampText);

       var dx = pw - ss.Height - 5;
       var dy = (ph - ss.Width   5);

       g.SetTransparency(0.25f);
       g.RotateTransform(-90);

       g.DrawString(stampText, font, PdfPens.Red, PdfBrushes.Red, new PointF(-(ss.Width   ss.Height), ss.Height / 2));

       g.Restore(state);

       cpage  = 1;
      }
      catch (Exception ex)
      {
         //Do Something here                           
      }
}
 
On some document however The contents of the page get wiped and all I am left with is the watermark...

I have tried all manner of things in this code to glean the differences between pages that wipe and the pages that do not wipe... and have not been able to find the reason for this. Has anyone else run into this issue.  

BTW with an earlier version of this library I would get NULL REFERENCE EXCEPTIONS on some of the pages in some documents. With the current library the Catch never gets entered but some pages still exhibit this blanking behavior

----------------------------------------------------------------------

Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand
If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor
who sold you the license and ask for your money back.

Back to ComponentPro Q&A Forum Index