PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jun 27, 2024 7:59 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Auto Paging
PostPosted: Wed Jun 02, 2010 4:25 pm 
Offline

Joined: Wed Jun 02, 2010 4:14 pm
Posts: 1
Hi,

I am using pdfsharp to create a pdf. A requirement came in that we need to added a "terms" section that can be very long and flow over a couple of pages. I am trying to implement the MigraDoc stuff because i believe this handles the case automatically. Unfortunately I can only get it to show for the first page and that is all.

here is the code

//this Document is from the MigraDoc.DocumentObjectModel

Document doc = new Document();
Section sec = doc.AddSection();
Paragraph terms = sec.AddParagraph();
terms.Format.Font.Name = "Calibri";
terms.Format.Font.Size = "11";
terms.Format.Font.Color = Colors.Black;
terms.Format.KeepTogether = false;

terms.AddText(purchaseOrder.Terms);

DocumentRenderer documentRenderer = new DocumentRenderer(doc);
documentRenderer.PrepareDocument();
documentRenderer.RenderObject(gfx, XUnit.FromCentimeter(2), offset, "19cm", terms);


Offset is an int i have for keeping track of the Y value, purchaseOrder.Terms is a giant string I am trying to get to flow over whatever the number of pages its needs, starting at the Y value of offset. GFX was set up as below


//this pdf document is from the PDFSharp.Pdf.PDFDocument

PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);


Any help would be appreciated,

Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: Auto Paging
PostPosted: Thu Jun 03, 2010 11:47 am 
Offline

Joined: Thu May 27, 2010 2:25 pm
Posts: 9
Hi,
XGraphics gfx = XGraphics.FromPdfPage(page);
means, that this graphics can draw only to this one page only. It's the reason why you have only one page in your document.

Create Document using MigraDoc, than render entire PdfDocument (with all pages) and after this just modify some pages from rendered instance.
Code:
Dim Renderer As New MigraDoc.Rendering.PdfDocumentRenderer(True)
Renderer.Document = Doc
Renderer.PrepareRenderPages()
Renderer.RenderDocument()
Renderer.PdfDocument <---- here's your document


There's an example of mixing Migradoc and PdfSharp in sampes section.

Hope this helps.


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

All times are UTC


Who is online

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