Skip to content

PDF to Office (Foxit conversion engine)

Foxit PDF SDK provides efficient PDF to Office conversion, supporting conversion of PDF documents to Office formats (docx, xlsx, pptx). This section explains how to use Foxit's proprietary pdf2office conversion engine. See the PDF to Office example configuration and run guide for setup steps and sample code.

To learn more about Foxit's conversion engine, see Explore Foxit Conversion SDK.

Configure PDF2Office conversion timeout

Starting in v10.1, the Foxit PDF2Office plugin module supports a conversion timeout. You can set the maximum allowed conversion time; the process stops automatically when the limit is exceeded.

Code example:

Java
PDF2OfficeSettingData settingData = new PDF2OfficeSettingData();
settingData.timeout = 60; / Set the timeout to 60 milliseconds.
PDF2Office converter = new PDF2Office();
converter.StartConvertToWord(pdfFilePath, outputFilePath, settingData);

Using the PDF2Office module

The sample code below shows how to use the PDF2Office module in Foxit PDF SDK to convert PDF files to Office formats without relying on third-party engines.

c++
#include "include/common/fs_common.h"
#include "include/addon/conversion/pdf2office/fs_pdf2office.h"

using namespace std;
using namespace foxit;
using namespace foxit::common;
using namespace foxit::common::file;
using foxit::common::Library;
using namespace addon::conversion::pdf2office;

class CustomConvertCallback : public ConvertCallback {
public:
    CustomConvertCallback() {}
    ~CustomConvertCallback() {}
    virtual bool NeedToPause() {
        return true;
    }

    virtual void ProgressNotify(int converted_count, int total_count) {}
};

CustomConvertCallback callback;
Progressive progressive = PDF2Office::StartConvertToWord(input_path + L"word.pdf", NULL, output_directory + L"pdf2word_result.docx", setting_data, &callback);
if (progressive.GetRateOfProgress() != 100) {
    Progressive::State state = Progressive::e_ToBeContinued;
    while (Progressive::e_ToBeContinued == state) {
        state = progressive.Continue();
    }
}
cout << "Convert PDF file to Word format file with path." << endl;

// Convert PDF file to Excel format file.
progressive = PDF2Office::StartConvertToExcel(input_path + L"excel.pdf", NULL, output_directory + L"pdf2excel_result.xlsx", setting_data);
if (progressive.GetRateOfProgress() != 100) {
    Progressive::State state = Progressive::e_ToBeContinued;
    while (Progressive::e_ToBeContinued == state) {
        state = progressive.Continue();
    }
}
cout << "Convert PDF file to Excel format file with path." << endl;

// Convert PDF file to PowerPoint format file.
progressive = PDF2Office::StartConvertToPowerPoint(input_path + L"powerpoint.pdf", NULL, output_directory + L"pdf2powerpoint_result.pptx", setting_data);
if (progressive.GetRateOfProgress() != 100) {
    Progressive::State state = Progressive::e_ToBeContinued;
    while (Progressive::e_ToBeContinued == state) {
        state = progressive.Continue();
    }
}
cout << "Convert PDF file to PowerPoint format file with path." << endl;
C
#include "include/fs_basictypes_c.h"
#include "include/fs_common_c.h"
#include "include/fx_stream_c.h"
#include "include/fs_pdf2office_c.h"

static FS_BOOL gNeedToPause(void* user_data) {
  return TRUE;
}

static void gProgressNotify(void* user_data, int converted_count, int total_count) {
}

FS_BOOL is_large_file = FALSE;
FILE* file = NULL;
FILE* filestream = NULL;
int ref = 0;
FS_INT64 cur_pos = 0;

FS_INT64 gGetSize(void* user_data) {
  if (!user_data) return 0;
  if (is_large_file) {
    long long size_long;
    _fseeki64(file, 0, SEEK_END);
    size_long = _ftelli64(file);
    return size_long;
  } else {
   fseek(file, 0, SEEK_END);
   return (FS_INT64)ftell(file);
  }
  return 0;
}

