PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 4:50 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Wed Nov 24, 2021 5:44 am 
Offline

Joined: Wed Nov 24, 2021 5:05 am
Posts: 8
PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'True' in PDF stream. The file may be corrupted. If you think this is a bug in PDFsharp, please send us your PDF file.'

Read all the pdf and converted to bytes. Stored in List<byte[]>. From this list, take first 25 items and try to create pdf getting "PdfSharp.Pdf.IO.PdfReaderException". This is working with "2020_f1095c.pdf", but not working with "2021_f1095c.pdf". The file "2021_f1095c.pdf" downloaded from https://www.irs.gov/pub/irs-pdf/f1095c.pdf

I have attached demo visual studio console application project to re-produce the issue.

We are working on Dec-2021 year end release. It will be helpful if you provide solution.


Attachments:
File comment: pdf files. Needs to add this file to vs sln project.
Pdfs.7z [226.67 KiB]
Downloaded 431 times
File comment: vs demo project. Needs to add the above pds to this demo project and PDFSharp.dll also. Latest version 1.50.5147.0
1905c.7z [146.2 KiB]
Downloaded 426 times
Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 26, 2021 2:48 am 
Offline

Joined: Wed Nov 24, 2021 5:05 am
Posts: 8
I am waiting for the solution. Is there any fix?

Is this because of corrupted .PDF file or other issues?


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 26, 2021 7:11 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3092
Location: Cologne, Germany
Hi!

I downloaded the file and it opens successfully.

Code:
PdfDocument inputDocument1 = PdfReader.Open(@"C:\Users\...\f1095c.pdf", PdfDocumentOpenMode.Import);
var x = inputDocument1.Pages.Count;


Sorry, but I did not want to download those 7z files and and try to find out how to combine them.
You lost me with this sentence: "Read all the pdf and converted to bytes. Stored in List<byte[]>. From this list, take first 25 items and try to create pdf getting "PdfSharp.Pdf.IO.PdfReaderException"."


Are you using the latest NuGet version? Which exactly?
Is it 1.51.5186-beta?

https://www.nuget.org/profiles/PDFsharp-Team

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 26, 2021 8:04 am 
Offline

Joined: Wed Nov 24, 2021 5:05 am
Posts: 8
No. Using 1.50.5147.0 stable version.

Please refer below C# method. First create bytes from PDFDcoument. Then using PdfDocument getting error "PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'True' in PDF stream. The file may be corrupted. If you think this is a bug in PDFsharp, please send us your PDF file.'"


Code:
byte[] pdfBytes = null;

            var document = PdfReader.Open(filePath);
            using (var stream = new MemoryStream())
            {
                document.Save(stream);
                pdfBytes = stream.ToArray();
            }

            using (var outputDocument = new PdfDocument())
            {
                using (var mem = new MemoryStream(pdfBytes))
                {
                    using (var pdfToMerge = PdfReader.Open(mem, PdfDocumentOpenMode.Import))
                    {
                    }
                }
            }


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 26, 2021 9:45 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 905
Location: CCAA
baburaja_r wrote:
Using 1.50.5147.0 stable version.
Does the error also occur with 1.51.5186-beta?

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 26, 2021 9:51 am 
Offline

Joined: Wed Nov 24, 2021 5:05 am
Posts: 8
Yes, getting the same error


Top
 Profile  
Reply with quote  
PostPosted: Sat Nov 27, 2021 3:02 am 
Offline

Joined: Wed Nov 24, 2021 5:05 am
Posts: 8
Is it possible to fix this issue?


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 29, 2021 6:24 am 
Offline

Joined: Wed Nov 24, 2021 5:05 am
Posts: 8
Can you any one help me on this issue?


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 29, 2021 8:22 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 905
Location: CCAA
baburaja_r wrote:
Is it possible to fix this issue?
Yes. I don't have time to step through the code.
Consider taking the PDFsharp source code and incorporate some of the proposed pull requests.

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 29, 2021 9:13 am 
Offline

Joined: Wed Nov 24, 2021 5:05 am
Posts: 8
Thanks for the response.

This year end we needs to give release for year end changes. The functionality which is breaking now is important for this release.
It could be helpful for us, if we get solution before Dec 1st week end.

Waiting for your support to come out of this issue.


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 14, 2023 4:33 pm 
Offline

Joined: Thu Sep 14, 2023 4:31 pm
Posts: 2
Did anyone identify the solution for this issue.


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 14, 2023 10:08 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 905
Location: CCAA
raviteja wrote:
Did anyone identify the solution for this issue.
The bug in PDFsharp has been fixed with recent builds of PDFsharp 6.0.0.

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


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 29, 2023 3:25 pm 
Offline

Joined: Wed Nov 24, 2021 5:05 am
Posts: 8
The PdfSharp.dll 6.0.0 required min .net framework 6.0. But our project uses 4.6.1.

Can you let me know, is there any option to get PdfSharp.dll to support .net framework 4.6.1 with the 'Unexpected token True' issue fix?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 25 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