Convert PDF Files to Excel

The code below shows you how to convert a PDF file to an Excel spreadsheet.

This sample requires a Professional license.


C#
using System;
using System.IO;
using SolidFramework.Converters.Plumbing;
using SolidFramework.Converters;

namespace PDFtoExcel
{
    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\filepdf.pdf";

            // Set the file extension you are creating
            String xlsFile = Path.ChangeExtension(pdfPath, "xlsx");

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

                // Set the preferred conversion properties 

                // This combines all tables onto one sheet 
                converter.SingleTable = ExcelTablesOnSheet.PlaceAllTablesOnSingleSheet;

                // This gets Non Table Content 
                converter.TablesFromContent = true;

                // convert the file, calling it the same name but with a different extention , setting overwrite to true 
                converter.ConvertTo(xlsFile, true);

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

C++

#include “stdafx.h”
#include “SolidFramework.h”

#include
using namespace std;

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

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

class PdfToExcelConverter : public SolidFramework::Converters::PdfToExcelConverterBase
{
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 Solid Documents License Information Here*/
SolidFramework::License::Import(L”C:\\MyFolder\\license.xml”);

PdfToExcelConverter *converter = new PdfToExcelConverter();

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

// Add files to convert and directory to output converted file
converter->AddSourceFile(L”C:\\YourFolder\\yourpdf.pdf”);
converter->setOutputDirectory(L”C:\\MyFolder”);

// Set the file extension you are creating
converter->setOutputType(SolidFramework::Converters::Plumbing::ExcelDocumentType::XlsX);

//This combines all tables onto one sheet
converter->setSingleTable(SolidFramework::Converters::Plumbing::ExcelTablesOnSheet::PlaceAllTablesOnSingleSheet);

// This gets Non Table Content
converter->setTablesFromContent(true);

// Convert the file
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 to exit.” << endl; cin.get(); return 0; } [/code] [/av_tab] [av_tab title='VB.Net' icon_select='no' icon='ue800' font='entypo-fontello'] [code language="vb"] Imports System.IO Imports SolidFramework.Converters.Plumbing Module PDFtoExcel 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 sXlsxPath As String ' Set your file path sPdfPath = ("C:\YourFolder\filepdf.pdf") ' Set your output file and location sXlsxPath = Path.ChangeExtension(sPdfPath, ".xlsx") ' Define your Solid Framework Converter Dim myConverter As SolidFramework.Converters.PdfToExcelConverter ' Set the converter myConverter = New SolidFramework.Converters.PdfToExcelConverter ' Set the preferred conversion properties ' Add the source file myConverter.AddSourceFile(sPdfPath) ' This combines all tables onto one sheet myConverter.SingleTable = ExcelTablesOnSheet.PlaceAllTablesOnSingleSheet ' This gets Non Table Content myConverter.TablesFromContent = False ' Convert the File. myConverter.ConvertTo(sXlsxPath, True) ' Clean up myConverter.Dispose() End Sub End Module [/code] [/av_tab] [/av_tab_container] [/av_one_full]