From de82460a036e889d7054a83b9da5512b4179f231 Mon Sep 17 00:00:00 2001 From: Nikita Shevtsov Date: Mon, 25 Sep 2023 15:31:11 +0300 Subject: [PATCH] add more code examples --- .../code_examples/dedoc_add_new_doc_type_tutorial.py | 2 +- docs/source/tutorials/add_new_doc_type.rst | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/source/_static/code_examples/dedoc_add_new_doc_type_tutorial.py b/docs/source/_static/code_examples/dedoc_add_new_doc_type_tutorial.py index 403667ba..b5d9a329 100644 --- a/docs/source/_static/code_examples/dedoc_add_new_doc_type_tutorial.py +++ b/docs/source/_static/code_examples/dedoc_add_new_doc_type_tutorial.py @@ -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) diff --git a/docs/source/tutorials/add_new_doc_type.rst b/docs/source/tutorials/add_new_doc_type.rst index 07fe7b5c..f8d0b148 100644 --- a/docs/source/tutorials/add_new_doc_type.rst +++ b/docs/source/tutorials/add_new_doc_type.rst @@ -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 ------------------------------- @@ -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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -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: