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

[Question]: when parsing a PDF, is it possible to include page number, into individual node's meta data ? #17546

Open
1 task done
jzhao62 opened this issue Jan 18, 2025 · 1 comment
Labels
question Further information is requested

Comments

@jzhao62
Copy link
Contributor

jzhao62 commented Jan 18, 2025

Question Validation

  • I have searched both the documentation and discord for an answer.

Question

  • as the question goes, it would be great if each node's meta data could contain page Number that points to its origianl occurance in the PDF
@jzhao62 jzhao62 added the question Further information is requested label Jan 18, 2025
Copy link

dosubot bot commented Jan 18, 2025

Yes, when parsing a PDF using the PyMuPDFReader class, you can include the page number in each individual node's metadata. This is done by adding the page number to the extra_info dictionary with the key "source". Here's a code snippet that demonstrates how to do this:

return [
    Document(
        text=page.get_text().encode("utf-8"),
        extra_info=dict(
            extra_info,
            **{
                "source": f"{page.number+1}",
            },
        ),
    )
    for page in doc
]

In this snippet, page.number+1 is used to get the page number (starting from 1) and include it in the metadata for each document node [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

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

No branches or pull requests

1 participant