You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
: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|.
15
+
16
+
17
+
18
+
**Example**
19
+
20
+
.. code-block:: python
21
+
22
+
import pymupdf
23
+
24
+
xps = pymupdf.open("input.xps")
25
+
pdfbytes = xps.convert_to_pdf()
26
+
pdf = pymupdf.open("pdf", pdfbytes)
27
+
pdf.save("output.pdf")
28
+
29
+
30
+
31
+
PDF to SVG
32
+
~~~~~~~~~~~~~~~~~~
33
+
34
+
Technically, as SVG files cannot be multipage, we must export each page as an SVG.
35
+
36
+
To get an SVG representation of a page use the :meth:`Page.get_svg_image` method.
37
+
38
+
**Example**
39
+
40
+
.. code-block:: python
41
+
42
+
import pymupdf
43
+
44
+
doc = pymupdf.open("input.pdf")
45
+
page = doc[0]
46
+
47
+
# Convert page to SVG
48
+
svg_content = page.get_svg_image()
49
+
50
+
# Save to file
51
+
withopen("output.svg", "w", encoding="utf-8") as f:
52
+
f.write(svg_content)
53
+
54
+
doc.close()
55
+
56
+
57
+
PDF to Markdown
58
+
~~~~~~~~~~~~~~~~~
59
+
60
+
By utlilizing the :doc:`PyMuPDF4LLM API <pymupdf4llm/api>` we are able to convert PDF to a Markdown representation.
0 commit comments