Repository navigation
Preventing header, footers, page indicators being inserted into the text #1326
Unanswered
MathieuLohr
asked this question in
Q&A
Replies: 2 comments
|
At the moment, Markitdown doesn't automatically distinguish or filter out headers, footers, or page numbers inserted into the body during PDF-to-markdown conversion. |
0 replies
|
For unrotated pages with consistent header and footer margins, you can remove the text in those strips from an in-memory copy before handing it to MarkItDown. That avoids having to guess which numbers in the Markdown are page numbers. from io import BytesIO
import pymupdf
from markitdown import MarkItDown, StreamInfo
with pymupdf.open("manual.pdf") as doc:
for page in doc:
w, h = page.rect.width, page.rect.height
page.add_redact_annot((0, 0, w, 45), fill=False)
page.add_redact_annot((0, h - 45, w, h), fill=False)
page.apply_redactions(images=0, graphics=0)
pdf = BytesIO(doc.tobytes())
result = MarkItDown().convert_stream(
pdf, stream_info=StreamInfo(extension=".pdf")
)
print(result.text_content)The 45-point strips are examples. Adjust them to your manual so they don't overlap body text. I tried this with MarkItDown 0.1.9 on a two-page PDF with selectable text. Both headers, both footers and the page numbers dropped out, and the body text stayed. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Every page's header ("XYZ MANUAL"), footer ("XYT Manual - XXX"), and page-numbers of my pdf has been inserted directly into the body of the text of the markdown.
Is there a way to have markitdown identify headers, footers, page indicators and similar elements, and prevent this behaviour?
Thank you!
All reactions