Sample code for using Apryse SDK to programmatically convert generic PDF documents to Word, Excel, PowerPoint; provided in Python, C++, C#, Go, Java, Node.js (JavaScript), PHP, Ruby and VB.
To convert files to Office with this Apryse Server SDK sample code:
To use this feature in production, your license key will need the Office Conversion Package. Trial keys already include all packages.
Learn more about our Server SDK and PDF to Office Conversion.
1//
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3//
4
5using System;
6using pdftron;
7using pdftron.Common;
8using pdftron.PDF;
9
10namespace PDF2OfficeTestCS
11{
12	/// <summary>
13	// The following sample illustrates how to use the PDF::Convert utility class to convert 
14	// documents and files to Office.
15	//
16	// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
17	// and other documents into Word, Excel, PowerPoint and HTML format.
18	//
19	// The Apryse SDK Structured Output add-on module can be downloaded from
20	// https://docs.apryse.com/core/info/modules/
21	//
22	// Please contact us if you have any questions.	
23	/// </summary>
24
25	class Class1
26	{
27		private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
28
29		static Class1() {}
30
31		// Relative path to the folder containing test files.
32		const string inputPath = "../../../../TestFiles/";
33		const string outputPath = "../../../../TestFiles/Output/";
34
35		/// <summary>
36		/// The main entry point for the application.
37		/// </summary>
38		[STAThread]
39		static int Main(string[] args)
40		{
41			// The first step in every application using PDFNet is to initialize the 
42			// library. The library is usually initialized only once, but calling 
43			// Initialize() multiple times is also fine.
44			PDFNet.Initialize(PDFTronLicense.Key);
45
46			PDFNet.AddResourceSearchPath("../../../../../Lib/");
47
48			if (!StructuredOutputModule.IsModuleAvailable())
49			{
50				Console.WriteLine();
51				Console.WriteLine("Unable to run the sample: Apryse SDK Structured Output module not available.");
52				Console.WriteLine("-----------------------------------------------------------------------------");
53				Console.WriteLine("The Structured Output module is an optional add-on, available for download");
54				Console.WriteLine("at https://docs.apryse.com/core/info/modules/. If you have already");
55				Console.WriteLine("downloaded this module, ensure that the SDK is able to find the required files");
56				Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.");
57				Console.WriteLine();
58				return 0;
59			}
60
61			bool err = false;
62
63			//////////////////////////////////////////////////////////////////////////
64			// Word
65			//////////////////////////////////////////////////////////////////////////
66
67			try
68			{
69				// Convert PDF document to Word
70				Console.WriteLine("Converting PDF to Word");
71
72				string outputFile = outputPath + "paragraphs_and_tables.docx";
73
74				pdftron.PDF.Convert.ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile);
75
76				Console.WriteLine("Result saved in " + outputFile);
77			}
78			catch (PDFNetException e)
79			{
80				Console.WriteLine("Unable to convert PDF document to Word, error: " + e.Message);
81				err = true;
82			}
83			catch (Exception e)
84			{
85				Console.WriteLine("Unknown Exception, error: ");
86				Console.WriteLine(e);
87				err = true;
88			}
89
90			//////////////////////////////////////////////////////////////////////////
91
92			try
93			{
94				// Convert PDF document to Word with options
95				Console.WriteLine("Converting PDF to Word with options");
96
97				string outputFile = outputPath + "paragraphs_and_tables_first_page.docx";
98
99				pdftron.PDF.Convert.WordOutputOptions wordOutputOptions = new pdftron.PDF.Convert.WordOutputOptions();
100
101				// Convert only the first page
102				wordOutputOptions.SetPages(1, 1);
103
104				pdftron.PDF.Convert.ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile, wordOutputOptions);
105
106				Console.WriteLine("Result saved in " + outputFile);
107			}
108			catch (PDFNetException e)
109			{
110				Console.WriteLine("Unable to convert PDF document to Word, error: " + e.Message);
111				err = true;
112			}
113			catch (Exception e)
114			{
115				Console.WriteLine("Unknown Exception, error: ");
116				Console.WriteLine(e);
117				err = true;
118			}
119
120			//////////////////////////////////////////////////////////////////////////
121			// Excel
122			//////////////////////////////////////////////////////////////////////////
123
124			try
125			{
126				// Convert PDF document to Excel
127				Console.WriteLine("Converting PDF to Excel");
128
129				string outputFile = outputPath + "paragraphs_and_tables.xlsx";
130
131				pdftron.PDF.Convert.ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile);
132
133				Console.WriteLine("Result saved in " + outputFile);
134			}
135			catch (PDFNetException e)
136			{
137				Console.WriteLine("Unable to convert PDF document to Excel, error: " + e.Message);
138				err = true;
139			}
140			catch (Exception e)
141			{
142				Console.WriteLine("Unknown Exception, error: ");
143				Console.WriteLine(e);
144				err = true;
145			}
146
147			//////////////////////////////////////////////////////////////////////////
148
149			try
150			{
151				// Convert PDF document to Excel with options
152				Console.WriteLine("Converting PDF to Excel with options");
153
154				string outputFile = outputPath + "paragraphs_and_tables_second_page.xlsx";
155
156				pdftron.PDF.Convert.ExcelOutputOptions excelOutputOptions = new pdftron.PDF.Convert.ExcelOutputOptions();
157
158				// Convert only the second page
159				excelOutputOptions.SetPages(2, 2);
160
161				pdftron.PDF.Convert.ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile, excelOutputOptions);
162
163				Console.WriteLine("Result saved in " + outputFile);
164			}
165			catch (PDFNetException e)
166			{
167				Console.WriteLine("Unable to convert PDF document to Excel, error: " + e.Message);
168				err = true;
169			}
170			catch (Exception e)
171			{
172				Console.WriteLine("Unknown Exception, error: ");
173				Console.WriteLine(e);
174				err = true;
175			}
176
177			//////////////////////////////////////////////////////////////////////////
178			// PowerPoint
179			//////////////////////////////////////////////////////////////////////////
180
181			try
182			{
183				// Convert PDF document to PowerPoint
184				Console.WriteLine("Converting PDF to PowerPoint");
185
186				string outputFile = outputPath + "paragraphs_and_tables.pptx";
187
188				pdftron.PDF.Convert.ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile);
189
190				Console.WriteLine("Result saved in " + outputFile);
191			}
192			catch (PDFNetException e)
193			{
194				Console.WriteLine("Unable to convert PDF document to PowerPoint, error: " + e.Message);
195				err = true;
196			}
197			catch (Exception e)
198			{
199				Console.WriteLine("Unknown Exception, error: ");
200				Console.WriteLine(e);
201				err = true;
202			}
203
204			//////////////////////////////////////////////////////////////////////////
205
206			try
207			{
208				// Convert PDF document to PowerPoint with options
209				Console.WriteLine("Converting PDF to PowerPoint with options");
210
211				string outputFile = outputPath + "paragraphs_and_tables_first_page.pptx";
212
213				pdftron.PDF.Convert.PowerPointOutputOptions powerPointOutputOptions = new pdftron.PDF.Convert.PowerPointOutputOptions();
214
215				// Convert only the first page
216				powerPointOutputOptions.SetPages(1, 1);
217
218				pdftron.PDF.Convert.ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions);
219
220				Console.WriteLine("Result saved in " + outputFile);
221			}
222			catch (PDFNetException e)
223			{
224				Console.WriteLine("Unable to convert PDF document to PowerPoint, error: " + e.Message);
225				err = true;
226			}
227			catch (Exception e)
228			{
229				Console.WriteLine("Unknown Exception, error: ");
230				Console.WriteLine(e);
231				err = true;
232			}
233
234			//////////////////////////////////////////////////////////////////////////
235
236			PDFNet.Terminate();
237			Console.WriteLine("Done.");
238			return (err == false ? 0 : 1);
239		}
240	}
241}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#include <iostream>
7#include <sstream>
8#include <PDF/PDFNet.h>
9#include <PDF/Convert.h>
10#include <PDF/StructuredOutputModule.h>
11#include "../../LicenseKey/CPP/LicenseKey.h"
12
13//---------------------------------------------------------------------------------------
14// The following sample illustrates how to use the PDF::Convert utility class to convert 
15// documents and files to Office.
16//
17// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
18// and other documents into Word, Excel, PowerPoint and HTML format.
19//
20// The Apryse SDK Structured Output module can be downloaded from
21// https://docs.apryse.com/core/info/modules/
22//
23// Please contact us if you have any questions.	
24//---------------------------------------------------------------------------------------
25
26using namespace pdftron;
27using namespace PDF;
28using namespace std;
29
30UString inputPath("../../TestFiles/");
31UString outputPath("../../TestFiles/Output/");
32
33int main(int argc, char *argv[])
34{	
35	// The first step in every application using PDFNet is to initialize the 
36	// library. The library is usually initialized only once, but calling 
37	// Initialize() multiple times is also fine.
38	PDFNet::Initialize(LicenseKey);
39
40	PDFNet::AddResourceSearchPath("../../../Lib/");
41
42	if (!StructuredOutputModule::IsModuleAvailable())
43	{
44		cout << endl;
45		cout << "Unable to run the sample: Apryse SDK Structured Output module not available." << endl;
46		cout << "-----------------------------------------------------------------------------" << endl;
47		cout << "The Structured Output module is an optional add-on, available for download" << endl;
48		cout << "at https://docs.apryse.com/core/info/modules/. If you have already" << endl;
49		cout << "downloaded this module, ensure that the SDK is able to find the required files" << endl;
50		cout << "using the PDFNet::AddResourceSearchPath() function." << endl;
51		cout << endl;
52		return 1;
53	}
54
55	int err = 0;
56
57	//////////////////////////////////////////////////////////////////////////
58	// Word
59	//////////////////////////////////////////////////////////////////////////
60
61	try
62	{
63		// Convert PDF document to Word
64		cout << "Converting PDF to Word" << endl;
65
66		UString outputFile = outputPath + "paragraphs_and_tables.docx";
67
68		Convert::ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile);
69
70		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
71	}
72	catch (Common::Exception& e)
73	{
74		cout << "Unable to convert PDF document to Word, error: " << e << endl;
75		err = 1;
76	}
77	catch (...)
78	{
79		cout << "Unknown Exception" << endl;
80		err = 1;
81	}
82
83	//////////////////////////////////////////////////////////////////////////
84
85	try
86	{
87		// Convert PDF document to Word with options
88		cout << "Converting PDF to Word with options" << endl;
89
90		UString outputFile = outputPath + "paragraphs_and_tables_first_page.docx";
91
92		Convert::WordOutputOptions wordOutputOptions;
93
94		// Convert only the first page
95		wordOutputOptions.SetPages(1, 1);
96
97		Convert::ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile, wordOutputOptions);
98
99		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
100	}
101	catch (Common::Exception& e)
102	{
103		cout << "Unable to convert PDF document to Word, error: " << e << endl;
104		err = 1;
105	}
106	catch (...)
107	{
108		cout << "Unknown Exception" << endl;
109		err = 1;
110	}
111
112	//////////////////////////////////////////////////////////////////////////
113	// Excel
114	//////////////////////////////////////////////////////////////////////////
115
116	try
117	{
118		// Convert PDF document to Excel
119		cout << "Converting PDF to Excel" << endl;
120
121		UString outputFile = outputPath + "paragraphs_and_tables.xlsx";
122
123		Convert::ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile);
124
125		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
126	}
127	catch (Common::Exception& e)
128	{
129		cout << "Unable to convert PDF document to Excel, error: " << e << endl;
130		err = 1;
131	}
132	catch (...)
133	{
134		cout << "Unknown Exception" << endl;
135		err = 1;
136	}
137
138	//////////////////////////////////////////////////////////////////////////
139
140	try
141	{
142		// Convert PDF document to Excel with options
143		cout << "Converting PDF to Excel with options" << endl;
144
145		UString outputFile = outputPath + "paragraphs_and_tables_second_page.xlsx";
146
147		Convert::ExcelOutputOptions excelOutputOptions;
148
149		// Convert only the second page
150		excelOutputOptions.SetPages(2, 2);
151
152		Convert::ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile, excelOutputOptions);
153
154		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
155	}
156	catch (Common::Exception& e)
157	{
158		cout << "Unable to convert PDF document to Excel, error: " << e << endl;
159		err = 1;
160	}
161	catch (...)
162	{
163		cout << "Unknown Exception" << endl;
164		err = 1;
165	}
166
167	//////////////////////////////////////////////////////////////////////////
168	// PowerPoint
169	//////////////////////////////////////////////////////////////////////////
170
171	try
172	{
173		// Convert PDF document to PowerPoint
174		cout << "Converting PDF to PowerPoint" << endl;
175
176		UString outputFile = outputPath + "paragraphs_and_tables.pptx";
177
178		Convert::ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile);
179
180		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
181	}
182	catch (Common::Exception& e)
183	{
184		cout << "Unable to convert PDF document to PowerPoint, error: " << e << endl;
185		err = 1;
186	}
187	catch (...)
188	{
189		cout << "Unknown Exception" << endl;
190		err = 1;
191	}
192
193	//////////////////////////////////////////////////////////////////////////
194
195	try
196	{
197		// Convert PDF document to PowerPoint with options
198		cout << "Converting PDF to PowerPoint with options" << endl;
199
200		UString outputFile = outputPath + "paragraphs_and_tables_first_page.pptx";
201
202		Convert::PowerPointOutputOptions powerPointOutputOptions;
203
204		// Convert only the first page
205		powerPointOutputOptions.SetPages(1, 1);
206
207		Convert::ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions);
208
209		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
210	}
211	catch (Common::Exception& e)
212	{
213		cout << "Unable to convert PDF document to PowerPoint, error: " << e << endl;
214		err = 1;
215	}
216	catch (...)
217	{
218		cout << "Unknown Exception" << endl;
219		err = 1;
220	}
221
222	//////////////////////////////////////////////////////////////////////////
223
224	PDFNet::Terminate();
225	cout << "Done.\n";
226	return err;
227}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3// Consult LICENSE.txt regarding license information.
4//---------------------------------------------------------------------------------------
5
6package main
7import (
8	"fmt"
9	. "pdftron"
10)
11
12import  "pdftron/Samples/LicenseKey/GO"
13
14//---------------------------------------------------------------------------------------
15// The following sample illustrates how to use the PDF::Convert utility class to convert 
16// documents and files to Word, Excel and PowerPoint.
17//
18// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
19// and other documents into Word, Excel, PowerPoint and HTML format.
20//
21// The PDFTron SDK Structured Output module can be downloaded from
22// https://docs.apryse.com/core/info/modules/
23//
24// Please contact us if you have any questions.
25//---------------------------------------------------------------------------------------
26
27// Relative path to the folder containing the test files.
28var inputPath = "../../TestFiles/"
29var outputPath = "../../TestFiles/Output/"
30
31//---------------------------------------------------------------------------------------
32
33func catch(err *error) {
34    if r := recover(); r != nil {
35        *err = fmt.Errorf("%v", r)
36    }
37}
38
39//---------------------------------------------------------------------------------------
40
41func ConvertToWordTest() (err error) {
42	defer catch(&err)
43
44	// Convert PDF document to Word
45	fmt.Println("Converting PDF to Word")
46
47	inputFile := inputPath + "paragraphs_and_tables.pdf"
48	outputFile := outputPath + "paragraphs_and_tables.docx"
49
50	// Convert to Word
51	ConvertToWord(inputFile, outputFile)
52
53	fmt.Println("Result saved in " + outputFile)
54	return nil
55}
56
57//---------------------------------------------------------------------------------------
58
59func ConvertToWordWithOptionsTest() (err error) {
60	defer catch(&err)
61
62	// Convert PDF document to Word with options
63	fmt.Println("Converting PDF to Word with options")
64
65	inputFile := inputPath + "paragraphs_and_tables.pdf"
66	outputFile := outputPath + "paragraphs_and_tables_first_page.docx"
67
68	wordOutputOptions := NewWordOutputOptions()
69
70	// Convert only the first page
71	wordOutputOptions.SetPages(1, 1)
72
73	// Convert to Word
74	ConvertToWord(inputFile, outputFile, wordOutputOptions)
75
76	fmt.Println("Result saved in " + outputFile)
77	return nil
78}
79
80//---------------------------------------------------------------------------------------
81
82func ConvertToExcelTest() (err error) {
83	defer catch(&err)
84
85	// Convert PDF document to Excel
86	fmt.Println("Converting PDF to Excel")
87
88	inputFile := inputPath + "paragraphs_and_tables.pdf"
89	outputFile := outputPath + "paragraphs_and_tables.xlsx"
90
91	// Convert to Excel
92	ConvertToExcel(inputFile, outputFile)
93
94	fmt.Println("Result saved in " + outputFile)
95	return nil
96}
97
98//---------------------------------------------------------------------------------------
99
100func ConvertToExcelWithOptionsTest() (err error) {
101	defer catch(&err)
102
103	// Convert PDF document to Excel with options
104	fmt.Println("Converting PDF to Excel with options")
105
106	inputFile := inputPath + "paragraphs_and_tables.pdf"
107	outputFile := outputPath + "paragraphs_and_tables_second_page.xlsx"
108
109	excelOutputOptions := NewExcelOutputOptions()
110
111	// Convert only the second page
112	excelOutputOptions.SetPages(2, 2)
113
114	// Convert to Excel
115	ConvertToExcel(inputFile, outputFile, excelOutputOptions)
116
117	fmt.Println("Result saved in " + outputFile)
118	return nil
119}
120
121//---------------------------------------------------------------------------------------
122
123func ConvertToPowerPointTest() (err error) {
124	defer catch(&err)
125
126	// Convert PDF document to PowerPoint
127	fmt.Println("Converting PDF to PowerPoint")
128
129	inputFile := inputPath + "paragraphs_and_tables.pdf"
130	outputFile := outputPath + "paragraphs_and_tables.pptx"
131
132	// Convert to PowerPoint
133	ConvertToPowerPoint(inputFile, outputFile)
134
135	fmt.Println("Result saved in " + outputFile)
136	return nil
137}
138
139//---------------------------------------------------------------------------------------
140
141func ConvertToPowerPointWithOptionsTest() (err error) {
142	defer catch(&err)
143
144	// Convert PDF document to PowerPoint with options
145	fmt.Println("Converting PDF to PowerPoint with options")
146
147	inputFile := inputPath + "paragraphs_and_tables.pdf"
148	outputFile := outputPath + "paragraphs_and_tables_first_page.pptx"
149
150	powerPointOutputOptions := NewPowerPointOutputOptions()
151
152	// Convert only the first page
153	powerPointOutputOptions.SetPages(1, 1)
154
155	// Convert to PowerPoint
156	ConvertToPowerPoint(inputFile, outputFile, powerPointOutputOptions)
157
158	fmt.Println("Result saved in " + outputFile)
159	return nil
160}
161
162//---------------------------------------------------------------------------------------
163
164func main() {
165    // The first step in every application using PDFNet is to initialize the 
166    // library. The library is usually initialized only once, but calling 
167    // Initialize() multiple times is also fine.
168    PDFNetInitialize(PDFTronLicense.Key)
169
170	//-----------------------------------------------------------------------------------
171
172	PDFNetAddResourceSearchPath("../../../PDFNetC/Lib/")
173
174	if !StructuredOutputModuleIsModuleAvailable() {
175		fmt.Println("")
176		fmt.Println("Unable to run the sample: PDFTron SDK Structured Output module not available.")
177		fmt.Println("-----------------------------------------------------------------------------")
178		fmt.Println("The Structured Output module is an optional add-on, available for download")
179		fmt.Println("at https://docs.apryse.com/core/info/modules/. If you have already")
180		fmt.Println("downloaded this module, ensure that the SDK is able to find the required files")
181		fmt.Println("using the PDFNet::AddResourceSearchPath() function.")
182		fmt.Println("")
183		return
184	}
185
186	//-----------------------------------------------------------------------------------
187
188	// Convert PDF document to Word
189	err := ConvertToWordTest()
190	if err != nil {
191		fmt.Println(fmt.Errorf("Unable to convert PDF document to Word, error: %s", err))
192	}
193
194	//-----------------------------------------------------------------------------------
195
196	// Convert PDF document to Word with options
197	err = ConvertToWordWithOptionsTest()
198	if err != nil {
199		fmt.Println(fmt.Errorf("Unable to convert PDF document to Word, error: %s", err))
200	}
201
202	//-----------------------------------------------------------------------------------
203
204	// Convert PDF document to Excel
205	err = ConvertToExcelTest()
206	if err != nil {
207		fmt.Println(fmt.Errorf("Unable to convert PDF document to Excel, error: %s", err))
208	}
209
210	//-----------------------------------------------------------------------------------
211
212	// Convert PDF document to Excel with options
213	err = ConvertToExcelWithOptionsTest()
214	if err != nil {
215		fmt.Println(fmt.Errorf("Unable to convert PDF document to Excel, error: %s", err))
216	}
217
218	//-----------------------------------------------------------------------------------
219
220	// Convert PDF document to PowerPoint
221	err = ConvertToPowerPointTest()
222	if err != nil {
223		fmt.Println(fmt.Errorf("Unable to convert PDF document to PowerPoint, error: %s", err))
224	}
225
226	//-----------------------------------------------------------------------------------
227
228	// Convert PDF document to PowerPoint with options
229	err = ConvertToPowerPointWithOptionsTest()
230	if err != nil {
231		fmt.Println(fmt.Errorf("Unable to convert PDF document to PowerPoint, error: %s", err))
232	}
233
234	//-----------------------------------------------------------------------------------
235
236    PDFNetTerminate()
237    fmt.Println("Done.")
238}
1//
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6import com.pdftron.common.PDFNetException;
7import com.pdftron.pdf.*;
8
9//---------------------------------------------------------------------------------------
10// The following sample illustrates how to use the PDF::Convert utility class to convert 
11// documents and files to Office.
12//
13// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
14// and other documents into Word, Excel, PowerPoint and HTML format.
15//
16// The Apryse SDK Structured Output module can be downloaded from
17// https://docs.apryse.com/core/info/modules/
18//
19// Please contact us if you have any questions.
20//---------------------------------------------------------------------------------------
21
22public class PDF2OfficeTest 
23{
24    // Relative path to the folder containing test files.
25    static String inputPath = "../../TestFiles/";
26    static String outputPath = "../../TestFiles/Output/";
27
28    /// <summary>
29    /// The main entry point for the application.
30    /// </summary>
31    public static void main(String[] args) 
32    {
33        // The first step in every application using PDFNet is to initialize the 
34        // library. The library is usually initialized only once, but calling 
35        // Initialize() multiple times is also fine.
36        PDFNet.initialize(PDFTronLicense.Key());
37
38        PDFNet.addResourceSearchPath("../../../Lib/");
39
40        try {
41            if (!StructuredOutputModule.isModuleAvailable()) {
42                System.out.println();
43                System.out.println("Unable to run the sample: Apryse SDK Structured Output module not available.");
44                System.out.println("-----------------------------------------------------------------------------");
45                System.out.println("The Structured Output module is an optional add-on, available for download");
46                System.out.println("at https://docs.apryse.com/core/info/modules/. If you have already");
47                System.out.println("downloaded this module, ensure that the SDK is able to find the required files");
48                System.out.println("using the PDFNet::AddResourceSearchPath() function.");
49                System.out.println();
50                return;
51            }
52        } catch (PDFNetException e) {
53            System.out.println(e);
54            return;
55        }  catch (Exception e) {
56            System.out.println(e);
57            return;
58        }
59
60        boolean err = false;
61
62        //////////////////////////////////////////////////////////////////////////
63        // Word
64        //////////////////////////////////////////////////////////////////////////
65
66        try {
67            // Convert PDF document to Word
68            System.out.println("Converting PDF to Word");
69
70            String outputFile = outputPath + "paragraphs_and_tables.docx";
71
72            Convert.toWord(inputPath + "paragraphs_and_tables.pdf", outputFile);
73
74            System.out.println("Result saved in " + outputFile);
75        } catch (PDFNetException e) {
76            System.out.println("Unable to convert PDF document to Word, error: ");
77            System.out.println(e);
78            err = true;
79        }  catch (Exception e) {
80            System.out.println("Unknown Exception, error: ");
81            System.out.println(e);
82            err = true;
83        }
84
85        //////////////////////////////////////////////////////////////////////////
86
87        try {
88            // Convert PDF document to Word with options
89            System.out.println("Converting PDF to Word with options");
90
91            String outputFile = outputPath + "paragraphs_and_tables_first_page.docx";
92
93            Convert.WordOutputOptions wordOutputOptions = new Convert.WordOutputOptions();
94
95            // Convert only the first page
96            wordOutputOptions.setPages(1, 1);
97
98            Convert.toWord(inputPath + "paragraphs_and_tables.pdf", outputFile, wordOutputOptions);
99
100            System.out.println("Result saved in " + outputFile);
101        } catch (PDFNetException e) {
102            System.out.println("Unable to convert PDF document to Word, error: ");
103            System.out.println(e);
104            err = true;
105        }  catch (Exception e) {
106            System.out.println("Unknown Exception, error: ");
107            System.out.println(e);
108            err = true;
109        }
110
111        //////////////////////////////////////////////////////////////////////////
112        // Excel
113        //////////////////////////////////////////////////////////////////////////
114
115        try {
116            // Convert PDF document to Excel
117            System.out.println("Converting PDF to Excel");
118
119            String outputFile = outputPath + "paragraphs_and_tables.xlsx";
120
121            Convert.toExcel(inputPath + "paragraphs_and_tables.pdf", outputFile);
122
123            System.out.println("Result saved in " + outputFile);
124        } catch (PDFNetException e) {
125            System.out.println("Unable to convert PDF document to Excel, error: ");
126            System.out.println(e);
127            err = true;
128        }  catch (Exception e) {
129            System.out.println("Unknown Exception, error: ");
130            System.out.println(e);
131            err = true;
132        }
133
134        //////////////////////////////////////////////////////////////////////////
135
136        try (PDFDoc doc = new PDFDoc()) {
137            // Convert PDF document to Excel with options
138            System.out.println("Converting PDF to Excel with options");
139
140            String outputFile = outputPath + "paragraphs_and_tables_second_page.xlsx";
141
142            Convert.ExcelOutputOptions excelOutputOptions = new Convert.ExcelOutputOptions();
143
144            // Convert only the second page
145            excelOutputOptions.setPages(2, 2);
146
147            Convert.toExcel(inputPath + "paragraphs_and_tables.pdf", outputFile, excelOutputOptions);
148
149            System.out.println("Result saved in " + outputFile);
150        } catch (PDFNetException e) {
151            System.out.println("Unable to convert PDF document to Excel, error: ");
152            System.out.println(e);
153            err = true;
154        }  catch (Exception e) {
155            System.out.println("Unknown Exception, error: ");
156            System.out.println(e);
157            err = true;
158        }
159
160        //////////////////////////////////////////////////////////////////////////
161        // PowerPoint
162        //////////////////////////////////////////////////////////////////////////
163
164        try {
165            // Convert PDF document to PowerPoint
166            System.out.println("Converting PDF to PowerPoint");
167
168            String outputFile = outputPath + "paragraphs_and_tables.pptx";
169
170            Convert.toPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile);
171
172            System.out.println("Result saved in " + outputFile);
173        } catch (PDFNetException e) {
174            System.out.println("Unable to convert PDF document to PowerPoint, error: ");
175            System.out.println(e);
176            err = true;
177        }  catch (Exception e) {
178            System.out.println("Unknown Exception, error: ");
179            System.out.println(e);
180            err = true;
181        }
182
183        //////////////////////////////////////////////////////////////////////////
184
185        try {
186            // Convert PDF document to PowerPoint with options
187            System.out.println("Converting PDF to PowerPoint with options");
188
189            String outputFile = outputPath + "paragraphs_and_tables_first_page.pptx";
190
191            Convert.PowerPointOutputOptions powerPointOutputOptions = new Convert.PowerPointOutputOptions();
192
193            // Convert only the first page
194            powerPointOutputOptions.setPages(1, 1);
195
196            Convert.toPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions);
197
198            System.out.println("Result saved in " + outputFile);
199        } catch (PDFNetException e) {
200            System.out.println("Unable to convert PDF document to PowerPoint, error: ");
201            System.out.println(e);
202            err = true;
203        }  catch (Exception e) {
204            System.out.println("Unknown Exception, error: ");
205            System.out.println(e);
206            err = true;
207        }
208
209        //////////////////////////////////////////////////////////////////////////
210
211        PDFNet.terminate();
212        System.out.println("Done.");        
213    }
214}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6//---------------------------------------------------------------------------------------
7// The following sample illustrates how to use the PDF::Convert utility class to convert 
8// documents and files to Word, Excel and PowerPoint.
9//
10// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
11// and other documents into Word, Excel, PowerPoint and HTML format.
12//
13// The Apryse SDK Structured Output module can be downloaded from
14// https://docs.apryse.com/core/info/modules/
15//
16// Please contact us if you have any questions.	
17//---------------------------------------------------------------------------------------
18
19const { PDFNet } = require('@pdftron/pdfnet-node');
20const PDFTronLicense = require('../LicenseKey/LicenseKey');
21
22((exports) => {
23	'use strict';
24
25	exports.runPDF2OfficeTest = () => {
26
27		const main = async () => {
28
29			const inputPath = '../TestFiles/';
30			const outputPath = '../TestFiles/Output/';
31
32			//////////////////////////////////////////////////////////////////////////
33
34			await PDFNet.addResourceSearchPath('../../lib/');
35
36			if (!await PDFNet.StructuredOutputModule.isModuleAvailable()) {
37				console.log('\nUnable to run the sample: Apryse SDK Structured Output module not available.');
38				console.log('---------------------------------------------------------------');
39				console.log('The Structured Output module is an optional add-on, available for download');
40				console.log('at https://docs.apryse.com/core/info/modules/. If you have already');
41				console.log('downloaded this module, ensure that the SDK is able to find the required files');
42				console.log('using the PDFNet::AddResourceSearchPath() function.\n');
43
44				return;
45			}
46
47			//////////////////////////////////////////////////////////////////////////
48
49			try {
50				// Convert PDF document to Word
51				console.log('Converting PDF to Word');
52
53				const outputFile = outputPath + 'paragraphs_and_tables.docx';
54
55				await PDFNet.Convert.fileToWord(inputPath + 'paragraphs_and_tables.pdf', outputFile);
56
57				console.log('Result saved in ' + outputFile);
58			} catch (err) {
59				console.log(err);
60			}
61
62			try {
63				// Convert PDF document to Word with options
64				console.log('Converting PDF to Word with options');
65
66				const outputFile = outputPath + 'paragraphs_and_tables_first_page.docx';
67
68				const wordOutputOptions = new PDFNet.Convert.WordOutputOptions();
69
70				// Convert only the first page
71				wordOutputOptions.setPages(1, 1);
72
73				await PDFNet.Convert.fileToWord(inputPath + 'paragraphs_and_tables.pdf', outputFile, wordOutputOptions);
74
75				console.log('Result saved in ' + outputFile);
76			} catch (err) {
77				console.log(err);
78			}
79
80			//////////////////////////////////////////////////////////////////////////
81
82			try {
83				// Convert PDF document to Excel
84				console.log('Converting PDF to Excel');
85
86				const outputFile = outputPath + 'paragraphs_and_tables.xlsx';
87
88				await PDFNet.Convert.fileToExcel(inputPath + 'paragraphs_and_tables.pdf', outputFile);
89
90				console.log('Result saved in ' + outputFile);
91			} catch (err) {
92				console.log(err);
93			}
94
95			try {
96				// Convert PDF document to Excel with options
97				console.log('Converting PDF to Excel with options');
98
99				const outputFile = outputPath + 'paragraphs_and_tables_second_page.xlsx';
100
101				const excelOutputOptions = new PDFNet.Convert.ExcelOutputOptions();
102
103				// Convert only the second page
104				excelOutputOptions.setPages(2, 2);
105
106				await PDFNet.Convert.fileToExcel(inputPath + 'paragraphs_and_tables.pdf', outputFile, excelOutputOptions);
107
108				console.log('Result saved in ' + outputFile);
109			} catch (err) {
110				console.log(err);
111			}
112
113			//////////////////////////////////////////////////////////////////////////
114
115			try {
116				// Convert PDF document to PowerPoint
117				console.log('Converting PDF to PowerPoint');
118
119				const outputFile = outputPath + 'paragraphs_and_tables.pptx';
120
121				await PDFNet.Convert.fileToPowerPoint(inputPath + 'paragraphs_and_tables.pdf', outputFile);
122
123				console.log('Result saved in ' + outputFile);
124			} catch (err) {
125				console.log(err);
126			}
127
128			try {
129				// Convert PDF document to PowerPoint with options
130				console.log('Converting PDF to PowerPoint with options');
131
132				const outputFile = outputPath + 'paragraphs_and_tables_first_page.pptx';
133
134				const powerPointOutputOptions = new PDFNet.Convert.PowerPointOutputOptions();
135
136				// Convert only the first page
137				powerPointOutputOptions.setPages(1, 1);
138
139				await PDFNet.Convert.fileToPowerPoint(inputPath + 'paragraphs_and_tables.pdf', outputFile, powerPointOutputOptions);
140
141				console.log('Result saved in ' + outputFile);
142			} catch (err) {
143				console.log(err);
144			}
145
146			//////////////////////////////////////////////////////////////////////////
147
148			console.log('Done.');
149		};
150
151		PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
152			console.log('Error: ' + JSON.stringify(error));
153		}).then(function () { return PDFNet.shutdown(); });
154	};
155	exports.runPDF2OfficeTest();
156})(exports);
157// eslint-disable-next-line spaced-comment
158//# sourceURL=PDF2OfficeTest.js
1<?php
2//---------------------------------------------------------------------------------------
3// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
4// Consult LICENSE.txt regarding license information.
5//---------------------------------------------------------------------------------------
6if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
7include("../../../PDFNetC/Lib/PDFNetPHP.php");
8include("../../LicenseKey/PHP/LicenseKey.php");
9
10//---------------------------------------------------------------------------------------
11// The following sample illustrates how to use the PDF::Convert utility class to convert 
12// documents and files to Word, Excel and PowerPoint.
13//
14// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
15// and other documents into Word, Excel, PowerPoint and HTML format.
16//
17// The PDFTron SDK Structured Output module can be downloaded from
18// https://docs.apryse.com/core/info/modules/
19//
20// Please contact us if you have any questions.
21//---------------------------------------------------------------------------------------
22
23function main()
24{
25	// Relative path to the folder containing the test files.
26	$inputPath = getcwd()."/../../TestFiles/";
27	$outputPath = $inputPath."Output/";
28
29	// The first step in every application using PDFNet is to initialize the 
30	// library. The library is usually initialized only once, but calling 
31	// Initialize() multiple times is also fine.
32	global $LicenseKey;
33	PDFNet::Initialize($LicenseKey);
34	PDFNet::GetSystemFontList();    // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.
35	
36	//-----------------------------------------------------------------------------------
37
38	PDFNet::AddResourceSearchPath("../../../PDFNetC/Lib/");
39
40	if (!StructuredOutputModule::IsModuleAvailable()) {
41		echo(nl2br("\n"));
42		echo(nl2br("Unable to run the sample: PDFTron SDK Structured Output module not available.\n"));
43		echo(nl2br("-----------------------------------------------------------------------------\n"));
44		echo(nl2br("The Structured Output module is an optional add-on, available for download\n"));
45		echo(nl2br("at https://docs.apryse.com/core/info/modules/. If you have already\n"));
46		echo(nl2br("downloaded this module, ensure that the SDK is able to find the required files\n"));
47		echo(nl2br("using the PDFNet::AddResourceSearchPath() function.\n"));
48		echo(nl2br("\n"));
49		return;
50	}
51
52	//-----------------------------------------------------------------------------------
53
54	try {
55		// Convert PDF document to Word
56		echo(nl2br("Converting PDF to Word\n"));
57
58		$outputFile = $outputPath."paragraphs_and_tables.docx";
59
60		Convert::ToWord($inputPath."paragraphs_and_tables.pdf", $outputFile);
61
62		echo(nl2br("Result saved in " . $outputFile . "\n"));
63	}
64	catch(Exception $e) {
65		echo(nl2br("Unable to convert PDF document to Word, error: " . $e->getMessage() . "\n"));
66	}
67
68	//-----------------------------------------------------------------------------------
69
70	try {
71		// Convert PDF document to Word with options
72		echo(nl2br("Converting PDF to Word with options\n"));
73
74		$outputFile = $outputPath."paragraphs_and_tables_first_page.docx";
75
76		$wordOutputOptions = new WordOutputOptions(); // Convert::WordOutputOptions();
77
78		// Convert only the first page
79		$wordOutputOptions->SetPages(1, 1);
80
81		Convert::ToWord($inputPath."paragraphs_and_tables.pdf", $outputFile, $wordOutputOptions);
82
83		echo(nl2br("Result saved in " . $outputFile . "\n"));
84	}
85	catch(Exception $e) {
86		echo(nl2br("Unable to convert PDF document to Word, error: " . $e->getMessage() . "\n"));
87	}
88
89	//-----------------------------------------------------------------------------------
90
91	try {
92		// Convert PDF document to Excel
93		echo(nl2br("Converting PDF to Excel\n"));
94
95		$outputFile = $outputPath."paragraphs_and_tables.xlsx";
96
97		Convert::ToExcel($inputPath."paragraphs_and_tables.pdf", $outputFile);
98
99		echo(nl2br("Result saved in " . $outputFile . "\n"));
100	}
101	catch(Exception $e) {
102		echo(nl2br("Unable to convert PDF document to Excel, error: " . $e->getMessage() . "\n"));
103	}
104
105	//-----------------------------------------------------------------------------------
106
107	try {
108		// Convert PDF document to Excel with options
109		echo(nl2br("Converting PDF to Excel with options\n"));
110
111		$outputFile = $outputPath."paragraphs_and_tables_second_page.xlsx";
112
113		$excelOutputOptions = new ExcelOutputOptions(); // Convert::ExcelOutputOptions();
114
115		// Convert only the second page
116		$excelOutputOptions->SetPages(2, 2);
117
118		Convert::ToExcel($inputPath."paragraphs_and_tables.pdf", $outputFile, $excelOutputOptions);
119
120		echo(nl2br("Result saved in " . $outputFile . "\n"));
121	}
122	catch(Exception $e) {
123		echo(nl2br("Unable to convert PDF document to Excel, error: " . $e->getMessage() . "\n"));
124	}
125
126	//-----------------------------------------------------------------------------------
127
128	try {
129		// Convert PDF document to PowerPoint
130		echo(nl2br("Converting PDF to PowerPoint\n"));
131
132		$outputFile = $outputPath."paragraphs_and_tables.pptx";
133
134		Convert::ToPowerPoint($inputPath."paragraphs_and_tables.pdf", $outputFile);
135
136		echo(nl2br("Result saved in " . $outputFile . "\n"));
137	}
138	catch(Exception $e) {
139		echo(nl2br("Unable to convert PDF document to PowerPoint, error: " . $e->getMessage() . "\n"));
140	}
141
142	//-----------------------------------------------------------------------------------
143
144	try {
145		// Convert PDF document to PowerPoint with options
146		echo(nl2br("Converting PDF to PowerPoint with options\n"));
147
148		$outputFile = $outputPath."paragraphs_and_tables_first_page.pptx";
149
150		$powerPointOutputOptions = new PowerPointOutputOptions(); // Convert::PowerPointOutputOptions();
151
152		// Convert only the first page
153		$powerPointOutputOptions->SetPages(1, 1);
154
155		Convert::ToPowerPoint($inputPath."paragraphs_and_tables.pdf", $outputFile, $powerPointOutputOptions);
156
157		echo(nl2br("Result saved in " . $outputFile . "\n"));
158	}
159	catch(Exception $e) {
160		echo(nl2br("Unable to convert PDF document to PowerPoint, error: " . $e->getMessage() . "\n"));
161	}
162
163	//-----------------------------------------------------------------------------------
164
165	PDFNet::Terminate();
166	echo(nl2br("Done.\n"));
167}
168
169main();
170?>
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6import site
7site.addsitedir("../../../PDFNetC/Lib")
8import sys
9from PDFNetPython import *
10
11import platform
12
13sys.path.append("../../LicenseKey/PYTHON")
14from LicenseKey import *
15
16#---------------------------------------------------------------------------------------
17# The following sample illustrates how to use the PDF.Convert utility class to convert 
18# documents and files to Word, Excel and PowerPoint.
19#
20# The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
21# and other documents into Word, Excel, PowerPoint and HTML format.
22#
23# The PDFTron SDK Structured Output module can be downloaded from
24# https://docs.apryse.com/core/info/modules/
25#
26# Please contact us if you have any questions.
27#---------------------------------------------------------------------------------------
28
29# Relative path to the folder containing the test files.
30inputPath = "../../TestFiles/"
31outputPath = "../../TestFiles/Output/"
32
33def main():
34    # The first step in every application using PDFNet is to initialize the 
35    # library. The library is usually initialized only once, but calling 
36    # Initialize() multiple times is also fine.
37    PDFNet.Initialize(LicenseKey)
38    
39    PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/")
40
41    if not StructuredOutputModule.IsModuleAvailable():
42        print("")
43        print("Unable to run the sample: PDFTron SDK Structured Output module not available.")
44        print("-----------------------------------------------------------------------------")
45        print("The Structured Output module is an optional add-on, available for download")
46        print("at https://docs.apryse.com/core/info/modules/. If you have already")
47        print("downloaded this module, ensure that the SDK is able to find the required files")
48        print("using the PDFNet::AddResourceSearchPath() function.")
49        print("")
50        return
51
52    #-----------------------------------------------------------------------------------
53
54    try:
55        # Convert PDF document to Word
56        print("Converting PDF to Word")
57
58        outputFile = outputPath + "paragraphs_and_tables.docx"
59
60        Convert.ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile)
61
62        print("Result saved in " + outputFile)
63    except Exception as e:
64        print("Unable to convert PDF document to Word, error: " + str(e))
65
66    #-----------------------------------------------------------------------------------
67
68    try:
69        # Convert PDF document to Word with options
70        print("Converting PDF to Word with options")
71
72        outputFile = outputPath + "paragraphs_and_tables_first_page.docx"
73
74        wordOutputOptions = WordOutputOptions()
75
76        # Convert only the first page
77        wordOutputOptions.SetPages(1, 1)
78
79        Convert.ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile, wordOutputOptions)
80
81        print("Result saved in " + outputFile)
82    except Exception as e:
83        print("Unable to convert PDF document to Word, error: " + str(e))
84
85    #-----------------------------------------------------------------------------------
86
87    try:
88        # Convert PDF document to Excel
89        print("Converting PDF to Excel")
90
91        outputFile = outputPath + "paragraphs_and_tables.xlsx"
92
93        Convert.ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile)
94
95        print("Result saved in " + outputFile)
96    except Exception as e:
97        print("Unable to convert PDF document to Excel, error: " + str(e))
98
99    #-----------------------------------------------------------------------------------
100
101    try:
102        # Convert PDF document to Excel with options
103        print("Converting PDF to Excel with options")
104
105        outputFile = outputPath + "paragraphs_and_tables_second_page.xlsx"
106
107        excelOutputOptions = ExcelOutputOptions()
108
109        # Convert only the second page
110        excelOutputOptions.SetPages(2, 2)
111
112        Convert.ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile, excelOutputOptions)
113
114        print("Result saved in " + outputFile)
115    except Exception as e:
116        print("Unable to convert PDF document to Excel, error: " + str(e))
117
118    #-----------------------------------------------------------------------------------
119
120    try:
121        # Convert PDF document to PowerPoint
122        print("Converting PDF to PowerPoint")
123
124        outputFile = outputPath + "paragraphs_and_tables.pptx"
125
126        Convert.ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile)
127
128        print("Result saved in " + outputFile)
129    except Exception as e:
130        print("Unable to convert PDF document to PowerPoint, error: " + str(e))
131
132    #-----------------------------------------------------------------------------------
133
134    try:
135        # Convert PDF document to PowerPoint with options
136        print("Converting PDF to PowerPoint with options")
137
138        outputFile = outputPath + "paragraphs_and_tables_first_page.pptx"
139
140        powerPointOutputOptions = PowerPointOutputOptions()
141
142        # Convert only the first page
143        powerPointOutputOptions.SetPages(1, 1)
144
145        Convert.ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions)
146
147        print("Result saved in " + outputFile)
148    except Exception as e:
149        print("Unable to convert PDF document to PowerPoint, error: " + str(e))
150
151    #-----------------------------------------------------------------------------------
152
153    PDFNet.Terminate()
154    print("Done.")
155    
156if __name__ == '__main__':
157    main()
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6require '../../../PDFNetC/Lib/PDFNetRuby'
7include PDFNetRuby
8require '../../LicenseKey/RUBY/LicenseKey'
9
10$stdout.sync = true
11
12#---------------------------------------------------------------------------------------
13# The following sample illustrates how to use the PDF.Convert utility class to convert 
14# documents and files to Word, Excel and PowerPoint.
15#
16# The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
17# and other documents into Word, Excel, PowerPoint and HTML format.
18#
19# The PDFTron SDK Structured Output module can be downloaded from
20# https://docs.apryse.com/core/info/modules/
21#
22# Please contact us if you have any questions.
23#---------------------------------------------------------------------------------------
24
25# Relative path to the folder containing the test files.
26$inputPath = "../../TestFiles/"
27$outputPath = "../../TestFiles/Output/"
28	
29def main()
30	# The first step in every application using PDFNet is to initialize the 
31	# library. The library is usually initialized only once, but calling 
32	# Initialize() multiple times is also fine.
33	PDFNet.Initialize(PDFTronLicense.Key)
34
35	PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/");
36
37	if !StructuredOutputModule.IsModuleAvailable() then
38		puts ""
39		puts "Unable to run the sample: PDFTron SDK Structured Output module not available."
40		puts "-----------------------------------------------------------------------------"
41		puts "The Structured Output module is an optional add-on, available for download"
42		puts "at https://docs.apryse.com/core/info/modules/. If you have already"
43		puts "downloaded this module, ensure that the SDK is able to find the required files"
44		puts "using the PDFNet::AddResourceSearchPath() function."
45		puts ""
46		return
47	end
48	
49	#-----------------------------------------------------------------------------------
50
51	begin
52		# Convert PDF document to Word
53		puts "Converting PDF to Word"
54
55		$outputFile = $outputPath + "paragraphs_and_tables.docx"
56
57		Convert.ToWord($inputPath + "paragraphs_and_tables.pdf", $outputFile)
58
59		puts "Result saved in " + $outputFile
60	rescue => error
61		puts "Unable to convert PDF document to Word, error: " + error.message
62	end
63
64	#-----------------------------------------------------------------------------------
65	
66	begin
67		# Convert PDF document to Word with options
68		puts "Converting PDF to Word with options"
69
70		$outputFile = $outputPath + "paragraphs_and_tables_first_page.docx"
71
72		$wordOutputOptions = Convert::WordOutputOptions.new()
73
74		# Convert only the first page
75		$wordOutputOptions.SetPages(1, 1);
76
77		Convert.ToWord($inputPath + "paragraphs_and_tables.pdf", $outputFile, $wordOutputOptions)
78		puts "Result saved in " + $outputFile
79	rescue => error
80		puts "Unable to convert PDF document to Word, error: " + error.message
81	end
82
83	#-----------------------------------------------------------------------------------
84
85	begin
86		# Convert PDF document to Excel
87		puts "Converting PDF to Excel"
88
89		$outputFile = $outputPath + "paragraphs_and_tables.xlsx"
90
91		Convert.ToExcel($inputPath + "paragraphs_and_tables.pdf", $outputFile)
92
93		puts "Result saved in " + $outputFile
94	rescue => error
95		puts "Unable to convert PDF document to Excel, error: " + error.message
96	end
97
98	#-----------------------------------------------------------------------------------
99	
100	begin
101		# Convert PDF document to Excel with options
102		puts "Converting PDF to Excel with options"
103
104		$outputFile = $outputPath + "paragraphs_and_tables_second_page.xlsx"
105
106		$excelOutputOptions = Convert::ExcelOutputOptions.new()
107
108		# Convert only the second page
109		$excelOutputOptions.SetPages(2, 2);
110
111		Convert.ToExcel($inputPath + "paragraphs_and_tables.pdf", $outputFile, $excelOutputOptions)
112		puts "Result saved in " + $outputFile
113	rescue => error
114		puts "Unable to convert PDF document to Excel, error: " + error.message
115	end
116
117	#-----------------------------------------------------------------------------------
118
119	begin
120		# Convert PDF document to PowerPoint
121		puts "Converting PDF to PowerPoint"
122
123		$outputFile = $outputPath + "paragraphs_and_tables.pptx"
124
125		Convert.ToPowerPoint($inputPath + "paragraphs_and_tables.pdf", $outputFile)
126
127		puts "Result saved in " + $outputFile
128	rescue => error
129		puts "Unable to convert PDF document to PowerPoint, error: " + error.message
130	end
131
132	#-----------------------------------------------------------------------------------
133	
134	begin
135		# Convert PDF document to PowerPoint with options
136		puts "Converting PDF to PowerPoint with options"
137
138		$outputFile = $outputPath + "paragraphs_and_tables_first_page.pptx"
139
140		$powerPointOutputOptions = Convert::PowerPointOutputOptions.new()
141
142		# Convert only the first page
143		$powerPointOutputOptions.SetPages(1, 1);
144
145		Convert.ToPowerPoint($inputPath + "paragraphs_and_tables.pdf", $outputFile, $powerPointOutputOptions)
146		puts "Result saved in " + $outputFile
147	rescue => error
148		puts "Unable to convert PDF document to PowerPoint, error: " + error.message
149	end
150
151	#-----------------------------------------------------------------------------------
152
153	PDFNet.Terminate
154	puts "Done."
155end
156
157main()
1'
2' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3'
4
5Imports System
6Imports pdftron
7Imports pdftron.Common
8Imports pdftron.PDF
9
10' The following sample illustrates how to use the PDF:Convert utility Class To convert 
11' documents And files to Office.
12'
13' The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
14' and other documents into Word, Excel, PowerPoint and HTML format.
15'
16' The Apryse SDK Structured Output module can be downloaded from
17' https://docs.apryse.com/core/info/modules/
18'
19' Please contact us if you have any questions.	
20'
21' Also note that conversion under ASP.NET can be tricky to configure. Please see the following document for advice: 
22' http://www.pdftron.com/pdfnet/faq_files/Converting_Documents_in_Windows_Service_or_ASP.NET_Application_using_PDFNet.pdf
23
24Module PDF2OfficeTestVB
25    Class Class1
26        Shared pdfNetLoader As pdftron.PDFNetLoader = pdftron.PDFNetLoader.Instance()
27
28        Shared Sub New()
29        End Sub
30
31        ' Relative path to the folder containing test files.
32        Const inputPath As String = "../../../../TestFiles/"
33        Const outputPath As String = "../../../../TestFiles/Output/"
34
35        <STAThread>
36        Shared Sub Main(ByVal args As String())
37            ' The first step in every application using PDFNet Is to initialize the 
38            ' library. The library Is usually initialized only once, but calling 
39            ' Initialize() multiple times Is also fine.
40            PDFNet.Initialize(PDFTronLicense.Key)
41
42            PDFNet.AddResourceSearchPath("../../../../../Lib/")
43
44            If Not StructuredOutputModule.IsModuleAvailable() Then
45                Console.WriteLine()
46                Console.WriteLine("Unable to run the sample: Apryse SDK Structured Output module not available.")
47                Console.WriteLine("-----------------------------------------------------------------------------")
48                Console.WriteLine("The Structured Output module is an optional add-on, available for download")
49                Console.WriteLine("at https://docs.apryse.com/core/info/modules/. If you have already")
50                Console.WriteLine("downloaded this module, ensure that the SDK is able to find the required files")
51                Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.")
52                Console.WriteLine()
53                Return
54            End If
55
56            Dim err As Boolean = False
57
58            '//////////////////////////////////////////////////////////////////////////
59            '// Word
60            '//////////////////////////////////////////////////////////////////////////
61
62            Try
63                ' Convert PDF document to Word
64                Console.WriteLine("Converting PDF to Word")
65
66                Dim outputFile As String = outputPath & "paragraphs_and_tables.docx"
67
68                pdftron.PDF.Convert.ToWord(inputPath & "paragraphs_and_tables.pdf", outputFile)
69
70                Console.WriteLine("Result saved in " & outputFile)
71            Catch e As PDFNetException
72                Console.WriteLine("Unable to convert PDF document to Word, error: " & e.Message)
73                err = True
74            Catch e As Exception
75                Console.WriteLine("Unknown Exception, error: ")
76                Console.WriteLine(e)
77                err = True
78            End Try
79
80            '//////////////////////////////////////////////////////////////////////////
81
82            Try
83                ' Convert PDF document to Word with options
84                Console.WriteLine("Converting PDF to Word with options")
85
86                Dim outputFile As String = outputPath & "paragraphs_and_tables_first_page.docx"
87
88                Dim wordOutputOptions As pdftron.PDF.Convert.WordOutputOptions = New pdftron.PDF.Convert.WordOutputOptions()
89
90                ' Convert only the first page
91                wordOutputOptions.SetPages(1, 1)
92
93                pdftron.PDF.Convert.ToWord(inputPath & "paragraphs_and_tables.pdf", outputFile, wordOutputOptions)
94
95                Console.WriteLine("Result saved in " & outputFile)
96            Catch e As PDFNetException
97                Console.WriteLine("Unable to convert PDF document to Word, error: " & e.Message)
98                err = True
99            Catch e As Exception
100                Console.WriteLine("Unknown Exception, error: ")
101                Console.WriteLine(e)
102                err = True
103            End Try
104
105            '//////////////////////////////////////////////////////////////////////////
106            '// Excel
107            '//////////////////////////////////////////////////////////////////////////
108
109            Try
110                ' Convert PDF document to Excel
111                Console.WriteLine("Converting PDF to Excel")
112
113                Dim outputFile As String = outputPath & "paragraphs_and_tables.xlsx"
114
115                pdftron.PDF.Convert.ToExcel(inputPath & "paragraphs_and_tables.pdf", outputFile)
116
117                Console.WriteLine("Result saved in " & outputFile)
118            Catch e As PDFNetException
119                Console.WriteLine("Unable to convert PDF document to Excel, error: " & e.Message)
120                err = True
121            Catch e As Exception
122                Console.WriteLine("Unknown Exception, error: ")
123                Console.WriteLine(e)
124                err = True
125            End Try
126
127            '//////////////////////////////////////////////////////////////////////////
128
129            Try
130                ' Convert PDF document to Excel with options
131                Console.WriteLine("Converting PDF to Excel with options")
132
133                Dim outputFile As String = outputPath & "paragraphs_and_tables_second_page.xlsx"
134
135                Dim excelOutputOptions As pdftron.PDF.Convert.ExcelOutputOptions = New pdftron.PDF.Convert.ExcelOutputOptions()
136
137                ' Convert only the second page
138                excelOutputOptions.SetPages(2, 2)
139
140                pdftron.PDF.Convert.ToExcel(inputPath & "paragraphs_and_tables.pdf", outputFile, excelOutputOptions)
141
142                Console.WriteLine("Result saved in " & outputFile)
143            Catch e As PDFNetException
144                Console.WriteLine("Unable to convert PDF document to Excel, error: " & e.Message)
145                err = True
146            Catch e As Exception
147                Console.WriteLine("Unknown Exception, error: ")
148                Console.WriteLine(e)
149                err = True
150            End Try
151
152            '//////////////////////////////////////////////////////////////////////////
153            '// PowerPoint
154            '//////////////////////////////////////////////////////////////////////////
155
156            Try
157                ' Convert PDF document to PowerPoint
158                Console.WriteLine("Converting PDF to PowerPoint")
159
160                Dim outputFile As String = outputPath & "paragraphs_and_tables.pptx"
161
162                pdftron.PDF.Convert.ToPowerPoint(inputPath & "paragraphs_and_tables.pdf", outputFile)
163
164                Console.WriteLine("Result saved in " & outputFile)
165            Catch e As PDFNetException
166                Console.WriteLine("Unable to convert PDF document to PowerPoint, error: " & e.Message)
167                err = True
168            Catch e As Exception
169                Console.WriteLine("Unknown Exception, error: ")
170                Console.WriteLine(e)
171                err = True
172            End Try
173
174            '//////////////////////////////////////////////////////////////////////////
175
176            Try
177                ' Convert PDF document to PowerPoint with options
178                Console.WriteLine("Converting PDF to PowerPoint with options")
179
180                Dim outputFile As String = outputPath & "paragraphs_and_tables_first_page.pptx"
181
182                Dim powerPointOutputOptions As pdftron.PDF.Convert.PowerPointOutputOptions = New pdftron.PDF.Convert.PowerPointOutputOptions()
183
184                ' Convert only the first page
185                powerPointOutputOptions.SetPages(1, 1)
186
187                pdftron.PDF.Convert.ToPowerPoint(inputPath & "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions)
188
189                Console.WriteLine("Result saved in " & outputFile)
190            Catch e As PDFNetException
191                Console.WriteLine("Unable to convert PDF document to PowerPoint, error: " & e.Message)
192                err = True
193            Catch e As Exception
194                Console.WriteLine("Unknown Exception, error: ")
195                Console.WriteLine(e)
196                err = True
197            End Try
198
199            '//////////////////////////////////////////////////////////////////////////
200
201            PDFNet.Terminate()
202            Console.WriteLine("Done.")
203        End Sub
204    End Class
205End Module
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales