.to_markdown() container flags query

Hi,

I decided to test some of my old documents whose content and layout caused issues with older versions my PyMuPDF - to good results at first glance. Thanks for keeping up the great work on this package :slight_smile:

One thing which tripped my pipeline up a smidge, was a possible change in the flags used to mark text extracted from pictures.

So, I wondered if there were any other such tags? I can’t find reference to <!-- Start of picture text --> ... <!-- End of picture text --> markers anywhere in the documentation - perhaps there are other content types marked in a similar manner?

One final observation is that ignore_images (bool) is set to true, so I’m a little surprised any were present?!

Hi @MW_UK - can you confirm you are using PyMuPDF 2.0 here?

Hi,

I believe so, yes. It’s a fresh cluster with a fresh pip install:

%pip install pandas PyMuPDF pypdf python-docx rapidocr onnxruntime

Then a standard import:

import pymupdf

I don’t directly import rapidocr, but it does report using it in the run logs.

and then:

        # Open the document
        doc = pymupdf.open(input_fp)
        
        # 1. Generate Markdown (The "CR disabled" non-fatal error may occur here but won't crash)
        markdown_output_string = doc.to_markdown(
            show_progress=False,
            header=False,
            footer=False,
            ignore_images=True,
            ignore_graphics=True,
            use_glyphs=True
        )

The most important change in v2.0 is that pymupdf, pymupdf4llm and pymupdf-layout are presented under one single umbrella and reachable / active by doing import pymupdf a… that’s it.
All 4LLM features and function (well almost all) are reachable via pymupdf’s API, for example there is the new Document method doc.to_markdown() – which does the same as pymupdf4llm.to_markdown(). The latter continues to exist of course – just as before.
If you have followed this comment carefully so far, you will realize that layout is activated now by default!
Therefore ignore_images/ignore_grahics has no effect - just the same as with pymupdf4llm under the Layout regime.
The will become effective again if you deactivate layout – again as before when using pymupdf4llm.

As per the tags around image text: A HTML-avid person will recognize them as HTML comments. We thought that it was about time to let the LLM consumers know that these wrappers are not page content.

@MW_UK It seems like you were maybe wanting to use PyMuPDF in non-layout mode. Check the ignore_images parameter in the docs here: Document - PyMuPDF documentation . It only applies if use_layout is False - see: Functions - PyMuPDF documentation

Thanks both - the presence of the tags is not a major issue, and yes, I do see the layout comment now. I think I just got used to ignoring it as it was not a real problem.

My real question is about any other tags which may be included in the outputs?

I couldn’t find anywhere in the documentation that details which extracted feature types are wrapped in such tags.

HTML-savvy or not - without scanning the entire Markdown library for substrings which look like html comments, I’m just guessing at the moment.

Any advice?

Cheers

HI @MW_UK , firstly sorry for the late reply here. If I understand correctly you think there could be other tags inside the Markdown ( but not standard Markdown tags ). In this case I think you would need to scan the Markdown for substrings like you say. However, I don’t think our to_markdown() method produces any additional inline tagging at the moment when layout is enabled.

Thanks @Jamie_Lemon. That’s great thanks. I was indeed just wondering if there could be any other tags in your to_markdown().

I’ll assume not :slight_smile:

1 Like

I have discovered and html tags in Markdown outputs.

Sorry to bring this up again - it would be helpful to understand the engine here.

Are these tags being carried verbatim from PDF styling, or are they being encoded by the Markdown writer?

If the latter, is there a list anywhere of the html tags which could be applied? Or is it safer to assume any/all could?

@MW_UK We don’t have an exhaustive list. Our markdown convertor is the engine & I believe it may include some HTML comments and things like <u> for underline tags if they are found. But overall HTML syntax should be pretty rare.

1 Like