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

support array of content streams and parse them as a single stream #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

romanpickl
Copy link

@romanpickl romanpickl commented Mar 12, 2024

Support array of content streams.

this is based on some work in

but, as far as I understand the spec, the streams have to be concatenated before they are interpreted i.e. they have to be interpreted as a single stream. Otherwise some streams might be invalid as they depend on e.g. BT ops being opened in the previous stream.

grafik
https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf (page 78)

This draft includes some duplication that could be refactored, but I don't have the full visibility of the code base (yet).

In addition I think that other functions like walkTextBlocks might have to be updated as well.

romanpickl referenced this pull request in oxisto/pdf Mar 12, 2024
The page object structure supports either a stream or an array in the `Contents` key. In the latter case, we need concat the contents of the individual streams.
@romanpickl romanpickl mentioned this pull request Mar 12, 2024
@romanpickl
Copy link
Author

romanpickl commented Mar 12, 2024

seems to fix:

potentially fixes:

the issue in #15 seems to be a broken xref table in the pdf which can be fixed with mutools.

@romanpickl romanpickl marked this pull request as ready for review March 14, 2024 09:08
@romanpickl
Copy link
Author

As far as my tests are representative, it now also works with

  • GetPlainText
  • GetTextByColumn
  • GetTextByRow

tok := b.readToken()
if tok == io.EOF {
break
s := strm
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe there is a more GO like way of doing this without repeating code.
I'm open for suggestions.

@iwilltry42
Copy link

I can confirm that it fixed failed to load PDF: malformed PDF: reading at offset 0: stream not present for me using https://github.com/hupe1980/golc/blob/main/documentloader/pdf.go and https://github.com/tmc/langchaingo/blob/main/documentloaders/pdf.go

Great job @romanpickl !

@qhenkart
Copy link

can this be merged?

bloeys added a commit to Sabbar-Engineering/pdf that referenced this pull request Dec 18, 2024
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

Successfully merging this pull request may close these issues.

3 participants