PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
Error on Open when pdf file is empty http://forum.pdfsharp.com/viewtopic.php?f=2&t=4417 |
Page 1 of 1 |
Author: | Jupklass [ Wed Feb 15, 2023 2:01 pm ] |
Post subject: | Error on Open when pdf file is empty |
There is a error when you try to open a pdf file of size 0. (try for example to create a empty .txt file and then just change the extension to .pdf) some pdf files of size 0 could be also the result of a proccess that have not well finish On PdfReader.cs Line 296 if (document._version == 0) throw new InvalidOperationException(PSSR.InvalidPdf); this should be added (document._version == null) if ((document._version == null) || (document._version == 0)) in my case also had to modify the catch to this and remove the throw catch (Exception ex) { Debug.WriteLine(ex.Message); document = new PdfDocument(); document.Close(); } |
Author: | TH-Soft [ Thu Feb 16, 2023 10:01 am ] |
Post subject: | Re: Error on Open when pdf file is empty |
Hi! Thank you for the feedback. Jupklass wrote: There is a error when you try to open a pdf file of size 0. Stefan and I agree that an empty file is not a valid PDF file and that it is correct that PDFsharp throws an exception when attempting to open such a file.This is not a bug, it is a feature. So it is up to the caller to check for files with a size of 0 and use "new PdfDocument()" instead of "PdfReader.Open()" in that case. |
Author: | Jupklass [ Mon Feb 20, 2023 1:44 pm ] |
Post subject: | Re: Error on Open when pdf file is empty |
TH-Soft wrote: Hi! This is not a bug, it is a feature. I agree with with with you. But it dosen´t throw an exception if it´s empty that´s why i place the null condition |
Author: | TH-Soft [ Mon Feb 20, 2023 1:48 pm ] |
Post subject: | Re: Error on Open when pdf file is empty |
Jupklass wrote: I agree with with with you. But it dosen´t throw an exception if it´s empty Current internal builds throw when it is empty.Cannot give an ETA when it will be published. |
Author: | Jupklass [ Mon Feb 20, 2023 1:58 pm ] |
Post subject: | Re: Error on Open when pdf file is empty |
Thank you. No problem with that |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |