Skip to content

Commit 76587a1

Browse files
committed
Updates Pro page with new API and adds images to converting files.
1 parent 8be2807 commit 76587a1

2 files changed

Lines changed: 134 additions & 23 deletions

File tree

docs/converting-files.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,23 @@ To get an SVG representation of a page use the :meth:`Page.get_svg_image` method
198198
199199
doc.close()
200200
201+
202+
PDF to Images
203+
~~~~~~~~~~~~~~~~~~
204+
205+
In order to convert a document to images, you should iterate the document pages, convert to :doc:`pixmap` and save, e.g.:
206+
207+
.. code-block:: python
208+
209+
doc = pymupdf.open("input.pdf")
210+
211+
for i, page in enumerate(doc):
212+
pix = page.get_pixmap(dpi=200)
213+
pix.save(f"page-{i+1}.png")
214+
215+
doc.close()
216+
217+
201218
PDF to DOCX
202219
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203220

docs/pymupdf-pro/index.rst

Lines changed: 117 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Enhance |PyMuPDF| capability with **Office** document support & **RAG/LLM** inte
2121
- Supports text and table extraction, document conversion and more.
2222
- Includes the commercial version of |PyMuPDF4LLM|.
2323

24-
To enquire about obtaining a commercial license, then `use this contact page <https://artifex.com/contact/>`_.
24+
To enquire about obtaining a commercial license, then `use this contact page <https://artifex.com/contact/?utm_source=rtd-pymupdf&utm_medium=referral&utm_content=page-link&utm_campaign=docs>`_.
2525

26+
Trial license keys are available for evaluation purposes. Please `fill out the form on this page <https://pymupdf.pro/try-pro/?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button-pymupdf-pro-page&utm_campaign=docs>`_ to obtain a trial key.
2627

2728
.. note::
2829

@@ -100,24 +101,6 @@ Import |PyMuPDF Pro| and you can then reference **Office** documents directly, e
100101
From then on you can work with document pages just as you would do normally, but with respect to the `restrictions <PyMuPDFPro_Restrictions>`.
101102

102103

103-
Converting an **Office** document to |PDF|
104-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105-
106-
The following code snippet can convert your **Office** document to |PDF| format:
107-
108-
.. code-block:: python
109-
110-
import pymupdf.pro
111-
pymupdf.pro.unlock()
112-
113-
doc = pymupdf.open("my-office-doc.xlsx")
114-
115-
pdfdata = doc.convert_to_pdf()
116-
with open('output.pdf', 'wb') as f:
117-
f.write(pdfdata)
118-
119-
120-
121104
.. _PyMuPDFPro_Restrictions:
122105

123106
Restrictions
@@ -128,15 +111,15 @@ Restrictions
128111

129112
**Only the first 3 pages of any document will be available.**
130113

131-
To unlock full functionality you should `obtain a trial key <https://pymupdf.pro/try-pro/?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button-pymupdf-pro-page>`_.
114+
To unlock full functionality you should `obtain a trial key <https://pymupdf.pro/try-pro/?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button-pymupdf-pro-page&utm_campaign=docs>`_.
132115

133116

134117
.. _PyMuPDFPro_TrialKeys:
135118

136119
Trial keys
137120
-----------------------
138121

139-
To obtain a license key `please fill out the form on this page <https://pymupdf.pro/try-pro/?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button-pymupdf-pro-page>`_. You will then have the trial key emailled to the address you submitted.
122+
To obtain a license key `please fill out the form on this page <https://pymupdf.pro/try-pro/?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button-pymupdf-pro-page&utm_campaign=docs>`_. You will then have the trial key emailled to the address you submitted.
140123

141124

