PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Rendering issue: PDF from Mac OS X 10.8.5 Quartz
http://forum.pdfsharp.com/viewtopic.php?f=3&t=3760
Page 1 of 1

Author:  JimboBaggins [ Mon Apr 09, 2018 2:23 pm ]
Post subject:  Rendering issue: PDF from Mac OS X 10.8.5 Quartz

A PDF I am attempting to generate is not generating correctly when I run it through PDFSharp (gdi 1.50.4845-RC2a). I am attempting to add a border to the top of the page using the code below. The source of the original PDF is Mac OS X 10.8.5 Quartz PDFContext (PDFversion 1.3). I have tested through a number of past versions of PDF sharp gdi and am getting the same result. PDF sharp is not throwing any exception during the generation process, so I do not know where to look for the error, or handle it differently.

I have also tried rendering this through PDFSharp, using XImage XImage.FromFile, same result.

Below is the code I am using, this would appear to be an issue with how the logo image in the original document is being dealt with when the PDF is redrawn, possibly how PDF sharp is dealing with the encoding/compression from that Mac OS X QUartz pdf creator.

I note in the FAQs it mentions layers are not supported (http://www.pdfsharp.net/wiki/PDFsharpFA ... PDFsharp_7). If this is a layer issue, if this can be detected via an exception or otherwise that would also be useful.

Note:
If I take the original document and print it to PDF using Adobe Reader or Windows print to PDF, it renders correctly using the code below.
Additionally, just adding the pages from the original document into a new PDF without making any changes works fine, and the output file opens correctly in Adobe Reader, Edge, and Chrome.
Code:
 PdfSharp.Pdf.PdfDocument outputDocument = new PdfSharp.Pdf.PdfDocument();
 XGraphics gfx;
 XRect box;

            try
            {
                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);

                    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 then save the output document. I will send on the test Visual Studio template with my findings. Thanks again guys, hopefully you can point me in the right direction on this one.

Author:  TH-Soft [ Fri Apr 13, 2018 6:38 am ]
Post subject:  Re: Rendering issue: PDF from Mac OS X 10.8.5 Quartz

Hi!

I didn't have time yet to investigate this issue. It was a busy week.

I hope I'll find time for a closer look tomorrow.

Author:  TH-Soft [ Sat Apr 14, 2018 7:40 am ]
Post subject:  Re: Rendering issue: PDF from Mac OS X 10.8.5 Quartz

Hi!
JimboBaggins wrote:
I am attempting to add a border to the top of the page using the code below.
It works when I open the PDF for modification and draw a Rectangle onto the page.

I can confirm that this PDF cannot be used as a XPdfForm nor can it be used as a page donor.
At the moment I don't have an idea what could be the problem.

Author:  TH-Soft [ Sat Apr 14, 2018 8:00 am ]
Post subject:  Re: Rendering issue: PDF from Mac OS X 10.8.5 Quartz

An Online Validator gives the following output for the modified file:
Code:
Validating file "OutPutPdf1.PDF" for conformance level pdf1.4
The operator has an invalid number of operands.
No clue about the operand or the PDF object.
So it's searching a needle in the haystack.

Author:  JimboBaggins [ Mon Apr 23, 2018 11:19 am ]
Post subject:  Re: Rendering issue: PDF from Mac OS X 10.8.5 Quartz

Hi Thomas,

Okay, thank you for taking the time to investigate I appreciate the effort. I have since tested with other PDFs generated on a mac, with and without images, and those worked fine. So it seems to be a relatively particular problem with the PDF in question.

If there was any flag or point at which a specific error could be looked out for that would be useful, as it would allow the handling of it better, including getting a handle on whether there are more silent fails happening in our system. It isn't throwing any critical errors, which is the tricky part.

If I find any further information, particularly in relation to detecting the issue without raising a false positive, I will post here.

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