PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 6:40 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: Mon Sep 05, 2016 8:02 am 
Offline

Joined: Mon Sep 05, 2016 7:54 am
Posts: 22
Hi there, currently writing a small C# program with PDFSharp but I have a problem that I can't seem to figure out. The program is used to load in a pre-made PDF with a number of forms present, I want to read the original PDF in, duplicate it's contents into a new PDF and then fill out the forms in the new PDF. So far I have the following code:

Code:
inPDF = PdfReader.Open(sourceFile, PdfDocumentOpenMode.Import);
outPDF = new PdfDocument();

for (int idx = 0; idx < inPDF.PageCount; ++idx)
{
   outPDF.AddPage(inPDF.Pages[idx]);
}


However the new PDF does not have any of the forms present in the original, how can I duplicate the contents (including forms) of the original PDF?

Thanks, RBrNx


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 05, 2016 10:04 am 
Offline
PDFsharp Guru
User avatar

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

Forms are not my area of experience.

Which version of PDFsharp?
Does this happen with all PDF files?
See also:
viewtopic.php?f=2&t=832

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 05, 2016 10:14 am 
Offline

Joined: Mon Sep 05, 2016 7:54 am
Posts: 22
Apologies! Currently using the 1.50.4000-Beta3B NuGet Package. Yes it happens with any PDF that has forms. Any text or images present in the PDF are copied over fine but the Forms seem to disappear. I can get around it by simply loading the original PDF in, filling the forms and then saving it as a different name and closing the original PDF again.

I have another issue that I am currently stuck with. There are some forms that are present in the PDF that I'd like to replace with an image. I understand that I can use the code below to draw an image at an exact position, but I am unaware of how to get the exact position of where a specific Form element is located.

Code:
XGraphics gfx = XGraphics.FromPdfPage(page);
XImage image = XImage.FromFile(imagepath);
gfx.DrawImage(image, x, y, width, height);


I am also unsure of how to get the specific page that the Form element is on so that I can pass it to the FromPdfPage() function. Can you help with either of these?

Thanks, Conor


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 127 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