FSConvertCallback * callback_word = (FSConvertCallback*)malloc(sizeof(FSConvertCallback));
callback ->user_data = callback;
callback ->NeedToPause = gNeedToPause;
callback ->ProgressNotify = gProgressNotify;
FS_PROGRESSIVE_HANDLE progressive_handle;
FSErrorCode error_code = FSDK_PDF2Office_StartConvertToWord(src_pdf_path, NULL, saved_word_file_path, setting_data, callback_word, &progressive_handle);
if (error_code != e_FSErrSuccess) {
    switch (error_code) {
    case e_FSErrNoPDF2OfficeModuleRight:
        printf("[Failed] Conversion module is not contained in current Foxit PDF Conversion SDK keys.\n");
        break;
    default:
        printf("Exception: %d\n",error_code);
        break;
    }
    return 1;
}
int rate;
FSDK_Progressive_GetRateOfProgress(progressive_handle, &rate);
if (rate != 100) {
    FSState state = e_FSToBeContinued;
    while (e_FSToBeContinued == state) {
        FSDK_Progressive_Continue(progressive_handle, &state);
    }
}
printf("Convert PDF file to Word format file with path.\n");

FSConvertCallback * callback_excel = (FSConvertCallback*)malloc(sizeof(FSConvertCallback));
callback ->user_data = callback;
callback ->NeedToPause = gNeedToPause;
callback ->ProgressNotify = gProgressNotify;
error_code = FSDK_PDF2Office_StartConvertToExcel(src_pdf_path, NULL, saved_excel_file_path, setting_data, callback_excel, &progressive_handle);
if (error_code != e_FSErrSuccess) {
    switch (error_code) {
    case e_FSErrNoPDF2OfficeModuleRight:
        printf("[Failed] Conversion module is not contained in current Foxit PDF Conversion SDK keys.\n");
        break;
    default:
        printf("Exception: \n");
        break;
    }
    return 1;
}
FSDK_Progressive_GetRateOfProgress(progressive_handle, &rate);
if (rate != 100) {
    FSState state = e_FSToBeContinued;
    while (e_FSToBeContinued == state) {
        FSDK_Progressive_Continue(progressive_handle, &state);
    }
}
printf("Convert PDF file to Excel format file with path.\n");

FSConvertCallback * callback_powepoint = (FSConvertCallback*)malloc(sizeof(FSConvertCallback));
callback ->user_data = callback;
callback ->NeedToPause = gNeedToPause;
callback ->ProgressNotify = gProgressNotify;
error_code = FSDK_PDF2Office_StartConvertToPowerPoint(src_pdf_path, NULL, saved_ppt_file_path, setting_data, powepoint, &progressive_handle);
if (error_code != e_FSErrSuccess) {
    switch (error_code) {
    case e_FSErrNoPDF2OfficeModuleRight:
        printf("[Failed] Conversion module is not contained in current Foxit PDF Conversion SDK keys.\n");
        break;
    default:
        printf("Exception: %d\n",error_code);
        break;
    }
    return 1;
}
FSDK_Progressive_GetRateOfProgress(progressive_handle, &rate);
if (rate != 100) {
    FSState state = e_FSToBeContinued;
    while (e_FSToBeContinued == state) {
        FSDK_Progressive_Continue(progressive_handle, &state);
    }
}
printf("Convert PDF file to PowerPoint format file with path.\n");
java
import com.foxit.sdk.PDFException;
import com.foxit.sdk.common.Library;
import com.foxit.sdk.common.Progressive;
import com.foxit.sdk.common.fxcrt.FileReaderCallback;
import com.foxit.sdk.addon.conversion.pdf2office.PDF2Office;
import com.foxit.sdk.addon.conversion.pdf2office.ConvertCallback;
import com.foxit.sdk.addon.conversion.pdf2office.PDF2OfficeSettingData;
import java.io.*;
 
class CustomConvertCallback extends ConvertCallback {
  CustomConvertCallback() {}
 
  @Override
  public boolean needToPause() {
    return true;
  }
 
  @Override
  public void progressNotify(int converted_count, int total_count) {
  }
}
 
CustomConvertCallback callback = new CustomConvertCallback();
Progressive progressive = PDF2Office.startConvertToWord(input_path + "word.pdf", null, output_path + "pdf2word_result.docx", setting_data, callback);
if (progressive.getRateOfProgress() != 100)
{
  int state = Progressive.e_ToBeContinued;
  while (Progressive.e_ToBeContinued == state)
  {
    state = progressive.resume();
  }
}
System.out.println("Convert PDF file to Word format file.");
 
