Skip to content

Office to PDF (3rd conversion engine)

Foxit PDF SDK provides robust Office to PDF conversion, supporting high-quality conversion of Word, Excel, and PowerPoint documents to PDF. This section explains how to implement this using third-party engines.

Before you begin

Before using this feature, see the Office to PDF example configuration and run guide for system requirements, environment setup, conversion engine parameters, sample execution, and other details.

LibreOffice multi-threaded conversion (Linux x86/x64)

On Linux x86/x64, Foxit PDF SDK provides a dedicated LibreOffice binary that supports multi-threaded Office-to-PDF conversion.

Implementation:

Assign the path to the architecture-specific binary engine to the engine_path parameter to enable multi-threaded conversion.

Code example:

c++
WString engine_path = L"/resource-folder/x64/fxoffice2pdf"; / Replace with the correct engine path.
foxit::addon::conversion::Convert::FromWord(word_file_path, L"", output_path, engine_path, word_convert_setting_data);

See the Foxit PDF SDK multi-threading safety guide for thread-safety details.


The sample code below shows how to use the Office2PDF module in Foxit PDF SDK on Windows and Linux with third-party engines to convert different Office document types to PDF. On Windows, samples typically select the Microsoft or WPS engine via the engine parameter; on Linux, they specify the LibreOffice or WPS engine path via engine_path.

Convert Word documents to PDF

c++
#include "include/addon/conversion/fs_convert.h"

// Make sure that SDK has already been initialized successfully.

WString word_file_path = L"test.doc";
WString output_path = L"saved.pdf";

// Use default Word2PDFSettingData values.
foxit::addon::conversion::Word2PDFSettingData word_convert_setting_data;
#if defined(_WIN32) || defined(_WIN64)
foxit::addon::conversion::Convert::FromWord(word_file_path, L"", output_path, word_convert_setting_data, foxit::addon::conversion::Convert::e_Office2PdfEngineMicrosoft);
#else
foxit::addon::conversion::Convert::FromWord(word_file_path, L"", output_path, engine_path, word_convert_setting_data);
#endif
C
#include "include/fs_basictypes_c.h"
#include "include/fs_convert_c.h"

// Make sure that SDK has already been initialized successfully.

const wchar_t* word_file_path = L"test.doc";
const wchar_t* output_path = L"saved.pdf";

// Use default Word2PDFSettingData values.
FSWord2PDFSettingData word_convert_setting_data;
word_convert_setting_data.include_doc_props = false;
word_convert_setting_data.optimize_option = e_FSConvertOptimizeOptionForPrint;
word_convert_setting_data.content_option = e_FSConvertContentOptionOnlyContent;
word_convert_setting_data.bookmark_option = e_FSConvertBookmarkOptionNone;
word_convert_setting_data.convert_to_pdfa = false;
FSDK_Convert_FromWord(word_file_path, L"", output_path, word_convert_setting_data, e_FSOffice2PdfEngineMicrosoft);
java
import com.foxit.sdk.addon.conversion.Word2PDFSettingData;
import com.foxit.sdk.addon.conversion.Convert;
 
// Make sure that SDK has already been initialized successfully.

String word_file_path = "test.doc";
String saved_pdf_path = "saved.pdf";

// Use default Word2PDFSettingData values.
Word2PDFSettingData word_convert_setting_data = new Word2PDFSettingData();
String os_name = System.getProperty("os.name").toLowerCase();
if (os_name.contains("win")) {
  Convert.fromWord(word_file_path, "", saved_pdf_path, word_convert_setting_data, Convert.e_Office2PdfEngineMicrosoft);
} else {
  Convert.fromWord(word_file_path, "", saved_pdf_path, engine_path, word_convert_setting_data);
}
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *

...
# Make sure that SDK has already been initialized successfully.

word_file_path = "test.doc"
output_path = "saved.pdf"

# Use default Word2PDFSettingData values.
word_convert_setting_data = Word2PDFSettingData()
if sys.platform == "linux":
  Convert.FromWord(word_file_path, "", output_path, engine_path, word_convert_setting_data)
