PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 10:09 pm

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: Wed Feb 15, 2023 2:01 pm 
Offline

Joined: Thu Jun 23, 2022 9:38 am
Posts: 10
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();
}


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 16, 2023 10:01 am 
Offline
PDFsharp Expert
User avatar

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

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 20, 2023 1:44 pm 
Offline

Joined: Thu Jun 23, 2022 9:38 am
Posts: 10
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


Last edited by Jupklass on Mon Feb 20, 2023 1:57 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 20, 2023 1:48 pm 
Offline
PDFsharp Expert
User avatar

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

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 20, 2023 1:58 pm 
Offline

Joined: Thu Jun 23, 2022 9:38 am
Posts: 10
Thank you.
No problem with that :D


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 111 guests


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