PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

XPdfForm.FromFile cutting top of PDF with Rotatation at 270
https://forum.pdfsharp.net/viewtopic.php?f=3&t=3758
Page 1 of 1

Author:  JimboBaggins [ Wed Apr 04, 2018 6:35 pm ]
Post subject:  XPdfForm.FromFile cutting top of PDF with Rotatation at 270

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.

Author:  () => true [ Wed Apr 04, 2018 7:23 pm ]
Post subject:  Re: XPdfForm.FromFile cutting top of PDF with Rotatation at

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

Author:  Thomas Hoevel [ Thu Apr 05, 2018 8:40 am ]
Post subject:  Re: XPdfForm.FromFile cutting top of PDF with Rotatation at

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.

Author:  TH-Soft [ Thu Apr 05, 2018 8:15 pm ]
Post subject:  Re: XPdfForm.FromFile cutting top of PDF with Rotatation at

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.

Author:  JimboBaggins [ Fri Apr 06, 2018 9:45 am ]
Post subject:  Re: XPdfForm.FromFile cutting top of PDF with Rotatation at

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.

Author:  TH-Soft [ Sun Apr 08, 2018 4:49 pm ]
Post subject:  Re: XPdfForm.FromFile cutting top of PDF with Rotatation at

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.

Author:  JimboBaggins [ Mon Apr 09, 2018 11:41 am ]
Post subject:  Re: XPdfForm.FromFile cutting top of PDF with Rotatation at

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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/