else:
  Convert.FromWord(word_file_path, "", output_path, word_convert_setting_data, Convert.e_Office2PdfEngineMicrosoft)
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");

...
// Make sure that SDK has already been initialized successfully.

let word_file_path = "test.doc";
let output_path = "saved.pdf";

// Use default Word2PDFSettingData values.
let word_convert_setting_data = new FSDK.Word2PDFSettingData();
if (process.platform === 'win32') {
  FSDK.Convert.FromWord(word_file_path, "", output_path, word_convert_setting_data, FSDK.Convert.e_Office2PdfEngineMicrosoft);
} else {
  engine_path = "";  / Please fill in the correct engine path. For example, "/usr/lib/libreoffice/program".
  FSDK.Convert.FromWord(word_file_path, "", output_path, engine_path, word_convert_setting_data);
}
csharp
using foxit;

// Make sure that SDK has already been initialized successfully.

string word_file_path = "test.doc";
string saved_pdf_path = "saved.pdf";

// Use default Word2PDFSettingData values.
using (foxit.addon.conversion.Word2PDFSettingData word_convert_setting_data = new foxit.addon.conversion.Word2PDFSettingData())
{
	foxit.addon.conversion.Convert.FromWord(word_file_path, "", saved_pdf_path, word_convert_setting_data, foxit.addon.conversion.Convert.e_Office2PdfEngineMicrosoft);
}
go
import (
. "foxit.com/fsdk"
“fmt”
“runtime”
) 

...
# Make sure that SDK has already been initialized successfully.

word_file_path := "test.doc"
output_path := "saved.pdf"

# Use default Word2PDFSettingData values.
word_convert_setting_data := NewWord2PDFSettingData()
if runtime.GOOS == "linux" {
  ConvertFromWord(word_file_path, "", output_path, engine_path, word_convert_setting_data)
} else{
  ConvertFromWord(word_file_path, "", output_path, word_convert_setting_data, e_Office2PdfEngineMicrosoft)
}

Convert Excel files to PDF

c++
#include "include/addon/conversion/fs_convert.h"

// Make sure that SDK has already been initialized successfully.

WString excel_file_path = L"test.xls";
WString output_path = L"saved.pdf";

// Use default Excel2PDFSettingData values.
foxit::addon::conversion::Excel2PDFSettingData excel_convert_setting_data;
#if defined(_WIN32) || defined(_WIN64)
foxit::addon::conversion::Convert::FromExcel(excel_file_path, L"", output_path, excel_convert_setting_data, foxit::addon::conversion::Convert::e_Office2PdfEngineMicrosoft);
#else
foxit::addon::conversion::Convert::FromExcel(excel_file_path, L"", output_path, engine_path, excel_convert_setting_data);
#endif
C
#include "include/fs_basictypes_c.h"
#include "include/fs_convert_c.h"

// Make sure that SDK has already been initialized successfully.

const wchar_t* excel_file_path = L"test.xls";
const wchar_t* output_path = L"saved.pdf";

// Use default Excel2PDFSettingData values.
FSExcel2PDFSettingData excel_convert_setting_data;
excel_convert_setting_data.include_doc_props = false;
excel_convert_setting_data.quality = e_FSConvertQualityStandard;
excel_convert_setting_data.ignore_print_area = true;
excel_convert_setting_data.scale_type = e_FSScaleTypeNone;
excel_convert_setting_data.convert_to_pdfa = false;
FSDK_Convert_FromExcel(excel_file_path, L"", output_path, excel_convert_setting_data, e_FSOffice2PdfEngineMicrosoft);
java
import com.foxit.sdk.addon.conversion.Excel2PDFSettingData;
import com.foxit.sdk.addon.conversion.Convert;
 
// Make sure that SDK has already been initialized successfully.

String excel_file_path = "test.xls";
String saved_pdf_path = "saved.pdf";

// Use default Excel2PDFSettingData values.
Excel2PDFSettingData excel_convert_setting_data = new Excel2PDFSettingData();
String os_name = System.getProperty("os.name").toLowerCase();
if (os_name.contains("win")) {
  Convert.fromExcel(excel_file_path, "", saved_pdf_path, excel_convert_setting_data, Convert.e_Office2PdfEngineMicrosoft);
} else {
  Convert.fromExcel(excel_file_path, "", saved_pdf_path, engine_path, excel_convert_setting_data);
}
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *

...
# Make sure that SDK has already been initialized successfully.

excel_file_path = "test.xls"
output_path = "saved.pdf"

# Use default Excel2PDFSettingData values.
excel_convert_setting_data = Excel2PDFSettingData()
if sys.platform == "linux":
  Convert.FromExcel(excel_file_path, "", output_path, engine_path, excel_convert_setting_data)
else:
  Convert.FromExcel(excel_file_path, "", output_path, excel_convert_setting_data, Convert.e_Office2PdfEngineMicrosoft)
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");

...
// Make sure that SDK has already been initialized successfully.

let excel_file_path = "test.xlsx";
let output_path = "saved.pdf";

// Use default Excel2PDFSettingData values.
let excel_convert_setting_data = new FSDK.Excel2PDFSettingData();
if (process.platform === 'win32') {
  FSDK.Convert.FromExcel(excel_file_path, "", output_path, excel_convert_setting_data, FSDK.Convert.e_Office2PdfEngineMicrosoft);
} else {
  FSDK.Convert.FromExcel(excel_file_path, "", output_path, engine_path, excel_convert_setting_data);
}
csharp
using foxit;

// Make sure that SDK has already been initialized successfully.

string excel_file_path= "test.xls";
string saved_pdf_path = "saved.pdf";
// Use default Excel2PDFSettingData values.
using (foxit.addon.conversion.Excel2PDFSettingData excel_convert_setting_data = new foxit.addon.conversion.Excel2PDFSettingData())
{
	foxit.addon.conversion.Convert.FromExcel(excel_file_path, "", saved_pdf_path, excel_convert_setting_data, foxit.addon.conversion.Convert.e_Office2PdfEngineMicrosoft);
}
go
import (
. "foxit.com/fsdk"
“fmt”
“runtime”
) 
...
# Make sure that SDK has already been initialized successfully.

excel_file_path := "test.xls"
output_path := "saved.pdf"

# Use default Excel2PDFSettingData values.
excel_convert_setting_data := NewExcel2PDFSettingData()
if runtime.GOOS == "linux"{
  ConvertFromExcel(excel_file_path, "", output_path, engine_path, excel_convert_setting_data)
}
else{
  ConvertFromExcel(excel_file_path, "", output_path, excel_convert_setting_data, e_Office2PdfEngineMicrosoft)
}

Convert PowerPoint files to PDF

c++
#include "include/addon/conversion/fs_convert.h"

// Make sure that SDK has already been initialized successfully.

WString ppt_file_path = L"test.ppt";
WString output_path = L"saved.pdf";

// Use default PowerPoint2PDFSettingData values.
foxit::addon::conversion::PowerPoint2PDFSettingData ppt_convert_setting_data;
#if defined(_WIN32) || defined(_WIN64)
foxit::addon::conversion::Convert::FromPowerPoint(ppt_file_path, L"", output_path, ppt_convert_setting_data, foxit::addon::conversion::Convert::e_Office2PdfEngineMicrosoft);
#else
foxit::addon::conversion::Convert::FromPowerPoint(ppt_file_path, L"", output_path, engine_path,  ppt_convert_setting_data);
#endif
C
#include "include/fs_basictypes_c.h"
#include "include/fs_convert_c.h"

// Make sure that SDK has already been initialized successfully.

const wchar_t* ppt_file_path = L"test.ppt";
const wchar_t* output_path = L"saved.pdf";

