PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Apr 16, 2024 1:10 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Nov 15, 2016 12:02 am 
Offline

Joined: Mon Nov 14, 2016 9:26 pm
Posts: 2
I am trying to preserve an existing PDF documents in there entirety and add text to these PDF documents. This includes keeping PDF markup such as comments and Pop Ups.

Version: 1.50.4000-beta3b

I have tried using both PdfDocumentOpenMode.Modify and PdfDocumentOpenMode.Import as you can see from my example code. Both have issues.
-Modify preserves PDF markup such as comments and Pop Ups, however I lose page size and page orientation with the saved PDF outputPDF1.
-Import strips the copied pages of markup information (comments, popups)but outputs the pdf with the original page orientation and size outputPDF2.


Code:
PdfDocument pdfModify = PdfReader.Open(myOriginalPDF, PdfDocumentOpenMode.Modify);
PdfDocument pdfImport = PdfReader.Open(myOriginalPDF, PdfDocumentOpenMode.Import);
PdfDocument pdfNewFromImport = new PdfDocument();

for (int pageNumber = 0; pageNumber < pdfModify.Pages.Count; pageNumber++)
{
     PdfPage pageModify = pdfModify.Pages[pageNumber];
     XGraphics xg1 = XGraphics.FromPdfPage(pageModify);
     XFont xfont1 = new XFont("Arial", 14, XFontStyle.Regular);
     xg1.DrawString("My Added Text", xfont1, XBrushes.Red, new XRect(0, 0, pageModify.Width, pageModify.Height), XStringFormats.TopLeft);

     PdfPage pageNew = pdfNewFromImport.AddPage(pdfImport.Pages[pageNumber]);
     XGraphics xg2 = XGraphics.FromPdfPage(pageNew);
     XFont xfont2 = new XFont("Arial", 14, XFontStyle.Regular);
     xg2.DrawString("My Added Text", xfont2, XBrushes.Red, new XRect(0, 0, pageNew.Width, pageNew.Height), XStringFormats.TopLeft);
}
pdfModify.Save(outputPDF1);
pdfNewFromImport.Save(outputPDF2);


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 15, 2016 12:05 am 
Offline

Joined: Mon Nov 14, 2016 9:26 pm
Posts: 2
Also forgot to mention I got started with this post, which was the suggest solution to one of my problems http://stackoverflow.com/questions/17647872/pdfsharp-edit-a-pdf-file


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 15, 2016 1:51 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

You can use the Issue Submission Template to allow us to replicate the issue.
See also:
viewtopic.php?f=2&t=832

Please check the second post in this thread:
viewtopic.php?p=9591#p9591
The proposed change may (or may not) help with your problem.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 69 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