empira / PDFsharp-1.5

A .NET library for processing PDF
MIT License
1.28k stars 588 forks source link

New PdfDocument defaults to version 1.0 and PdfReader.Open() fails to open it #121

Closed AGlezB closed 1 year ago

AGlezB commented 4 years ago

PDFsharp: 1.50.5147

If you create a new PDF using new PdfDocument(), save it and try to open it with PdfReader.Open() it fails with File is not a valid PDFfile.

Looking at the document properties I noticed this: image

PdfReader.Open() works fine ffter setting pdf.Version = 14. I didn't try other versions.

This is only a bug because PDFSharp cannot open the files created with the default settings. Please consider changing the default version to something PdfReader.Open() can handle.

ThomasHoevel commented 4 years ago

Did you add any pages? Please try the PDF created by the Hello World sample. See also: http://pdfsharp.net/wiki/IssueSubmissions.ashx http://pdfsharp.net/wiki/HelloWorld-sample.ashx

AGlezB commented 4 years ago

We have a WinForms app that uses SSRS to generate a bunch of PDF reports then PDFSharp to merge those in a single PDF file. Then our client requested to merge some of those previusly merged files to email their clients a single file.

For exalmple the app creates a bunch of individual reports for 2019, say Billing, Expenses, Raw Material usage, Production, etc. for single client and then merges those in a single PDF like {ClientID}_{Yeay}.pdf. Then our client says they want 2019 and 2018 in a single file, so we grab the existing files and merge them before sending them to their client and here we failed to merge {ClientID}_2018.pdf and {ClientID}_2019.pdf because of the issue with the version.

Unfortunately I cannot provide the code or a PDF sample since everything is covered in NDAs and whatnot.

EDIT: Ok, this sould be safe image That is a partial screenshot of Foxit Reader's file poperties. That one fails to open with PdfReader.Open()

This one was generated with the same code but with one additional LOC setting version to 1.4 image PdfReader.Open() has no issue with it.

AGlezB commented 4 years ago

This should also be safe image

image