PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 20, 2018 6:53 am

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 09, 2018 2:23 pm 
Offline

Joined: Wed Feb 14, 2018 10:28 am
Posts: 8
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.


Last edited by JimboBaggins on Fri Apr 13, 2018 11:58 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 13, 2018 6:38 am 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 381
Location: CCAA
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.

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


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 14, 2018 7:40 am 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 381
Location: CCAA
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.

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


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 14, 2018 8:00 am 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 381
Location: CCAA
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.

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 23, 2018 11:19 am 
Offline

Joined: Wed Feb 14, 2018 10:28 am
Posts: 8
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.


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 1 guest


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