-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0121a2a
commit d937023
Showing
5 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from fake import FAKER, TextPdfGenerator | ||
|
||
texts = ["Page 1 content", "Page 2 content", "Page 3 content"] | ||
pdf_bytes = FAKER.pdf(texts=texts, generator=TextPdfGenerator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
Creating files | ||
============== | ||
|
||
.. Internal references | ||
.. _fake.py: https://github.com/barseghyanartur/fake.py/ | ||
.. _Creating archives: https://fakepy.readthedocs.io/en/latest/creating_archives.html | ||
.. _Creating DOCX: https://fakepy.readthedocs.io/en/latest/creating_docx.html | ||
.. _Creating images: https://fakepy.readthedocs.io/en/latest/creating_images.html | ||
.. _Creating ODT: https://fakepy.readthedocs.io/en/latest/creating_odt.html | ||
.. _Creating PDF: https://fakepy.readthedocs.io/en/latest/creating_pdf.html | ||
|
||
Creation of specific file formats is extensively covered in dedicated | ||
sections: | ||
|
||
- `Creating archives`_ | ||
- `Creating DOCX`_ | ||
- `Creating images`_ | ||
- `Creating ODT`_ | ||
- `Creating PDF`_ | ||
|
||
This section covers basic concepts of file generation within `fake.py`_. | ||
|
||
It's possible to generate either bytes or files on the file system. | ||
|
||
- When generating bytes, the returned value is ``BytesValue``. | ||
|
||
- When generating files on the file system, the returned value | ||
is ``StringValue``. | ||
|
||
Both ``BytesValue`` and ``StringValue`` behave like ``bytes`` and ``str`` | ||
respectively, but have a ``data`` (``dict``) property, which contains useful | ||
meta-data about the specific kind of file. | ||
|
||
For generated files, it will always have the following: | ||
|
||
- ``storage``: Storage class that was used to generate the file. | ||
- ``filename``: Absolute file path. It's important to know, that string | ||
representation of the file contains a relative file path. | ||
|
||
---- | ||
|
||
See the example below for a graphic PDF generation: | ||
|
||
.. container:: jsphinx-toggle-emphasis | ||
|
||
.. code-block:: python | ||
:name: test_pdf_file | ||
:emphasize-lines: 3 | ||
from fake import FAKER | ||
pdf_file = FAKER.pdf_file() | ||
print(pdf_file) | ||
# tmp/tmpnvwoa2ap.pdf | ||
print(pdf_file.data["filename"]) | ||
# /tmp/tmp/tmpnvwoa2ap.pdf | ||
print(pdf_file.data) | ||
# {'storage': <fake.FileSystemStorage at 0x7f72221fd750>, | ||
# 'filename': '/tmp/tmp/tmpragc8wyr.pdf', | ||
# 'content': None} | ||
---- | ||
|
||
See the example below for a text PDF generation: | ||
|
||
.. container:: jsphinx-toggle-emphasis | ||
|
||
.. code-block:: python | ||
:name: test_text_pdf_file | ||
:emphasize-lines: 3 | ||
from fake import FAKER | ||
pdf_file = FAKER.text_pdf_file() | ||
print(pdf_file) | ||
# tmp/tmpragc8wyr.pdf | ||
print(pdf_file.data["filename"]) | ||
# /tmp/tmp/tmpragc8wyr.pdf | ||
print(pdf_file.data) | ||
# {'storage': <fake.FileSystemStorage at 0x7f7222157750>, | ||
# 'filename': '/tmp/tmp/tmpragc8wyr.pdf', | ||
# 'content': 'If dutch beats although complex.'} | ||
Note, that text PDF does contain full text of the entire document in the | ||
``content`` key. | ||
|
||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters