PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'True'
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4301
Page 1 of 1

Author:  baburaja_r [ Wed Nov 24, 2021 5:44 am ]
Post subject:  PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'True'

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 456 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 453 times

Author:  baburaja_r [ Fri Nov 26, 2021 2:48 am ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

I am waiting for the solution. Is there any fix?

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

Author:  Thomas Hoevel [ Fri Nov 26, 2021 7:11 am ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

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

Author:  baburaja_r [ Fri Nov 26, 2021 8:04 am ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

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))
                    {
                    }
                }
            }

Author:  TH-Soft [ Fri Nov 26, 2021 9:45 am ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

baburaja_r wrote:
Using 1.50.5147.0 stable version.
Does the error also occur with 1.51.5186-beta?

Author:  baburaja_r [ Fri Nov 26, 2021 9:51 am ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

Yes, getting the same error

Author:  baburaja_r [ Sat Nov 27, 2021 3:02 am ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

Is it possible to fix this issue?

Author:  baburaja_r [ Mon Nov 29, 2021 6:24 am ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

Can you any one help me on this issue?

Author:  TH-Soft [ Mon Nov 29, 2021 8:22 am ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

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.

Author:  baburaja_r [ Mon Nov 29, 2021 9:13 am ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

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.

Author:  raviteja [ Thu Sep 14, 2023 4:33 pm ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

Did anyone identify the solution for this issue.

Author:  TH-Soft [ Thu Sep 14, 2023 10:08 pm ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

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.

Author:  baburaja_r [ Wed Nov 29, 2023 3:25 pm ]
Post subject:  Re: PdfSharp.Pdf.IO.PdfReaderException: 'Unexpected token 'T

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?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/