PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 19, 2024 4:33 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: Mon Apr 04, 2016 2:15 pm 
Offline

Joined: Mon Apr 04, 2016 11:45 am
Posts: 3
I don't know if the problem is the source pdf generator, but all the pair numbered pages became diferent from original, when using the DrawImage method from the class XGraphics.

The problem is the page image gets shifted to the left and bottom.

In attachment goes the test source code and document.

It happens with PDFSharp version 1.32 and the latest one.

Best regards


Attachments:
PDF.zip [91.39 KiB]
Downloaded 344 times
Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 04, 2016 2:55 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

I think it is a bug in PDFsharp.

The first page is not rotated and it is handled correctly.

The second page was rotated by 180°. The code that draws it handles the rotation somewhat incorrectly.

Is the PDF file coming from a duplex scanner?
Different scanner settings could be a workaround.
The PDF is a bit unusual, but still it should be handled correctly.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 04, 2016 3:17 pm 
Offline

Joined: Mon Apr 04, 2016 11:45 am
Posts: 3
Hi.

Yes, it cames from a duplex scanner.

I asked the user to try different settings.

Best regards.


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 04, 2016 3:36 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
If you are using the source code version of PDFsharp, here is a change I tried successfully with your PDF file:

In file "PdfFormXObject.cs" go to the method "internal PdfFormXObject(PdfDocument thisDocument, PdfImportedObjectTable importedObjectTable, XPdfForm form)"
and look for the comment "// Translate the image such that its center lies on the center of the rotated bounding box".
I added an "if" around six lines of code:
Code:
if (rotate != 180)
{
    // Translate the image such that its center lies on the center of the rotated bounding box
    double offset = (height - width) / 2;
    if (height > width)
        matrix.TranslatePrepend(offset, offset);
    else
        matrix.TranslatePrepend(-offset, -offset);
}
This change was not yet approved by the PDFsharp master programmer.

Original source code (without this fix) can be found here:
http://pdfsharp.codeplex.com/releases/view/618773

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 04, 2016 4:29 pm 
Offline

Joined: Mon Apr 04, 2016 11:45 am
Posts: 3
Hi.

Thanks for you help, I made the changes and worked as you said.

If for some reason the proposed solution gets changed, I would like to know, so i can make the appropriate source changes.

Best regards.


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: No registered users and 248 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