PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 1:42 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: Wed May 24, 2017 10:06 am 
Offline

Joined: Wed May 24, 2017 9:44 am
Posts: 3
Using migra doc PDFsharp-MigraDocFoundation-1_50-beta3b with windows forms in visual studio 2015

In the Important Facts about MigraDoc, PDFsharp, and PDF it states "MigraDoc documents are highly dynamic, you can change anything at any time."

I've created a pdf document with headers and footers and tables based on the invoice from the samples, built it up fully and saved it. I'm looking to create 5 different versions of the pdf with a slight change to the header for each document, but i don't want to create the body of the document (which has many sections with tables) each time as the details are the same.

I have a table created in the headers.primary section and i'm looking to change a cell, save the document, use the same document alter the header table cell save the document x 4.

Is it possible to get or retrieve a section or headers section and alter the table contents of a document that has been built up already. If im looking for pointers to achieve this.

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Wed May 24, 2017 11:59 am 
Offline
PDFsharp Guru
User avatar

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

The general approach:
The Section has an Elements member with an index operator []. Use that to get each element.
Every document element has a Tag member for use by your application. You can use the tag to identify the element that needs modification later on.
Some elements have an Elements member of their own, so in some cases you have to use recursion (e.g. to find a Paragraph in the Cell of a Table).

The simple approach:
If you just need different headers/footer, then just set them new for the section before rendering the document. That would be simpler than finding the right cell in an existing header.

Usage hint: create the master document, then call "Clone()" to create a copy, modify the copy, create a PDF, dispose the copy - and go back to "Clone()" until you got all the PDFs you need.

Or maybe use a subroutine for the common part and call that during the creation of all documents. Cleaner code, but if the creation of the common body takes a long time (e.g. database or web calls) then the "Clone()" method may be much faster.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed May 24, 2017 2:37 pm 
Offline

Joined: Wed May 24, 2017 9:44 am
Posts: 3
Hi,

The clone worked. Creation of the common body i was thinking would be the step that would take the most time for each pdf document but further investigation i think its this step MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl"); that is taking the longest, which i need to do for each document anyway i presume.

So there might not be much of a gain to clone the body for use each time. Maybe need some further tests on how long it takes.

Thanks

Nickie


Top
 Profile  
Reply with quote  
PostPosted: Wed May 24, 2017 2:45 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
nickie wrote:
Creation of the common body i was thinking would be the step that would take the most time for each pdf document but further investigation i think its this step MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl"); that is taking the longest, which i need to do for each document anyway i presume.
The file "MigraDoc.mdddl" usually is for debugging purposes only - just delete that line or comment it out.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed May 24, 2017 3:27 pm 
Offline

Joined: Wed May 24, 2017 9:44 am
Posts: 3
Fantastic, its producing documents much much much faster now.

Thanks v much.


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