142125
Using a key
@@ -151,7 +134,79 @@ Initialize |PyMuPDF Pro| with a key as follows:
151134
pymupdf.pro.unlock(my_key)
152135
# PyMuPDF has now been extended with PyMuPDF Pro features.
153136
154-
This will allow you to evaluate the product for a limited time. If you want to use |PyMuPDF Pro| after this time you should then `enquire about obtaining a commercial license <https://artifex.com/products/pymupdf-pro/>`_.
137+
This will allow you to evaluate the product for a limited time. If you want to use |PyMuPDF Pro| after this time you should then `enquire about obtaining a commercial license <https://artifex.com/contact/?utm_source=rtd-pymupdf&utm_medium=referral&utm_content=page-link&utm_campaign=docs>`_.
138+
139+
140+
141+
142+
Converting
143+
-------------
144+
145+
**Office** document to |PDF|
146+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147+
148+
Use the :meth:`office_to_pdf()` method to convert an **Office** document to |PDF|, e.g.:
149+
150+
.. code-block:: python
151+
152+
import pymupdf.pro
153+
pymupdf.pro.unlock()
154+
155+
pymupdf.pro.office_to_pdf("input.docx", "output.pdf")
156+
157+
158+
If you require a byte representation of the PDF data, you can use the :meth:`office_to_pdf()` without specifying an output file, e.g.:
159+
160+
.. code-block:: python
161+
162+
import pymupdf.pro
163+
pymupdf.pro.unlock()
164+
165+
pdfdata = pymupdf.pro.office_to_pdf("input.docx")
166+
167+
168+
**Office** document to Images
169+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
170+
171+
In order to convert an **Office** document to images, you should iterate the document pages, convert to :doc:`../pixmap` and save, e.g.:
172+
173+
.. code-block:: python
174+
175+
doc = pymupdf.open("input.docx")
176+
177+
for i, page in enumerate(doc):
178+
pix = page.get_pixmap(dpi=200)
179+
pix.save(f"page-{i+1}.png")
180+
181+
doc.close()
182+
183+
**Office** document to |Markdown|
184+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185+
186+
Use the :meth:`office_to_markdown()` method to convert an **Office** document to |Markdown|, e.g.:
187+
188+
.. code-block:: python
189+
190+
import pymupdf.pro
191+
pymupdf.pro.unlock()
192+
193+
pymupdf.pro.office_to_markdown("input.docx", "output.md")
194+
195+
If you require a string representation of the Markdown data, you can use the :meth:`office_to_markdown()` without specifying an output file.
196+
197+
**Office** document to |JSON|
198+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
199+
200+
Use the :meth:`office_to_json()` method to convert an **Office** document to |JSON|, e.g.:
201+
202+
.. code-block:: python
203+
204+
import pymupdf.pro
205+
pymupdf.pro.unlock()
206+
207+
pymupdf.pro.office_to_json("input.docx", "output.json")
208+
209+
If you require a string representation of the JSON data, you can use the :meth:`office_to_json()` without specifying an output file.
155210

156211

157212
Fonts
@@ -170,9 +225,48 @@ This can be controlled with keyword-only args:
170225
Function `pymupdf.pro.get_fontpath()` returns a tuple of all font directories used by `unlock()`.
171226

172227

228+
API
229+
-----------------------
230+
231+
232+
.. method:: office_to_pdf(input_path: str, output_path:str = None) -> bytes | None
233+
234+
Reads the input file and converts its contents into |PDF| format.
235+
236+
:arg str input_path: the input file path.
237+
238+
:arg str output_path: the path to the output file. If `None`, the method returns the bytes of the PDF content.
239+
240+
:returns: Either bytes of the PDF content, `None` if `output_path` is specified.
241+
242+
243+
.. method:: office_to_markdown(input_path: str, output_path:str = None) -> str | None
244+
245+
Reads the input file and outputs the text of its pages in |Markdown| format.
246+
247+
:arg str input_path: the input file path.
248+
249+
:arg str output_path: the path to the output file. If `None`, the method returns the content as a string.
250+
251+
:returns: Either a string of the Markdown representation, `None` if `output_path` is specified.
252+
253+
254+
.. method:: office_to_json(input_path: str, output_path:str = None) -> str | None
255+
256+
Reads the input file and outputs the text of its pages in |JSON| format.
257+
258+
:arg str input_path: the input file path.
259+
260+
:arg str output_path: the path to the output file. If `None`, the method returns the content as a string.
261+
262+
:returns: Either a string of the JSON representation, `None` if `output_path` is specified.
263+
264+
265+
266+
173267
.. raw:: html
174268

175-
<button id="findOutAboutPyMuPDFPro" class="cta orange" onclick="window.location='https://pymupdf.pro/try-pro/?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button-pymupdf-pro-page'">Ready to try PyMuPDF Pro?</button>
269+
<button id="findOutAboutPyMuPDFPro" class="cta orange" onclick="window.location='https://pymupdf.pro/try-pro/?utm_source=rtd-pymupdf&utm_medium=rtd&utm_content=cta-button-pymupdf-pro-page&utm_campaign=docs'">Ready to try PyMuPDF Pro?</button>
176270

177271

178272

0 commit comments

Comments
 (0)