PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Dec 08, 2024 2:26 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Oct 07, 2024 7:56 am 
Offline

Joined: Mon Oct 07, 2024 7:35 am
Posts: 3
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/ ... pP2Yb6xBbD

Second 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);


Attachments:
textV2.png
textV2.png [ 1.81 KiB | Viewed 9767 times ]
textV1.png
textV1.png [ 1.83 KiB | Viewed 9767 times ]
Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 07, 2024 8:01 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1019
Location: CCAA
We no longer attempt to reproduce issues from supplied code snippets. Sorry.

See here:
https://docs.pdfsharp.net/General/Issue-Reporting.html

See here:
http://forum.pdfsharp.net/viewtopic.php?f=2&t=832

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 07, 2024 8:26 am 
Offline

Joined: Mon Oct 07, 2024 7:35 am
Posts: 3
Ok, didn't know - thanks for the answer, I'll provide you the code as described!


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 09, 2024 12:57 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3113
Location: Cologne, Germany
Issue #2:
The second page of the document has a TrimBox set ("X1=95.5276, Y1=170.079, X2=747.472, Y2=1020.92").
Make sure to draw your text within the margins of the trim box or it will be trimmed. No problem of PDFsharp.

With a small change, the text shows up:
Code:
XGraphicsState state = gfx.Save();

gfx.TranslateTransform(pageWidth - 200, pageHeight / 1.5);
gfx.RotateTransform(-90);

string verticalText = "Blub Blub, Bestellnummer RG5566224";
gfx.DrawString(verticalText, font, XBrushes.Black, new XPoint(0, 0));


gfx.Restore(state);


Clean code must take the TrimBox into account, of course.

Issue #1:
At small zoom levels, Adobe Reader sometimes does funny things when displaying letters.
Issue does not show when PDF is viewed at high zoom levels. No problem of PDFsharp.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 09, 2024 7:06 pm 
Offline

Joined: Mon Oct 07, 2024 7:35 am
Posts: 3
Thank you very much for your support!
5 stars out of five :-)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 30 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group