Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentOutOfRangeException when reading a document #861

Open
sreejith-kulamgarath opened this issue Jun 28, 2024 · 7 comments
Open

ArgumentOutOfRangeException when reading a document #861

sreejith-kulamgarath opened this issue Jun 28, 2024 · 7 comments

Comments

@sreejith-kulamgarath
Copy link

sreejith-kulamgarath commented Jun 28, 2024

Here is my code.

        var stream = new FileStream(@"JPM_Metals_Weekly_Booste_2024-05-03_4691417 (1)-pages-2.pdf", FileMode.Open);
        using var document = PdfDocument.Open(stream, new ParsingOptions());

        var pages = document.GetPages();
        
        Console.WriteLine(pages.Count());

I have attached the file I have used.
JPM_Metals_Weekly_Booste_2024-05-03_4691417 (1)-pages-2.pdf

The version I was using: 0.1.9-alpha-20240628-bac00

@BobLd
Copy link
Collaborator

BobLd commented Jun 28, 2024

@sreejith-kulamgarath what library are you using here? I don't think this is PdfPig code

@sreejith-kulamgarath
Copy link
Author

@sreejith-kulamgarath what library are you using here? I don't think this is PdfPig code

Sorry about the previous code, I have updated the code now.

@BobLd
Copy link
Collaborator

BobLd commented Jun 29, 2024

@sreejith-kulamgarath can you try the following:

PdfDocument.Open(stream, new ParsingOptions() { SkipMissingFonts = true });

@BobLd
Copy link
Collaborator

BobLd commented Jun 29, 2024

@sreejith-kulamgarath anticipating your next question, you will need to use the following to clean the letters (many duplicate letters in your document)

 var letters = DuplicateOverlappingTextProcessor.Get(page.Letters);

@sreejith-kulamgarath
Copy link
Author

@sreejith-kulamgarath can you try the following:

PdfDocument.Open(stream, new ParsingOptions() { SkipMissingFonts = true });

This worked. But can we get a better user friendly message than an incomprehensible exception?

@BobLd
Copy link
Collaborator

BobLd commented Jun 29, 2024

What's the full stack trace you're getting?

@sreejith-kulamgarath
Copy link
Author

sreejith-kulamgarath commented Jul 1, 2024

Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at UglyToad.PdfPig.PdfFonts.Parser.Parts.BaseFontRangeParser.Parse(NumericToken numberOfOperations, ITokenScanner scanner, CharacterMapBuilder builder)
   at UglyToad.PdfPig.PdfFonts.Parser.CMapParser.Parse(IInputBytes inputBytes)
   at UglyToad.PdfPig.PdfFonts.Cmap.CMapCache.Parse(IInputBytes bytes)
   at UglyToad.PdfPig.PdfFonts.Parser.Handlers.Type0FontHandler.Generate(DictionaryToken dictionary)
   at UglyToad.PdfPig.PdfFonts.FontFactory.Get(DictionaryToken dictionary)
   at UglyToad.PdfPig.Content.ResourceStore.LoadFontDictionary(DictionaryToken fontDictionary, InternalParsingOptions parsingOptions)
   at UglyToad.PdfPig.Content.ResourceStore.LoadResourceDictionary(DictionaryToken resourceDictionary, InternalParsingOptions parsingOptions)
   at UglyToad.PdfPig.Parser.PageFactory.Create(Int32 number, DictionaryToken dictionary, PageTreeMembers pageTreeMembers, NamedDestinations namedDestinations, InternalParsingOptions parsingOptions)
   at UglyToad.PdfPig.Content.Pages.GetPage(Int32 pageNumber, NamedDestinations namedDestinations, InternalParsingOptions parsingOptions)
   at UglyToad.PdfPig.PdfDocument.GetPage(Int32 pageNumber)
   at UglyToad.PdfPig.PdfDocument.GetPages()+MoveNext()
   at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
   at Modules.PdfProcessorTest.Test() in ***Modules/PdfProcessorTest.cs:line 23
   at Program.<Main>$(String[] args) in /**/Program.cs:line 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants