Skip to content

Office to PDF Sample: Configuration and Run Guide (Third-Party Engine)

This guide explains how to configure and run the Foxit PDF SDK Office to PDF sample. To learn how to call the related APIs and use this feature module, see Office to PDF.

System Requirements

  • Platforms: Windows, Linux (x86, x64, and armv8)
  • Languages: C, C++, Python, Java, C#, Node.js, Go
  • License: A license key that includes the Conversion module
  • SDK versions:
    • Word and Excel: SDK C++/C#/Java 7.3+, SDK 7.4+, SDK Python 8.3+
    • PowerPoint: SDK C/C++/C#/Java 7.4+, SDK Python 8.3+
    • Word/Excel/PowerPoint: SDK Node.js 10.0+

The versions above are the minimum SDK versions that first introduced the features described in this guide for each listed language. Refer to the package documentation and release notes for the latest versions and platform differences.

Runtime Requirements

Before running the sample or calling the related module classes, ensure the following conditions are met:

  • Windows: Microsoft Office 2007+ or WPS Office is installed.
  • Excel conversion: Before converting Excel files to PDF, set a default printer on Windows (a virtual printer is acceptable).
  • Linux x86/x64: LibreOffice is installed.
  • Linux armv8: Kingsoft WPS Office is installed.
  • LibreOffice compatibility: Use LibreOffice 7.0+. If you encounter the error "An unknown error has occurred", set the following environment variable before running the program, where x represents the LibreOffice version number:
    sh
    export URE_BOOTSTRAP=vnd.sun.star.pathname:/opt/libreoffice7.x/program/fundamentalrc

Office Engine Selection on Windows

Starting with version 11.1, Windows supports switching between the Microsoft engine and the WPS engine through the engine parameter. If this parameter is not specified, the Microsoft engine is used by default.

  • C++ / Java / Python / Node.js / C# / Go: engine enum values are e_Office2PdfEngineMicrosoft and e_Office2PdfEngineWps
  • C: engine enum values are e_FSOffice2PdfEngineMicrosoft and e_FSOffice2PdfEngineWps
  • Linux still specifies the LibreOffice / WPS engine path through engine_path; this interface change does not affect Linux usage

The following example shows how to explicitly switch to the WPS engine on Windows:

c++

// 以下示例仅以 Word 文档转换并显式选择 WPS 引擎为例。
#include "include/addon/conversion/fs_convert.h"
...

WString word_file_path = L"test.doc";
WString output_path = L"saved.pdf";
foxit::addon::conversion::Word2PDFSettingData word_convert_setting_data;

foxit::addon::conversion::Convert::FromWord(
    word_file_path,
    L"",
    output_path,
    word_convert_setting_data,
    foxit::addon::conversion::Convert::e_Office2PdfEngineWps);

NOTE

If both WPS Office and Microsoft Office are installed and WPS "Office compatibility mode" is enabled, the system may open documents with WPS instead of Office without the user noticing, even when the interface shows "Microsoft Word". To avoid this, disable all "Compatible with Microsoft Office" options in the WPS configuration tool.

Obtaining LibreOffice to PDF Resources

Foxit Office to PDF supports two ways to invoke the LibreOffice engine:

  • Direct LibreOffice engine invocation: No additional resource package is required; ensure LibreOffice is installed on the system. Multithreaded conversion is not supported.
  • Foxit-provided LibreOffice executable: Requires downloading a dedicated resource package from Foxit. The dedicated package includes a Foxit-optimized LibreOffice engine and supports multithreaded conversion.

Obtain the resource package:

Request a trial through the [Foxit Developer Hub][foxit-dev-hub], or contact your Foxit technical support team and sales representatives to obtain the dedicated LibreOffice to PDF resource package.

Linux Engine Path Configuration Guide

When using the Office to PDF feature module or running the sample on Linux, configure the engine_path parameter correctly to specify the engine path. The following describes configuration for different Linux architectures:

1. Linux x86/x64 architecture:

  • Engine type: LibreOffice
  • Parameter configuration: Set engine_path to the directory containing the LibreOffice engine.
  • Path lookup: Find the full path to the LibreOffice engine by running the following command in a terminal:
    bash
    locate soffice.bin
  • Example: If the command returns /usr/lib/libreoffice/program/soffice.bin, set engine_path to /usr/lib/libreoffice/program.

2. Linux x86/x64 architecture:

  • Engine type: Foxit dedicated LibreOffice
  • Parameter configuration: Set engine_path to the directory containing the Foxit dedicated LibreOffice engine.
  • Example: See the "Configure the sample" section below.

3. Linux armv8 architecture:

  • Engine type: Kingsoft WPS Office
  • Parameter configuration: Set engine_path to the directory containing the WPS engine library (librpcwpsapi.so).
  • Path lookup: Manually locate the directory that contains the librpcwpsapi.so file.
  • Example: If librpcwpsapi.so is located in /opt/kingsoft/wps-office/office6, set engine_path to /opt/kingsoft/wps-office/office6.

Sample Run Guide (Linux x64 C++)

Sample location:

  • The LibreOffice to PDF sample is located in the \examples\simple_demo\office2pdf directory. The configuration below uses the Linux x64 C++ library as an example.

Engine selection:

  • Direct LibreOffice engine invocation: See Linux Engine Path Configuration Guide above.
  • Foxit dedicated LibreOffice executable: Configure the dedicated resource engine path as described below.

Configuration steps:

  1. Build the office2pdf resource directory:

    • Extract the dedicated resource package to a specified directory.
    • The extracted directory structure should look like this:
    x86/
    ├── fxoffice2pdf
    x64/
    ├── fxoffice2pdf

    Tip: Select the engine file that matches your operating system architecture.

  2. Configure the sample:

    • Edit \examples\simple_demo\pdf2office\office2pdf.cpp to configure the sample.
    • Based on your CPU architecture, set the engine_path parameter to the full path of x64/fxoffice2pdf or x86/fxoffice2pdf under the dedicated resource engine directory.
    c++
    WString engine_path = L"/resource-folder/x64/fxoffice2pdf"; // 请替换为正确的引擎路径。
    foxit::addon::conversion::Convert::FromWord(word_file_path, L"", output_path, engine_path, word_convert_setting_data);
  3. Run the sample:

    • After configuration is complete, see Run Samples for instructions on running the sample.