PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 17, 2021 5:39 am

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
PostPosted: Mon Aug 20, 2018 1:07 pm 

Joined: Wed Aug 15, 2018 12:23 pm
Posts: 3

I create a pdf document containing one page. The size of the page depends on the total size of it content.

The following steps are executed:

1) create the pdf doc
me.PdfDoc = new pdfdocument

2) add a pdf page
me.PdfPage = me.PdfDoc.AddPage()

3) create Gfx object
me.gfx = xgraphics.FromPdfPage(me.PdfPage)

4) I add rectangles and text in teh Gfx object. All works fine.

5) After calculating the max width and Height used in the PdfPage I need to shrink the PdfPage to the minimal values (+10mm)
Using the "PdfPage.width = value" removes all contents.

Can I redefine the width and Height of the PdfPage after in contains elements like text and rectangles?
Or do I have to create a new PdfPage from start, set the width and height, and then fill the content of it?

Best regards,

Reply with quote  
PostPosted: Mon Aug 20, 2018 1:50 pm 
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3047
Location: Cologne, Germany
Maarten wrote:
Using the "PdfPage.width = value" removes all contents.
Most likely it does not remove the contents. You expect to see the top half of the page, but what you still see could be the bottom half of the page. The contents are still there, they are just outside the visible area.

Maybe try playing around with the MediaBox to make sure you see the part where you added contents.

Or maybe create a second PDF page with the desired size and draw the oversized page on this page. This adds a few extra bytes to the PDF file.

The best way: determine the page size you need before creating the final contents. Call your code twice: first time to determine the correct page size (discarding the page created in this run), second time to draw the correct page.
Use caching if you access databases or do other "slow" things in the code.

Thomas Hoevel
PDFsharp Team

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: Bing [Bot] and 22 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