Samples β
Sample project overview β
Foxit Conversion SDK provides samples for every supported language. Samples are in the examples directory of the development package. Directory layout:
π Sample directory structure β
examples/
βββ simple_demo/ # Simple sample projects
β βββ input_files/ # Source Office and PDF files for testing
β βββ office2pdf/ # Office to PDF samples (Windows only)
β βββ pdf2office/ # PDF to Office samples
βββ βββ output_files/ # Converted output; subfolders named per sampleSample directory reference β
| Sample | Description | Platforms | Input formats | Output formats |
|---|---|---|---|---|
| office2pdf | Convert Office documents to PDF | Windows/Linux | docx, xlsx, pptx | |
| pdf2office | Convert PDF to Office formats | Windows/Linux | docx, xlsx, pptx |
Run preparation β
Development environment and system support β
- See Getting started for environment and system requirements.
Run samples β
Overview β
How you run samples varies slightly by platform and language:
- Windows C/C++ and .NET: The SDK does not ship a command-line runner; use an IDE (e.g. Visual Studio) to open and run sample projects.
- Other language packages: Use the SDK command-line runner, sample scripts, or an IDE.
- Linux C++: Command line or build and run with CMake and Make.
Detailed guides β
- Command-line run β most language packages
- Visual Studio run β Windows C/C++ and .NET
- Eclipse IDE run β Java development
Command-line run β
Samples under \examples\simple_demo that include a command-line runner (except Python and Node.js) can be run via .bat or .sh files.
Basic usage β
Run all samples
- Windows:
RunDemo.bat allorRunDemo.bat all x86. - Linux:
RunDemo.sh all.
- Windows:
Run a specific sample
- Windows:
RunDemo.bat demo_nameorRunDemo.bat demo_name x86. For example,RunDemo.bat office2pdf x86runs only the office2pdf sample. - Linux:
RunDemo.sh demo_name.
NOTE
- Before SDK 2.1, the Java command-line runner was in each sample directory. To run a sample,
cdto that directoryβfor example,\examples\simple_demo\pdf2officefor pdf2office.
- Windows:
Language-specific samples β
Node.js samples β
Install the SDK Node.js package:
- From the project root, run:
jsnpm i @fuxinsoft/foxit-pdf-conversion-sdk-nodeRun a sample:
cdto the sample directory, e.g.\examples\simple_demo\office2pdfor\examples\simple_demo\pdf2office- Run
node office2pdf.jsornode pdf2office.js
Python samples β
- Install SDK Python library {#install-sdk-python-library}
python
pip install FoxitPDFConversionSDKPython3- Configure SDK Python library {#configure-sdk-python-library}
For Foxit SDK Python 2.7 on Windows or Linux, copy the correct library file for your Python bitness (32 or 64).
Windows Python 2.7:
- x64:
- Copy
FoxitPDFConversionSDKPython2/x64_vc15/_fpdfconversionsdk.pydtoFoxitPDFConversionSDKPython2/.
- Copy
- x86:
- Copy
FoxitPDFConversionSDKPython2/x86_vc15/_fpdfconversionsdk.pydtoFoxitPDFConversionSDKPython2/.
- Copy
Linux Python 2.7:
- x64:
- Copy
FoxitPDFConversionSDKPython2/x64_vc15/_fpdfconversionsdk.sotoFoxitPDFConversionSDKPython2/.
- Copy
- x86:
- Copy
FoxitPDFConversionSDKPython2/x86_vc15/_fpdfconversionsdk.sotoFoxitPDFConversionSDKPython2/.
- Copy
Alternatively, run
examples/simple_demo/rundemo_python.pyto copy libraries automatically.- x64:
- Run SDK Python samples {#run-sdk-python-demo}
- Run samples with the Python script
rundemo_python.py wraps configuration and dependencies for easier runs.
- Run all samples
python
cd examples/simple_demo/
python rundemo_python.py- Run one sample
For example, pdf2office:
python
cd examples/simple_demo/
python rundemo_python.py pdf2office- Run sample scripts directly
- If Python and dependencies are configured, run scripts directly. Example for office2pdf:
bash
cd examples/simple_demo/office2pdf/
python -u office2pdf.pyNOTE
- Python 2.7: see Configure Python library and match library files to your Python version.
- Python 3: if
FoxitPDFSDKPython3is installed, you can run sample scripts directly.
Go samples β
- Set environment variables
After downloading the Foxit PDF SDK Go package, set environment variables so the dynamic libraries can be found:
Linux:
- x64:bash
export LD_LIBRARY_PATH=/home/user/Desktop/foxitpdfsdk_xx_x_linux_go/lib/x64:$LD_LIBRARY_PATH - x86:bash
export LD_LIBRARY_PATH=/home/user/Desktop/foxitpdfsdk_xx_x_linux_go/lib/x86:$LD_LIBRARY_PATH
MacOS:
- x64:bash
export DYLD_LIBRARY_PATH=/Users/user/Desktop/foxitpdfsdk_xx_x_mac_go/lib:$DYLD_LIBRARY_PATH
NOTE
- Replace paths with your actual SDK install location
- Add these to your shell config (e.g.
~/.bashrcor~/.zshrc) for persistence - Reopen the terminal or run
source ~/.bashrcafter changes
- x64:
- Run samples
- See Command-line run basic usage above.
Visual Studio run β
On Windows, building the SDK with Visual Studio creates a bin folder under \examples\simple_demo\ with .exe files. Executable names depend on the build configuration.
Open the solution:
- Under
\examples\simple_demo, open the.slnfor your Visual Studio version. - To build one sample only, open the
.vcxprojin that sample folder.
- Under
Build:
- In Visual Studio: Build > Build Solution.
Run: After a successful build:
- Method 1: Run the
.exe- Open
binand double-click the.exe.
- Open
- Method 2: Run from Visual Studio
- In Solution Explorer, right-click the project and choose Set as Startup Project.
- Press F5 or Debug > Start Debugging.
- Method 1: Run the
Output:
- Results appear in the Visual Studio Output window or console.
Get detailed execution logs
Open
cmd.exe,cdto\examples\simple_demo\bin, and run the.exe.
Eclipse IDE run β
The following uses Java samples as an example.
- Create a Java project and add the SDK:
- Create a new Java project in Eclipse.
- Add the Foxit Conversion SDK Java library.
- Copy sample source:
- Copy the sample
.javafile into the projectsrcfolder. - For
pdf2office, copypdf2office.javafrom\examples\simple_demo\pdf2officeintosrc.
- Copy the sample
- Configure paths:
- Edit
output_pathandinput_pathin the copied source as needed. - For default test files, use absolute paths to
output_filesandinput_filesunderexamples\simple_demo.
- Edit
- Run:
- Right-click the project and choose Run As -> Java Application.