File: quickstart.convert.rst

package info (click to toggle)
pdf2docx 0.5.9-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 9,480 kB
  • sloc: python: 6,811; makefile: 82; sh: 9
file content (95 lines) | stat: -rw-r--r-- 2,157 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
.. include:: header.rst

Convert PDF
=======================

We can use either the :py:class:`~pdf2docx.converter.Converter` class, or 
a wrapped method :py:meth:`~pdf2docx.main.parse` to convert all/specified 
pdf pages to docx. Multi-processing is supported in case pdf file with a
large number of pages. 


Example 1: convert all pages
----------------------------------

::

  from pdf2docx import Converter

  pdf_file = '/path/to/sample.pdf'
  docx_file = 'path/to/sample.docx'

  # convert pdf to docx
  cv = Converter(pdf_file)
  cv.convert(docx_file)      # all pages by default
  cv.close()


An alternative using ``parse`` method::

  from pdf2docx import parse

  pdf_file = '/path/to/sample.pdf'
  docx_file = 'path/to/sample.docx'

  # convert pdf to docx
  parse(pdf_file, docx_file)


Example 2: convert specified pages
----------------------------------------

* Specify pages range by ``start`` (from the first page if omitted) and 
  ``end`` (to the last page if omitted)::

    # convert from the second page to the end (by default)
    cv.convert(docx_file, start=1)

    # convert from the first page (by default) to the third (end=3, excluded)
    cv.convert(docx_file, end=3)

    # convert from the second page and the third
    cv.convert(docx_file, start=1, end=3)


* Alternatively, set separate pages by ``pages``::

    # convert the first, third and 5th pages
    cv.convert(docx_file, pages=[0,2,4])


.. note::
  Refer to :py:meth:`~pdf2docx.converter.Converter.convert` for detailed description 
  on the input arguments.



Example 3: multi-Processing
--------------------------------

Turn on multi-processing with default count of CPU::

  cv.convert(docx_file, multi_processing=True)

Specify the count of CPUs::

  cv.convert(docx_file, multi_processing=True, cpu_count=4)


.. note::
  Multi-processing works for continuous pages specified by ``start`` and ``end`` only.



Example 4: convert encrypted pdf
---------------------------------------

Provide ``password`` to open and convert password protected pdf::

  cv = Converter(pdf_file, password)
  cv.convert(docx_file)
  cv.close()


.. include:: footer.rst