progressive = PDF2Office.startConvertToExcel(input_path + "excel.pdf", null, output_path + "pdf2excel_result.xlsx", setting_data, callback);
if (progressive.getRateOfProgress() != 100)
{
  int state = Progressive.e_ToBeContinued;
  while (Progressive.e_ToBeContinued == state)
  {
    state = progressive.resume();
  }
}
System.out.println("Convert PDF file to Excel format file.");
 
progressive = PDF2Office.startConvertToPowerPoint(input_path + "powerpoint.pdf", null, output_path + "pdf2powerpoint_result.pptx", setting_data, callback);
if (progressive.getRateOfProgress() != 100)
{
  int state = Progressive.e_ToBeContinued;
  while (Progressive.e_ToBeContinued == state)
  {
    state = progressive.resume();
  }
}
System.out.println("Convert PDF file to PowerPoint format file.");
py
import os
import sys
import site
 
if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False
 
if _PYTHON2_:
    site.addsitedir('../../../')
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *
 
class CustomConvertCallback(ConvertCallback):
 
    def __init__(self, *args):
        if _PYTHON2_:
            super(CustomConvertCallback, self).__init__(*args)
        else:
            super().__init__(*args)
    def __del__(self):
        self.__disown__()
 
    def Release(self, *args):
        pass
 
    def NeedToPause(self, *args):
        return True
 
    def ProgressNotify(self, *args):
        converted_count = args[0]
        total_count = args[1]
 
callback = CustomConvertCallback()
progressive = PDF2Office.StartConvertToWord(input_path + "word.pdf", "", output_directory + "pdf2word_result.docx", setting_data, callback)
if progressive.GetRateOfProgress() != 100:
    state = Progressive.e_ToBeContinued
    while (Progressive.e_ToBeContinued == state):
        state = progressive.Continue()
print("Convert PDF file to Word format file with path.")
 
progressive = PDF2Office.StartConvertToExcel(input_path + "excel.pdf", "", output_directory + "pdf2excel_result.xlsx", setting_data, callback)
if progressive.GetRateOfProgress() != 100:
    state = Progressive.e_ToBeContinued
    while (Progressive.e_ToBeContinued == state):
        state = progressive.Continue()
print("Convert PDF file to Excel format file with path.")
 
progressive = PDF2Office.StartConvertToPowerPoint(input_path + "powerpoint.pdf", "", output_directory + "pdf2powerpoint_result.pptx", setting_data, callback)
if progressive.GetRateOfProgress() != 100:
   state = Progressive.e_ToBeContinued
   while Progressive.e_ToBeContinued == state:
   state = progressive.Continue()
print("Convert PDF file to PowerPoint format file with path.")
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");
 
class CustomConvertCallback {
  constructor() {

  }

  NeedToPause() {
    return true;
  }

  ProgressNotify(converted_count, total_count) {
  }
};
let custom_callback = new CustomConvertCallback();
let convert_callback = new FSDK.ConvertCallback(custom_callback);

let progressive = FSDK.PDF2Office.StartConvertToWord(input_path + "word.pdf", "", output_directory + "pdf2word_result.docx", setting_data, convert_callback);
if (progressive.GetRateOfProgress() != 100) {
  let state = FSDK.Progressive.e_ToBeContinued;
  while (FSDK.Progressive.e_ToBeContinued == state) {
    state = progressive.Continue();
  }
}
 
progressive = FSDK.PDF2Office.StartConvertToWord(reader_callback_word, "", stream_callback_word, setting_data, convert_callback_word_stream);
if (progressive.GetRateOfProgress() != 100) {
  let state = FSDK.Progressive.e_ToBeContinued;
  while (FSDK.Progressive.e_ToBeContinued == state) {
    state = progressive.Continue();
  }
}
 
