Skip to content

Commit

Permalink
add more code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Shevtsov committed Sep 25, 2023
1 parent 30574db commit de82460
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
file_mime = mimetypes.guess_type(file_path)[0]

djvu_converter.can_convert(file_extension, file_mime) # True
djvu_converter.do_convert(file_dir, name_wo_extension, file_extension) # 'example_with_table7.pdf'
djvu_converter.do_convert(file_dir, name_wo_extension, file_extension) # 'example_with_table.pdf'

file_dir, file_name = "test_dir", "example_with_attachments_depth_1.pdf"
file_path = os.path.join(file_dir, file_name)
Expand Down
12 changes: 12 additions & 0 deletions docs/source/tutorials/add_new_doc_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ You should call the constructor of the base class in the constructor of the curr

* :meth:`~dedoc.converters.AbstractConverter.do_convert` method performs the required file conversion. Don't worry about the file name containing spaces or other unwanted characters because the file has been renamed by the manager.


3 Add the converter to manager config, see :ref:`adding_handlers_to_manager_config`.


General scheme of adding Reader
-------------------------------

Expand Down Expand Up @@ -128,6 +130,11 @@ You should implement the following methods:
* :meth:`~dedoc.converters.AbstractConverter.can_convert`: return True if file extension is `.djvu`. You can see the file ``dedoc/extensions.py`` for more accurate work with extensions.
* :meth:`~dedoc.converters.AbstractConverter.do_convert`: use `ddjvu` utility and run it using ``os.system``. ``._await_for_conversion()`` method ensures that the converted file was saved.

You can use the converter in your code:

.. literalinclude:: ../_static/code_examples/dedoc_add_new_doc_type_tutorial.py
:language: python
:lines: 20, 16-17, 22-27

Implementing of PdfAttachmentsExtractor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -168,6 +175,11 @@ We use PyPDF2 to extract the text and tabula to extract tables. They must be add
We use class ``PdfAttachmentsExtractor`` for attachments extraction (it was mentioned before).
It must be added to the reader's constructor and used in ``read`` method.

You can use the reader in your code:

.. literalinclude:: ../_static/code_examples/dedoc_add_new_doc_type_tutorial.py
:language: python
:lines: 21, 29-41

.. _adding_handlers_to_manager_config:

Expand Down

0 comments on commit de82460

Please sign in to comment.