// Use default PowerPoint2PDFSettingData values.
FSPowerPoint2PDFSettingData ppt_convert_setting_data;
ppt_convert_setting_data.intent = e_FSConvertIntentPrint;
ppt_convert_setting_data.frame_output_slides = false;
ppt_convert_setting_data.output_type = e_FSOutputSlides;
ppt_convert_setting_data.handout_order = e_FSHandoutOrderVerticalFirst;
ppt_convert_setting_data.output_hidden_slides = false;
ppt_convert_setting_data.include_doc_props = false;
FSDK_Convert_FromPowerPoint(ppt_file_path, L"", output_path, ppt_convert_setting_data, e_FSOffice2PdfEngineMicrosoft);
java
import com.foxit.sdk.addon.conversion.PowerPoint2PDFSettingData;
import com.foxit.sdk.addon.conversion.Convert;

// Make sure that SDK has already been initialized successfully.

String ppt_file_path = "test.ppt";
String saved_pdf_path = "saved.pdf";

// Use default PowerPoint2PDFSettingData values.
PowerPoint2PDFSettingData ppt_convert_setting_data = new PowerPoint2PDFSettingData();
String os_name = System.getProperty("os.name").toLowerCase();
if (os_name.contains("win")) {
  Convert.fromPowerPoint(ppt_file_path, "", saved_pdf_path, ppt_convert_setting_data, Convert.e_Office2PdfEngineMicrosoft);
} else {
  Convert.fromPowerPoint(ppt_file_path, "", saved_pdf_path, engine_path, ppt_convert_setting_data);
}
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *

...
# Make sure that SDK has already been initialized successfully.

ppt_file_path = "test.ppt"
output_path = "saved.pdf"

# Use default PowerPoint2PDFSettingData values.
ppt_convert_setting_data = PowerPoint2PDFSettingData()
if sys.platform == "linux":
  Convert.FromPowerPoint(ppt_file_path, "", output_path, engine_path, ppt_convert_setting_data)
else:
  Convert.FromPowerPoint(ppt_file_path, "", output_path, ppt_convert_setting_data, Convert.e_Office2PdfEngineMicrosoft)
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");

...
// Make sure that SDK has already been initialized successfully.

let ppt_file_path = "test.pptx";
let output_path = "saved.pdf";

// Use default PowerPoint2PDFSettingData values.
let ppt_convert_setting_data = new FSDK.PowerPoint2PDFSettingData();
if (process.platform === 'win32') {
  FSDK.Convert.FromPowerPoint(ppt_file_path, "", output_path, ppt_convert_setting_data, FSDK.Convert.e_Office2PdfEngineMicrosoft);
} else {
  FSDK.Convert.FromPowerPoint(ppt_file_path, "", output_path, engine_path, ppt_convert_setting_data);
}
csharp
using foxit;

// Make sure that SDK has already been initialized successfully.

string ppt_file_path = "test.ppt";
string saved_pdf_path = "saved.pdf";

// Use default PowerPoint2PDFSettingData values.
using (foxit.addon.conversion.PowerPoint2PDFSettingData ppt_convert_setting_data = new foxit.addon.conversion.PowerPoint2PDFSettingData())
{
	foxit.addon.conversion.Convert.FromPowerPoint(ppt_file_path, "", saved_pdf_path, ppt_convert_setting_data, foxit.addon.conversion.Convert.e_Office2PdfEngineMicrosoft);
}
go
import (
. "foxit.com/fsdk"
“fmt”
“runtime”
) 
...
# Make sure that SDK has already been initialized successfully.

ppt_file_path := "test.ppt"
output_path := "saved.pdf"

# Use default PowerPoint2PDFSettingData values.
ppt_convert_setting_data := NewPowerPoint2PDFSettingData()
if runtime.GOOS == "linux"{
  ConvertFromPowerPoint(ppt_file_path, "", output_path, engine_path, ppt_convert_setting_data)
}
else{
  ConvertFromPowerPoint(ppt_file_path, "", output_path, ppt_convert_setting_data, e_Office2PdfEngineMicrosoft)
}