Convert PDF Files to Word

The code below shows you how to convert a PDF file to a Word document.

This sample requires a Tools license.

C#
using System;
using System.IO;
using SolidFramework.Converters.Plumbing;
using SolidFramework.Converters;
namespace PDFtoWord
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Call your Solid Documents License
            SolidFramework.License.Import(@"C:\MyFolder\license.xml");

            // Set the location of your the file you want to convert
            string pdfPath = @"C:\YourFolder\yourpdf.pdf";

            // Set the file extension you are creating
            string docxPath = Path.ChangeExtension(pdfPath, ".docx");

            // *PDF to DOCX*//  
            using (PdfToWordConverter converter = new PdfToWordConverter())
            {
                // Add files to convert. 
                converter.AddSourceFile(pdfPath);

                //Set the preferred conversion properties 

                // Detect Headers and Footers
                converter.HeaderAndFooterMode = HeaderAndFooterMode.Detect;

                // Set a specific page range to convert
                converter.PageRange = new SolidFramework.PageRange(new int[] { 1 });

                // Turn on Solid Documents Optical Character Recognition (OCR) for Scanned Files
                converter.TextRecoveryEngine = TextRecoveryEngine.SolidOCR; //Only with Pro+OCR and OCR license
                converter.TextRecoveryType = TextRecovery.Automatic;

                // Set the layout of the reconstruction (Exact for Forms)
                converter.ReconstructionMode = ReconstructionMode.Flowing;

                // Convert the File.
                converter.ConvertTo(docxPath, true);

                // Show the status of the PDF file in the Console Window
                SolidFramework.Converters.Plumbing.ConversionStatus status = converter.ConvertTo(docxPath, true);
                if (status != ConversionStatus.Success)
                {
                    Console.WriteLine(status);
                }
            }

            Console.ReadKey();
        }
    }
}

C++
#include "stdafx.h"
#include "SolidFramework.h"

#include <iostream>
using  namespace std;

void DoProgress(SolidFramework::ProgressEventArgsPtr args)
{
    // Not implemented
}

void DoWarning(SolidFramework::WarningEventArgsPtr args)
{
    // Not implemented
}

class PdfToWordConverter : public SolidFramework::Converters::PdfToWordConverterBase
{
public:
    void FireProgress(SolidFramework::ProgressEventArgsPtr args) override { DoProgress(args); };
    void FireWarning(SolidFramework::WarningEventArgsPtr args) override { DoWarning(args); };
};

int _tmain(int argc, _TCHAR* argv[])
{
    // Enter your License code goes here
    SolidFramework::License::Import(L"C:\\MyFolder\\license.xml");

    // Create a PDF to Word Converter called converter
    PdfToWordConverter *converter = new PdfToWordConverter();

    SolidFramework::Converters::CustomData *pData = NULL;
    pData = new SolidFramework::Converters::CustomData();
    pData->Converter = converter;
    pData->Data = nullptr;
    converter->setCustomData(pData);

    // Add the PDF file to convert.
    converter->AddSourceFile(L"C:\\YourFolder\\yourpdf.pdf");
    converter->setOutputDirectory(L"C:\\MyFolder");

    // Set the file type
    converter->setOutputType(SolidFramework::Converters::Plumbing::WordDocumentType::DocX);

    // Detect headers and footers
    converter->setHeaderAndFooterMode(SolidFramework::Converters::Plumbing::HeaderAndFooterMode::Detect);

    // Turn on Solid Documents Optical Character Recognition (OCR) for Scanned Files
    converter->setTextRecoveryEngine(SolidFramework::Converters::Plumbing::TextRecoveryEngine::SolidOCR);
    converter->setTextRecoveryType(SolidFramework::Converters::Plumbing::TextRecovery::Automatic);

    // Set the layout of the reconstruction (Exact for Forms)
    converter->setReconstructionMode(SolidFramework::Converters::Plumbing::ReconstructionMode::Flowing);

	// Handle annotations
	// SolidFramework::Converters::Plumbing::MarkupAnnotConversionType::Comment - Comment
	// SolidFramework::Converters::Plumbing::MarkupAnnotConversionType::Never - Remove
	// SolidFramework::Converters::Plumbing::MarkupAnnotConversionType::Textbox - Textbox
	converter->setMarkupAnnotConversionType(SolidFramework::Converters::Plumbing::MarkupAnnotConversionType::Comment);

    //Start the Conversion

    cout << "Starting conversion." << endl; converter->Convert();

    SolidFramework::Converters::Plumbing::ConversionStatus status = converter->getResults()->getItem(0)->getStatus();
    if (status != SolidFramework::Converters::Plumbing::ConversionStatus::Success)
    {
        cout << "Conversion failed." << endl;
    }
    else
    {
        cout << "Conversion succeeded." << endl; } converter->Dispose();

    cout << "Press <Enter> to exit." << endl;
    cin.get();

    return 0;
}
VB.Net
Imports System.IO
Imports SolidFramework.Converters.Plumbing

Module PDFtoWord

    Sub Main()

        ' Call your Solid Documents License
        SolidFramework.License.Import("C:\MyFolder\license.xml")

        'Define a variable for your source file
        Dim sPdfPath As String

        ' Define a String for the output file
        Dim sDocxPath As String

        ' Define your Solid Framework Converter
        Dim myConverter As SolidFramework.Converters.PdfToWordConverter

        ' Set your file path 
        sPdfPath = "C:\YourFolder\filepdf.pdf"

        ' Set your output file and location
        sDocxPath = Path.ChangeExtension(sPdfPath, ".docx")

        ' Set the converter
        myConverter = New SolidFramework.Converters.PdfToWordConverter

        ' Set the preferred conversion properties 

        ' Add files to convert. 
        myConverter.AddSourceFile(sPdfPath)

        ' Detect Headers and Footers
        myConverter.HeaderAndFooterMode = HeaderAndFooterMode.Detect

        ' Turn on Solid Documents Optical Character Recognition (OCR) for Scanned Files
        myConverter.TextRecoveryEngine = TextRecoveryEngine.Automatic

        ' Set the layout of the reconstruction (Exact for Forms)
        myConverter.ReconstructionMode = ReconstructionMode.Flowing

        ' Convert the File.
        myConverter.ConvertTo(sDocxPath, True)

        ' Clean up
        myConverter.Dispose()

    End Sub

End Module