PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 1:21 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: Thu Jan 15, 2009 4:07 am 
Offline

Joined: Thu Jan 08, 2009 1:46 am
Posts: 8
hi,

I've got a pdf that says its rotation is 90 but adobe reader opens it upright in portrait mode. Does this mean that the original content is at 270 ?

My problem is that PDFsharp opens it as Landscape (because it determines orientation by rotation). Then for some reason PDFsharp will save the document as portrait even if i tell it not to.

Thanks,

billy.


Last edited by billy anachronism on Thu Jan 15, 2009 11:36 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 15, 2009 11:16 pm 
Offline

Joined: Thu Jan 08, 2009 1:46 am
Posts: 8
When I remove the /Rotate flag from all the pages they do indeed display at 270.

It seems that PdfSharp cannot recognise rotated content. If i open the pdf and save it with PdfSharp, it saves the document as landscape (even though it isn't). I assume this is because it reads the page has a rotate of 90, so it rotates it on its side. This has the nasty consequence of cutting of the content on the page because the content isn't at 90.

Surely someone else has come across this issue. Does anyone have any suggestions?


Top
 Profile  
Reply with quote  
PostPosted: Tue May 25, 2010 4:36 pm 
Offline

Joined: Thu Oct 16, 2008 1:54 pm
Posts: 14
I've just run into exactly the same problem with v1.31.1789.0. My PDF page is 1460x475mm, with a rotation of 90. If I open it with PDFSharp and save it without making any changes, the page size has changed to 475x1460mm with a rotation of 90, which cuts off the right-hand side of the document.

I think the problem is in PdfSharp.Pdf\PdfPage.cs, line 166:
Code:
// THHO: MediaBox is always in Portrait mode (see Height, Width)
/*if (this.orientation == PageOrientation.Portrait)*/
  MediaBox = new PdfRectangle(0, 0, size.Width, size.Height);
/*else
  MediaBox = new PdfRectangle(0, 0, size.Height, size.Width);*/


In v1.2, this was:
Code:
if (this.orientation == PageOrientation.Portrait)
  MediaBox = new PdfRectangle(0, 0, size.Width, size.Height);
else
  MediaBox = new PdfRectangle(0, 0, size.Height, size.Width);


The hacky workaround I've used is to call this function after loading any document:
Code:
private static void HackPageRotation([NotNull] PdfDocument document)
{
    for (int index = 0; index < document.PageCount; index++)
    {
        var page = document.Pages[index];
        if (PageOrientation.Landscape == page.Orientation)
        {
            var value = page.MediaBox;
            var size = new XSize(value.Height, value.Width);
            page.MediaBox = new PdfRectangle(value.Location, size);
        }
    }
}


Top
 Profile  
Reply with quote  
PostPosted: Wed May 26, 2010 7:58 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
RichardD wrote:
I think the problem is in PdfSharp.Pdf\PdfPage.cs, line 166

This change (my change :oops: ) fixes a problem reported in August 2009 - so this change cannot be the cause of a problem reported in January 2009.

I haven't investigated this issue yet, therefore I cannot say anything about it.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 07, 2010 12:22 pm 
Offline

Joined: Wed Jul 07, 2010 8:49 am
Posts: 1
Hello, i'm encountering an issue with a rotated landscape PDF. (seems very related to me)
However i had to put your hack before saving the PDF and not after loading or page calculations were wrong.

After digging into the source code i saw the problem in PDFPage.cs line 563:
Code:
      internal override void WriteObject(PdfWriter writer)
      {
         // HACK: temporarily flip media box if Landscape
         PdfRectangle mediaBox = MediaBox;
         // TODO: Take /Rotate into account
         if (orientation == PageOrientation.Landscape)
             MediaBox = new PdfRectangle(mediaBox.X1, mediaBox.Y1, mediaBox.Y2, mediaBox.X2);


Removing this "hack" seems to fix my problem.

I've seen a message (25-03-2010) on SourceForge saying this bug had been corrected in internal builds of PDFSharp.
Is there a way to get a snapshot of current development sources?

Thanks.


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: Google [Bot] and 60 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