PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 9:31 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Jan 08, 2009 2:00 am 
Offline

Joined: Thu Jan 08, 2009 1:46 am
Posts: 8
Hi, has anyone noticed that pdfsharp doesn't deal very well with non-standard page sizes?

I've got a pdf with strange height and width (16.54 x 11.70 in) which is in landscape. I need to add some outlines to it. When I do so (with PdfSharp) and save it, the document has been converted to portrait and subsequently almost half of the page is cut off.

So, I add a routine to rotate the document to landscape before I add the outlines.

PdfDocument pdf = PdfReader.Open(pdfFile, PdfDocumentOpenMode.Modify);

foreach (PdfPage page in pdf.Pages)
{
page.Orientation = PdfSharpMod.PageOrientation.Landscape;
}

This yields the same result. It still is rotated to portrait, even though PdfSharp presumably knows that the contents of the page is not in portrait.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 08, 2009 2:19 am 
Offline

Joined: Thu Jan 08, 2009 1:46 am
Posts: 8
I haven't fixed this issue but I managed to create the output that I wanted.
The pdf was actually landscape when it should have been portrait, so I gave up trying to fit it on a landscape page and made it portrait by:

page.Rotate = 0;
page.Orientation = PdfSharpMod.PageOrientation.Portrait;


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 08, 2009 4:11 am 
Offline

Joined: Thu Jan 08, 2009 1:46 am
Posts: 8
If anyone's interested, I've worked out how to rescale the document to A4.

// Open the pdf as a form

XPdfForm form = XPdfForm.FromFile(pdfFile);

for (int i = 1; i <= form.PageCount; i++)
{
// Create a new page in the new pdf

PdfPage newPage = pdf.AddPage();
newPage.Size = PdfSharpMod.PageSize.A4;
newPage.Rotate = 0;
newPage.Orientation = PdfSharpMod.PageOrientation.Portrait;
double width = newPage.Width;
double height = newPage.Height;

// Prepare the contents of the new page

XGraphics gfx = XGraphics.FromPdfPage(newPage);

// Make a new bounding box for the contents of the page

XRect box = new XRect(0, 0, width, height);

// Select the right page number in the current pdf

form.PageNumber = i;
form.Page.Rotate = 0;
form.Page.Orientation = PdfSharpMod.PageOrientation.Portrait;

// Add the contents of the page to the new page

gfx.DrawImage(form, box);
}


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 10, 2010 1:25 am 
Offline

Joined: Fri Feb 26, 2010 11:15 pm
Posts: 10
This is good. but I see the font size reduced. do you have any idea?


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

All times are UTC


Who is online

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