Skip to content

Commit

Permalink
Finish the PDF doc
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Dec 3, 2023
1 parent d3c232b commit 61801a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 43 deletions.
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
".rst": "restructuredtext",
}

pygments_style = "sphinx"

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

Expand Down
63 changes: 20 additions & 43 deletions docs/creating_pdf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,82 +29,72 @@ If you need bytes
*See the full example*
:download:`here <_static/examples/creating_pdf/text_pdf_bytes_1.py>`

The generated PDF will have 10,000 characters of text, which is about 2 pages.
The generated PDF will consist of a single page with little text on it.

If you want to provide texts to be used:
If you want to control number of pages created, you could:

- Increase the value of ``max_nb_chars`` accordingly.
- Set value of ``wrap_chars_after`` to 80 characters to force longer pages.
- Insert manual page breaks and other content.
- Pass the list of texts to be used in ``texts`` argument.
- Pass the number of pages to be created in ``nb_pages`` argument.

----

See the example below for ``max_nb_chars`` tweak:
See the example below for ``texts`` tweak:

.. container:: jsphinx-download

.. literalinclude:: _static/examples/creating_pdf/text_pdf_bytes_2.py
:language: python
:lines: 11-
:lines: 3-

*See the full example*
:download:`here <_static/examples/creating_pdf/text_pdf_bytes_2.py>`

----

See the example below for ``wrap_chars_after`` tweak:
See the example below for ``nb_pages`` tweak:

.. container:: jsphinx-download

.. literalinclude:: _static/examples/creating_pdf/text_pdf_bytes_3.py
:language: python
:lines: 11-
:lines: 3-

*See the full example*
:download:`here <_static/examples/creating_pdf/text_pdf_bytes_3.py>`

If you need files
~~~~~~~~~~~~~~~~~
There's a so called `graphic` PDF file provider available. Produced PDF files
would not contain text, so don't use it when you need text based content.
However, sometimes you just need a valid file in PDF format, without
caring much about the content. That's where a GraphicPdfFileProvider comes to
rescue:

.. container:: jsphinx-download

.. literalinclude:: _static/examples/creating_pdf/text_pdf_file_1.py
:language: python
:lines: 2-3, 7-
:lines: 3-

*See the full example*
:download:`here <_static/examples/creating_pdf/text_pdf_file_1.py>`

The generated file will contain a random graphic (consisting of lines and
shapes of different colours).

----

One of the most useful arguments supported is ``size``.
With ``texts`` tweak:

.. container:: jsphinx-download

.. literalinclude:: _static/examples/creating_pdf/text_pdf_file_2.py
:language: python
:lines: 7-
:lines: 3-

*See the full example*
:download:`here <_static/examples/creating_pdf/text_pdf_file_2.py>`

----

One of the most useful arguments supported is ``size``.
With ``nb_pages`` tweak:

.. container:: jsphinx-download

.. literalinclude:: _static/examples/creating_pdf/text_pdf_file_3.py
:language: python
:lines: 7-
:lines: 3-

*See the full example*
:download:`here <_static/examples/creating_pdf/text_pdf_file_3.py>`
Expand All @@ -122,56 +112,43 @@ If you need bytes
*See the full example*
:download:`here <_static/examples/creating_pdf/graphic_pdf_bytes_1.py>`

The generated PDF will have 10,000 characters of text, which is about 2 pages.

If you want PDF with more pages, you could either:
The generated PDF will consist of a single page with a colored square on it.

- Increase the value of ``max_nb_chars`` accordingly.
- Set value of ``wrap_chars_after`` to 80 characters to force longer pages.
- Insert manual page breaks and other content.
If you want PDF with more pages, provide the ``nb_pages`` argument.

----

See the example below for ``max_nb_chars`` tweak:
See the example below for ``nb_pages`` tweak:

.. container:: jsphinx-download

.. literalinclude:: _static/examples/creating_pdf/graphic_pdf_bytes_2.py
:language: python
:lines: 11-
:lines: 3-

*See the full example*
:download:`here <_static/examples/creating_pdf/graphic_pdf_bytes_2.py>`

If you need files
~~~~~~~~~~~~~~~~~
There's a so called `graphic` PDF file provider available. Produced PDF files
would not contain text, so don't use it when you need text based content.
However, sometimes you just need a valid file in PDF format, without
caring much about the content. That's where a GraphicPdfFileProvider comes to
rescue:

.. container:: jsphinx-download

.. literalinclude:: _static/examples/creating_pdf/graphic_pdf_file_1.py
:language: python
:lines: 2-3, 7-
:lines: 3-

*See the full example*
:download:`here <_static/examples/creating_pdf/graphic_pdf_file_1.py>`

The generated file will contain a random graphic (consisting of lines and
shapes of different colours).

----

One of the most useful arguments supported is ``size``.
With ``nb_pages`` tweak:

.. container:: jsphinx-download

.. literalinclude:: _static/examples/creating_pdf/graphic_pdf_file_2.py
:language: python
:lines: 7-
:lines: 3-

*See the full example*
:download:`here <_static/examples/creating_pdf/graphic_pdf_file_2.py>`

0 comments on commit 61801a7

Please sign in to comment.