PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

pdfsharp doesn't handle non-a4 page sizes correctly

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Bug Reports - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
billy anachronism



Joined: 08 Jan 2009
Posts: 8

PostPosted: Thu Jan 08, 2009 2:00 am    Post subject: pdfsharp doesn't handle non-a4 page sizes correctly Reply with quote

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.
Back to top
View user's profile Send private message
billy anachronism



Joined: 08 Jan 2009
Posts: 8

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

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;
Back to top
View user's profile Send private message
billy anachronism



Joined: 08 Jan 2009
Posts: 8

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

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);
}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Bug Reports - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com