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
Copy file name to clipboardExpand all lines: docs/app3.rst
+82Lines changed: 82 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -421,6 +421,88 @@ Typical document page sizes are **ISO A4** and **Letter**. A **Letter** page has
421
421
422
422
423
423
424
+
425
+
.. _CSS_Support:
426
+
427
+
CSS Support
428
+
--------------------------------------------
429
+
430
+
For now, only a subset of CSS properties are supported.
431
+
432
+
The underlying C library MuPDF supports a subset of HTML4 and CSS2. The primary goal of the HTML/CSS support is to serve as a popular and convenient way to style text — not to faithfully reproduce websites in PDF.
433
+
434
+
What Works
435
+
~~~~~~~~~~~~~
436
+
437
+
The following list shows the supported properties, grouped by category.
The properties ``position`` & ``display`` are supported in a very limited way. Only the values ``position: relative`` and ``display: block`` are supported.
Background images are not supported, but the ``background`` property can be used to set a background color for a text block, which is then rendered as a filled rectangle behind the text.
Modern CSS (CSS3+): no ``flexbox``, ``grid``, ``custom properties`` (--vars), ``calc()``, ``transitions``, ``animations``, ``position: absolute`` / ``fixed``, ``float``, ``clear`` and so on.
505
+
424
506
.. rubric:: Footnotes
425
507
426
508
.. [#f1] MuPDF supports "deep-copying" objects between PDF documents. To avoid duplicate data in the target, it uses so-called "graftmaps", like a form of scratchpad: for each object to be copied, its :data:`xref` number is looked up in the graftmap. If found, copying is skipped. Otherwise, the new :data:`xref` is recorded and the copy takes place. PyMuPDF makes use of this technique in two places so far: :meth:`Document.insert_pdf` and :meth:`Page.show_pdf_page`. This process is fast and very efficient, because it prevents multiple copies of typically large and frequently referenced data, like images and fonts. However, you may still want to consider using garbage collection (option 4) in any of the following cases:
Copy file name to clipboardExpand all lines: docs/archive-class.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Archive
10
10
11
11
This class represents a generalization of file folders and container files like ZIP and TAR archives. Archives allow accessing arbitrary collections of file folders, ZIP / TAR files and single binary data elements as if they all were part of one hierarchical tree of folders.
12
12
13
-
In PyMuPDF, archives are currently only used by :ref:`Story` objects to specify where to look for fonts, images and other resources.
13
+
In PyMuPDF, archives are currently only used by :ref:`Story` objects and as an :ref:`option when opening files <Full_Options_for_Opening_a_File>` to specify where to look for fonts, images and other resources.
: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|.
14
+
: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
15
16
16
17
17
@@ -20,38 +20,97 @@ Files to PDF
20
20
.. code-block:: python
21
21
22
22
import pymupdf
23
-
23
+
24
+
# Convert Markdown to PDF
25
+
md_doc = pymupdf.open("example.md")
26
+
pdfdata = md_doc.convert_to_pdf()
27
+
pdf_doc = pymupdf.open(stream=pdfdata)
28
+
pdf_doc.save("example.pdf")
29
+
30
+
# Convert XPS to PDF
24
31
xps = pymupdf.open("input.xps")
25
-
pdfbytes= xps.convert_to_pdf()
26
-
pdf = pymupdf.open("pdf", pdfbytes)
32
+
pdfdata= xps.convert_to_pdf()
33
+
pdf = pymupdf.open(stream=pdfdata)
27
34
pdf.save("output.pdf")
28
35
36
+
.. _Markdown_to_PDF:
29
37
38
+
Markdown to PDF
39
+
~~~~~~~~~~~~~~~~~
30
40
31
-
PDF to SVG
32
-
~~~~~~~~~~~~~~~~~~
41
+
As Markdown files are supported input files they can be easily converted to PDF using the :meth:`Document.convert_to_pdf` method.
33
42
34
-
Technically, as SVG files cannot be multipage, we must export each page as an SVG.
43
+
In the simplest case you can just open the Markdown file and call the method to get a PDF representation of the content.
35
44
36
-
To get an SVG representation of a page use the :meth:`Page.get_svg_image` method.
37
45
38
-
**Example**
46
+
Defining paper size
47
+
"""""""""""""""""""
48
+
49
+
The default paper size is 400 x 600 :doc:`rect` but you can specify a custom paper size if you wish, to do this just send through the `rect` parameter as required, for example:
By default, the Markdown content will be converted to PDF using a default CSS stylesheet. However, you can specify your own CSS stylesheet to customize the appearance of the resulting PDF. To do this, define your `css` and apply it.
60
+
61
+
For example, to make all ``h1`` headers red (The single ``#`` symbol in Markdown), you could do the following:
62
+
63
+
.. code-block:: python
64
+
65
+
md_doc = pymupdf.open( # open the Markdown document in A4 size
The :ref:`support for CSS <CSS_Support>` is currently limited.
79
+
80
+
81
+
Defining Fonts
82
+
"""""""""""""""""
83
+
84
+
Fonts can be defined by using the `archive` parameter to provide a custom :ref:`Archive` containing the font files.
85
+
86
+
The fonts must exist in an archive which is provided to the `archive` parameter when opening the Markdown file. The CSS can then refer to these fonts by their names as defined in the archive.
87
+
88
+
For example, assuming you have access to the source files for the "Comic Sans" font for all text, you could do the following:
89
+
90
+
.. code-block:: python
91
+
92
+
# Global CSS instructions to use the "Comic Sans" font for all text. The font files must be provided in the archive.
0 commit comments