Section:

Examples of converting PDF to Word using command-line

Apryse's PDF2Word is a command-line application designed to convert PDF documents to Word files while preserving the fonts and formats of the PDF. This section covers the basic usage of PDF2Word, explaining all of the available options.

Basic Syntax

The basic command-line syntax is:

pdf2word [options] -in inputfile -out outputfile

The '-in' parameter can be abbreviated as '-i', and the '-out' parameter can be abbreviated as '-o'.

If you are calling PDF2Word from the console or a BAT file, you may use relative file names. However, if you are calling it from an application or a server, you should be using absolute file names.

See more options in Command-Line Summary for PDF2Word.

General Usage Examples

Example 1. The simplest command line: Convert PDF to Word DOCX.

Note:

  • Converts 'my.pdf' to 'my.docx' located in the current working folder.

pdf2word -in my.pdf -out my.docx

Example 2. Convert PDF to a specific output file name.

Notes:

  • The '-in' (or '-i') parameter is used to specify the input file. You can use relative and/or absolute file name.
  • The '-out' (or '-o') parameter is used to specify the output file. You can use relative and/or absolute file name.

pdf2word -in my.pdf -out outDOCX.docx

Example 3. Convert PDF to a specific output file type.

Notes:

  • The '-output' parameter is used to specify the output file type. Possible output types are DOCX, DOC and RTF.
  • Alternatively, you can omit the '-output' parameter and specify the output file type as the file extension of the output file name, i.e. .docx, .doc or .rtf.

pdf2word -output rtf -in my.pdf -out outRTF.rtf

Example 4. Convert a password-protected PDF.

Notes:

  • The '-password' parameter is used to specify the master password required to open the protected document.
  • The password provided must give unrestricted content extraction permissions.

pdf2word -password MyPDFPassword -in my.pdf -out myDOC.doc

Example 5. Convert specific pages in PDF.

Notes:

  • The '-pages' parameter is used to specify which page(s) to convert.
  • You can specify a single page, e.g. '-pages 1' or a range of pages, e.g. '-pages 1-2'.

pdf2word -pages 1-2 -in my.pdf -out my.docx

Example 6. Batch convert PDF files.

Notes:

  • The '-in' (or '-i') parameter supports multiple input file names. Separate each input file name with a space.
  • Output files will be generated in the same folder as the input, e.g. 'a.doc', 'b.doc' and 'c.doc'.
  • The number of input file names must match the number of output file names.
  • For Windows (not available for Linux and Mac), you can also use wildcards with the '-in' parameter and omitting the '-out' parameter to tell the application to auto-generate the output file names based on the input file names, e.g. 'pdf2word -in *.pdf'.

pdf2word -in a.pdf b.pdf c.pdf -out a.doc b.doc c.doc

Exit Codes

To provide additional feedback, PDF2Word returns exit codes after completing processing. The exit codes can be used to provide user feedback, for logging, etc. This is particularly important for applications running in an unattended environment.

The following table lists possible exit codes and their descriptions:

sh

1Exit Code Description
2--------------- ---------------------------------------------------------------
30 All files converted successfully.
41 Invalid parameter. One or more parameters were invalid.
52 License problem. Invalid license; license or evaluation
6 expired; the feature you are trying to use is not enabled with
7 the license you have.
83 Cannot open input. Input file name is invalid; file does not
9 exist; network is unavailable; drive was ejected; not enough
10 permissions to access the input file.
114 Cannot create output. Output file name is invalid; network is
12 unavailable; drive was ejected or full; another application has
13 opened the same file; not enough permission to create the
14 output file.
155 Invalid input. Input file exists, but it is invalid. Usually
16 indicates an invalid or corrupt PDF, or any other input file
17 parsing problem, other than password problems.
186 Invalid output. Output file was created, but it is invalid.
19 There were some problems, such as fonts could not be embedded,
20 some issues that make the output corrupt.
217 Encrypted input. Input file is encrypted, and there is no
22 password, or the password is invalid, or the password does not
23 give permission to complete the requested operation.
248 Timeout. The whole or part of the operation has timed out. You
25 may get better luck by increasing the timeout, because some
26 operations take a lot of time to complete.
279 Cancelled. The operation has been cancelled. This is very
28 unlikely in an SDK, which has no user interaction.
2910 Access denied. Temporary file could not be created; registry
30 could not be accessed; any other system-level denial of access.
31 Exception: If the input or output file cannot be accessed, the
32 error codes 3 and 4 are used instead.
3317 Invalid setup. The product is not set up correctly. Files or
34 registry got corrupted. Please reinstall.
3518 Out of memory. There was not enough memory to complete the
36 operation. Note: It is not guaranteed that you get this error
37 when you run out of memory. You could also get 19 - Internal
38 error.
3919 Internal error. Invalid operation; unknown error; crash; access
40 violation.
4120 Page too large. PDF page is too large for Word.
4221 Word automation error. Error when converting from RTF to
43 DOC/DOCX using Microsoft Word automation.

All codes other then '0' indicate that there was an error during the conversion process.

The following illustrates a sample Windows batch script that processes exit codes:

sh

1@echo off
2rem convert my.pdf to my.docx in the current working folder
3pdf2word -in my.pdf -out my.docx
4if errorlevel 19 goto othererror
5if errorlevel 3 goto inputerr
6if errorlevel 0 goto exit
7
8:inputerr
9echo No input files specified.
10goto exit
11
12:othererror
13echo An error encountered during processing.
14goto exit
15
16:exit

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales