Hi all,
I wrote a short script, adding text to all pages of a PDF.
Works great so far, but I have two issues:
One is, that my test is not added to a specific page, linked below.
If I print the PDF via the Windows PDF engine, I can add text, so there has to be something special with that page.
Can anyone tell me what the problem is here, and if there is a way to detect this and work around it?
The sample Page:
https://share.ancora-verlagsservice.de/ ... pP2Yb6xBbDSecond is, that the text is sometimes printed a bit different (you can see that in the attached files, the spacing between "66" and "22" is slightly different) in the same document.
This is clearly visible when turning the pages of a multipage document.
The pages have the same height and width.
Any ideas? I'm new to PDFsharp, so any advice is welcome.
Best wishes
Christoph
Here is my code that adds the text:
PdfDocument document = PdfReader.Open(inputPdfPath, PdfDocumentOpenMode.Modify);
foreach (PdfPage page in document.Pages)
{
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Arial", 12);
double pageWidth = page.Width;
double pageHeight = page.Height;
XGraphicsState state = gfx.Save();
gfx.TranslateTransform(pageWidth - 12, pageHeight / 1.1);
gfx.RotateTransform(-90);
string verticalText = "Blub Blub, Bestellnummer RG5566224";
gfx.DrawString(verticalText, font, XBrushes.Black, new XPoint(0, 0));
gfx.Restore(state);
}
document.Save(outputPdfPath);