For the complete documentation index, see llms.txt. This page is also available as Markdown.

Convert PDF to Word, Excel, and PowerPoint for Windows, Linux, and macOS: Sample Code in C#, Python,

Convert PDFs to MS Office (DOCX, XLSX, PPTX) without any external third party dependencies. PDF to Word, PDF to Excel, PDF to PowerPoint are all provided with support for C#, Python, C++, Java, PHP, Ruby, Go; on Windows, Linux and Mac.

Setup

  1. Download the Structured Output Module that allows PDF to Office conversion.

  2. Place it in the directory of your project, in a folder called lib and then reference it in the below sample.

Convert PDF to Word

This sample demonstrates how to convert from a PDF to DOCX file.

Convert.WordOutputOptions wordOutputOptions = new Convert.WordOutputOptions();
// Optionally convert only the first page
wordOutputOptions.SetPages(1, 1);
// Requires the Structured Output module
Convert.ToWord(filename, output_filename, wordOutputOptions);
Convert::WordOutputOptions wordOutputOptions;
// Optionally convert only the first page
wordOutputOptions.SetPages(1, 1);
// Requires the Structured Output module
Convert::ToWord(filename, output_filename, wordOutputOptions);
wordOutputOptions := NewWordOutputOptions()
// Optionally convert only the first page
wordOutputOptions.SetPages(1, 1)
// Requires the Structured Output module
ConvertToWord(filename, output_filename, wordOutputOptions)
Convert.WordOutputOptions wordOutputOptions = new Convert.WordOutputOptions();
// Optionally convert only the first page
wordOutputOptions.setPages(1, 1);
// Requires the Structured Output module
Convert.toWord(filename, output_filename, wordOutputOptions);

Convert PDF to Word with Paddle OCR

For scanned or image-based PDFs, SetPreferredOCREngine() lets you choose the Paddle OCR engine instead of the default engine for improved accuracy on low-quality scans and complex layouts, at the cost of longer processing time (see Select OCR Engine for a full comparison). Since Paddle does not support automatic language detection, set the OCR language explicitly with SetCustomOCRLanguage().

Info

SetPreferredOCREngine() is also available on ExcelOutputOptions, PowerPointOutputOptions, and HTMLOutputOptions (for HTML, only when using e_reflow_full mode).

Info

Paddle OCR is currently available in the Windows x64 and Linux x64 builds of the Structured Output Module.

Info-Reducing size when Paddle OCR is not used

If you don't use the Paddle OCR engine, you can delete the paddleocr and onnx directories, located directly under Lib/Windows (Windows) or Lib/Linux (Linux), to reduce package/disk footprint.

Convert PDF to PowerPoint

This sample demonstrates how to convert from a PDF to PPTX file.

Convert PDF to Excel

This sample demonstrates how to convert from a PDF to XLSX file.

Full Sample Code

Convert PDF files to MS Office Full sample code which illustrates how to convert PDF to MS Office files (Word, Excel, PowerPoint). Code sample is available in C++, C#, Java, Python, Go, PHP, Ruby & VB.

Last updated

Was this helpful?