My base language is C#. I am using PdfSharp 1.31 to draw header and footer on every page of the document. Header consists of line and string, footer consists of line and image.
Here's how I am looping through every page and drawing the header and footer.
Code:
PdfDocument doc = PdfSharp.Pdf.IO.PdfReader.Open(path);
foreach (PdfPage page in doc.Pages)
{
XUnit pageWidth = page.Width;
XUnit pageHeight = page.Height;
XUnit headerLine = 50;
XUnit footerLine = pageHeight - 50;
XGraphics gfx = XGraphics.FromPdfPage(page);
// header
gfx.DrawLine(pen, 15, headerLine , pageWidth - 15, headerLine );
gfx.DrawString(productName, fontReportHeader, brush, 15, 35, XStringFormat.Default); //productName is a string variable
// footer
gfx.DrawLine(pen, 15, footerLine , pageWidth, footerLine);
gfx.DrawImage(imgLogo, pageWidth - imageWidth - 15, pageHeight - 49); // imgLogo is a XImage variable, imgWidth is imgLogo.PointWidth variable
)
doc.Save(path);
When I run this application, I get a warning as shown in the screenshot below. If I click on the ignore button (same warning comes up five times so I'll have to click ignore as many times), the output contains both the header and footer with lines, string and image. So I know the code is working, only problem is why the error popping up? Am I not doing my code the proper way? However, if I comment out the gfx.DrawString and gfx.DrawImage lines, the application does not throw any error and prints the two lines.
Thanks.