progressive = FSDK.PDF2Office.StartConvertToExcel(reader_callback_excel, "", stream_callback_excel, setting_data, convert_callback_excel_stream);
if (progressive.GetRateOfProgress() != 100) {
  let state = FSDK.Progressive.e_ToBeContinued;
  while (FSDK.Progressive.e_ToBeContinued == state) {
    state = progressive.Continue();
  }
}
csharp
using System;
using System.IO;
using System.Runtime.InteropServices;
using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.addon.conversion.pdf2office;
 
public class CustomConvertCallback : ConvertCallback
{
    public CustomConvertCallback() { }
    public override bool NeedToPause()
    {
        return true;
    }

    public override void ProgressNotify(int converted_count, int total_count)
    {
    }
}

using (CustomConvertCallback callback = new CustomConvertCallback())
{
    using (Progressive progressive = PDF2Office.StartConvertToWord(input_path + "word.pdf", null, output_path + "pdf2word_result.docx", setting_data, callback))
    {
        if (progressive.GetRateOfProgress() != 100)
        {
            Progressive.State state = Progressive.State.e_ToBeContinued;
            while (Progressive.State.e_ToBeContinued == state)
            {
                state = progressive.Continue();
            }
        }
        Console.WriteLine("Convert PDF file to Word format file with path.");
    }
}


using (CustomConvertCallback callback = new CustomConvertCallback())
{
    using (Progressive progressive = PDF2Office.StartConvertToExcel(input_path + "excel.pdf", null, output_path + "pdf2excel_result.xlsx", setting_data, callback))
    {
        if (progressive.GetRateOfProgress() != 100)
        {
            Progressive.State state = Progressive.State.e_ToBeContinued;
            while (Progressive.State.e_ToBeContinued == state)
            {
                state = progressive.Continue();
            }
        }
        Console.WriteLine("Convert PDF file to Excel format file with path.");
    }
}

using (CustomConvertCallback callback = new CustomConvertCallback())
{
    using (Progressive progressive = PDF2Office.StartConvertToPowerPoint(input_path + "powerpoint.pdf", null, output_path + "pdf2powerpoint_result.pptx", setting_data, callback))
    {
        if (progressive.GetRateOfProgress() != 100)
        {
            Progressive.State state = Progressive.State.e_ToBeContinued;
            while (Progressive.State.e_ToBeContinued == state)
            {
                state = progressive.Continue();
            }
        }
        Console.WriteLine("Convert PDF file to PowerPoint format file with path.");
    }
}
go
import (
. "foxit.com/fsdk"
“fmt”
)  
type CustomConvertCallback struct {
    ConvertCallback
}

// Release releases resources
func (callback CustomConvertCallback) Release() {
}

// NeedToPause checks if the conversion process needs to pause
func (callback CustomConvertCallback) NeedToPause() bool {
    return true
}

// ProgressNotify notifies progress of conversion
func (callback CustomConvertCallback) ProgressNotify(convertedCount int, totalCount int) {
    / Can be implemented to track progress
}

callback := CustomConvertCallback{}
callback_ := NewDirectorConvertCallback(callback)
progressive := PDF2OfficeStartConvertToWord(input_path + "word.pdf", "", output_directory + "pdf2word_result.docx", setting_data, callback_)
if progressive.GetRateOfProgress() != 100 {
    state := ProgressiveE_ToBeContinued
    for (ProgressiveE_ToBeContinued == state){
        state = progressive.Continue()
}
}
fmt.Printf("Convert PDF file to Word format file with path.")
 
progressive = PDF2OfficeStartConvertToExcel(input_path + "excel.pdf", "", output_directory + "pdf2excel_result.xlsx", setting_data, callback_)
if progressive.GetRateOfProgress() != 100{
    state := ProgressiveE_ToBeContinued
    for (ProgressiveE_ToBeContinued == state){
        state = progressive.Continue()
}
}
fmt.Printf("Convert PDF file to Excel format file with path.")
 
progressive = PDF2OfficeStartConvertToPowerPoint(input_path + "powerpoint.pdf", "", output_directory + "pdf2powerpoint_result.pptx", setting_data, callback_)
if progressive.GetRateOfProgress() != 100 {
   state := ProgressiveE_ToBeContinued
   for ProgressiveE_ToBeContinued == state {
       state = progressive.Continue()
}
}
fmt.Printf("Convert PDF file to PowerPoint format file with path.")