Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions docs/converting-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Converting Files
Files to PDF
~~~~~~~~~~~~~~~~~~

:ref:`Document types supported by PyMuPDF <HowToOpenAFile>` can easily be converted to |PDF| by using the :meth:`Document.convert_to_pdf` method. This method returns a buffer of data which can then be utilized by |PyMuPDF| to create a new |PDF|.

:ref:`Document types supported by PyMuPDF <HowToOpenAFile>` can easily be converted to |PDF| by using the :meth:`Document.save` or :meth:`Document.ez_save` method after they have been opened.

If you require a byte representation of the PDF, you can use :meth:`Document.convert_to_pdf`. This method returns a buffer of data which can then be utilized by |PyMuPDF| to create a new |PDF|.

**Example**

Expand All @@ -23,26 +23,21 @@ Files to PDF

# Convert Markdown to PDF
md_doc = pymupdf.open("example.md")
pdfdata = md_doc.convert_to_pdf()
pdf_doc = pymupdf.open(stream=pdfdata)
pdf_doc.save("example.pdf")
md_doc.ez_save("example.pdf")

# Convert to PDF and get byte representation
pdf_bytes = md_doc.convert_to_pdf()

# Convert XPS to PDF
xps = pymupdf.open("input.xps")
pdfdata = xps.convert_to_pdf()
pdf = pymupdf.open(stream=pdfdata)
pdf.save("output.pdf")
xps_doc = pymupdf.open("input.xps")
xps_doc.ez_save("output.pdf")


.. _Markdown_to_PDF:

Markdown to PDF
~~~~~~~~~~~~~~~~~

As Markdown files are supported input files they can be easily converted to PDF using the :meth:`Document.convert_to_pdf` method.

In the simplest case you can just open the Markdown file and call the method to get a PDF representation of the content.


Defining paper size
"""""""""""""""""""

Expand Down Expand Up @@ -70,8 +65,7 @@ For example, to make all ``h1`` headers red (The single ``#`` symbol in Markdown
css = "h1 {color:red;}"
md_doc.apply_css(css)

pdf_doc = pymupdf.open(stream=md_doc.convert_to_pdf())
pdf_doc.ez_save("red-colored-header.pdf")
md_doc.ez_save("red-colored-header.pdf")

.. note::

Expand Down Expand Up @@ -156,6 +150,7 @@ For example, assuming you have access to the source files for the "Comic Sans" f

md_doc.apply_css(css)

md_doc.ez_save("sample.pdf")



Expand Down
4 changes: 2 additions & 2 deletions docs/header.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
</style>

<div id="searchAndLangugeHolder">
<button id="visit-pymupdf-io" class="cta orange" onclick="window.location='https://pymupdf.io?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button'">pymupdf.io</button>
<button id="visit-pymupdf-io" class="cta orange" onclick="window.location='https://pymupdf.io?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button-header'">pymupdf.io</button>
<form id="headerSearchWidget" class="sidebar-search-container top" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
<input type="hidden" name="check_keywords" value="yes">
Expand Down Expand Up @@ -201,7 +201,7 @@
</a>
</div>
<div class="forumLink">
<div id="forumCTAText"></div><a id="winking-cow-link" style="font-weight: bold;" href="https://forum.mupdf.com">Try our forum! <img alt="MuPDF Forum link logo" id="winking-cow-image" src="https://pymupdf.readthedocs.io/en/latest/_static/forum-logo.gif" width=38px height=auto /></a>
<div id="forumCTAText"></div><a id="winking-cow-link" style="font-weight: bold;" href="https://forum.mupdf.com?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button-header">Try our forum! <img alt="MuPDF Forum link logo" id="winking-cow-image" src="https://pymupdf.readthedocs.io/en/latest/_static/forum-logo.gif" width=38px height=auto /></a>
</div>
</div>

Expand Down
Loading