Skip to content

Commit 27b89da

Browse files
committed
Document new function markdown_to_pdf
1 parent 4c37225 commit 27b89da

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

docs/pymupdf4llm/api.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,29 @@ The PyMuPDF4LLM API
279279
}
280280
}
281281

282+
.. method:: markdown_to_pdf(md_path: str | pathlib.Path, \
283+
user_css: str | None = None, \
284+
page_rect: rect-like | None = None, \
285+
margins: rect-like | None) = None, \
286+
archive: str | pathlib.Path | None = None, \
287+
output_path: str | pathlib.Path | None = None) -> pymupdf.Document | None
288+
289+
Convert the markdown text content of the file specified by `md_path` into a PDF document.
290+
291+
The function is always available -- independently of whether you are using the PyMuPDF Layout module or not.
292+
293+
:arg str|Path md_path: the file path of the markdown file to be converted.
294+
295+
:arg str|None user_css: optional, a string of CSS code to be applied to the markdown content. This may be used to customize the appearance of the generated PDF document. If `None` (default), the built-in default CSS is used.
296+
297+
:arg rect-like|None page_rect: optional, the rectangle defining the page boundaries for the generated PDF document. If `None` (default), ISO A4 page dimensions are used. To use one of PyMuPDF's predefined page formats, use e.g. ``pymupdf.paper_rect("Letter")``.
298+
299+
:arg rect-like|None margins: optional, the margins (borders) for the generated pages. This must be a sequence of four floats ``[left, top, right, bottom]`` specifying the respective border width in points (1/72 inches). If `None` (default), the default ``[50, 50, 50, 50]`` margins are used.
300+
301+
:arg str|Archive|None archive: optional. This is be required if the markdown source references images that are **not** stored in the same folder as the markdown file. In this case, `archive` must be a `pymupdf.Archive` object which provides access to the respective image files. If `None` (default), it is assumed that all referenced images are stored in the same folder as the markdown file. The parameter **may** also be required if a custom ``user_css`` references external resources like font files.
302+
303+
:arg str|Path|None output_path: optional, the file path where the generated PDF document will be saved. If specified, the generated PDF will be saved to that location. If `None` (default), the document is returned as a `pymupdf.Document` object.
304+
282305
.. note::
283306

284307
Please see `this site <https://github.com/pymupdf/pymupdf4llm/discussions/327>`_ for more background and the current status of further improvements regarding usage with :ref:`PyMuPDF Layout <pymupdf-layout>`.

0 commit comments

Comments
 (0)