PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed Apr 04, 2018 6:35 pm 
Offline

Joined: Wed Feb 14, 2018 10:28 am
Posts: 9
Ok, so I need to open an existing PDF, copy its pages to another PDF and add a top margin space. This all works well with the below code, except on some PDFs I see coming through our system, which have orientation = portrait and rotation = 270.
When the below output document is created in these instances, the top of the content in the portrait page is cut off.

It seems that the 'window' that is used to snap the image for import into the XPdfForm automatically rotates to 270 (i.e. landscape), and takes its shot thereby missing the PDF content at the top of the page in Portrait orientation. I don't seem to be able to do anything about this, I have tried a number of variations regarding the output doc, but the issue seems to be with the Input form whose PixelHeight = 612 & PixelWidth = 792. I would have expected these to be the opposite for a page with a Portrait orientation.

Playing around with widths, heights, setting orientations, rotations, none of these seemed to matter, the output doc is still chopped. The issue seems to be with how the Form object is getting set up. I have reviewed numerous similar threads, which are related but do not seem to hit on this issue, and am not able to find a resolution

I have the files but they are a few kB too big, 256 is a very small file limit. I'm using PDFsharp-MigraDoc-gdi 1.50.4790-beta5a

Help would be greatly appreciated, thank you in advance!

Here's the code I am using

Code:
form = XPdfForm.FromFile(destination);

PdfSharp.Pdf.PdfDocument outputDocument = new PdfSharp.Pdf.PdfDocument();
XGraphics gfx;
XRect box;

 for (int idx = 0; idx < form.PageCount; idx++)
                {
                    // Add a new page to the output document
                    PdfSharp.Pdf.PdfPage page = outputDocument.AddPage();
                    XSize size = PageSizeConverter.ToSize(PdfSharp.PageSize.Letter);

                    //double width = 0d;
                    //double height = 0d;

                    if (form.PixelWidth > form.PixelHeight)
                    {
                        page.Width = size.Height;
                        page.Height = size.Width;
                    }
                    else
                    {
                        page.Width = size.Width;
                        page.Height = size.Height;
                    }
                                       

                    int rotate = page.Elements.GetInteger("/Rotate");
                   
                    gfx = XGraphics.FromPdfPage(page);
                   
                    box = new XRect(0, 25, page.Width, (page.Height - 25));
                    // Draw the page identified by the page number like an image
                    gfx.DrawImage(form, box);
                    form.PageNumber++;
                }


I have also tried simply opening the existing doc and adding the pages to a new document and that works fine, but as I understand I cannot add margins that way, I have to redraw the existing pages onto a new page using the gfx object if I wish to do this.


Last edited by JimboBaggins on Thu Apr 05, 2018 7:54 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 04, 2018 7:23 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 339
Hi!
JimboBaggins wrote:
Here's the code I am using
Please use the IssueSubmissionTemplate to allow us to replicate the issue.
You can send the ZIP (without NuGet packages) via e-mail.

See also:
viewtopic.php?f=2&t=832

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 05, 2018 8:40 am 
Offline
PDFsharp Guru
User avatar

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

Your e-mail has arrived, thanks for that.
I'll give you feedback when I will have found time to check this with a debugger.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 05, 2018 8:15 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
Hi!
JimboBaggins wrote:
I'm using PDFsharp-MigraDoc-gdi 1.50.4790-beta5a
Jim reported that everything works fine with 1.50 beta 3b.
Thanks for your feedback.

So I undid a change I made to resolve an issue reported in 2015 and came up with a new modification that works for both cases.
The old thread:
viewtopic.php?p=9587#p9587

I'll try to post a new "1.50 RC2" to NuGet later this week.

I just hope this new change does not cause problems with other use cases.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 06, 2018 9:45 am 
Offline

Joined: Wed Feb 14, 2018 10:28 am
Posts: 9
Hi guys thanks for the quick responses and communication, really excellent, glad the sample I sent on helped.

We are moving forward with 1.50 beta 3b as it is working well for us now, just regression testing its performance and looking well so far.

Once the new "1.50 RC2" is available I will test with that.

I had seen that bug reported at:
viewtopic.php?p=9587#p9587
and knew it was likely related, but not quite the same use case.

Hopefully the fix works across use cases as mentioned.

Appreciate the effort & turnaround.


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 08, 2018 4:49 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
With PDFsharp 1.50 RC2 situation is not yet perfect.

When opening files for modification I have to set
Code:
page.Orientation = PageOrientation.Portrait;

This has no effect if rotation is 0 or 180, but it is needed to get correct results when rotation is 90 or 270.

This hack is not needed when rotated PDF pages are used with XPdfForm and drawn on other PDF pages.
So the issue discussed in this thread should be fully resolved.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 09, 2018 11:41 am 
Offline

Joined: Wed Feb 14, 2018 10:28 am
Posts: 9
I have tested PDFSharp gdi 1.50.4845-RC2a with both the portrait and landscape issue rotation PDFs I sent in. In the case of drawing with XPdfForms into a new PDF (as per release post: viewtopic.php?f=1&t=3744), I can confirm that it works with both of them and the PDFs are rendering as expected. Thank you, this really is a help to me.

I am proceeding with gdi 1.50.4845-RC2a for our production system.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 52 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