Sample C# code for using Apryse SDK to convert Office documents to PDF (including Word, Excel, PowerPoint and Publisher) without needing any external dependencies or MS Office licenses. Office to PDF conversion can be performed on a Linux or Windows server to automate Office-centric workflows, or entirely in the user's client (web browser, mobile device). The conversion functionality can be combined with our Viewer to display or annotate Office files (docx, xlsx, pptx) on all major platforms, including Web, Android, iOS, Xamarin, UWP, and Windows. Learn more about our Server SDK and Office Document Conversion Library.
1//
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3//
4
5using System;
6using System.Drawing;
7using System.Drawing.Drawing2D;
8
9using pdftron;
10using pdftron.Common;
11using pdftron.Filters;
12using pdftron.SDF;
13using pdftron.PDF;
14
15namespace OfficeToPDFTestCS
16{
17 /// <summary>
18 ///---------------------------------------------------------------------------------------
19 /// The following sample illustrates how to use the PDF::Convert utility class to convert
20 /// .docx files to PDF
21 ///
22 /// This conversion is performed entirely within the PDFNet and has *no* external or
23 /// system dependencies dependencies
24 ///
25 /// Please contact us if you have any questions.
26 ///---------------------------------------------------------------------------------------
27 /// </summary>
28
29
30
31 class Class1
32 {
33 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
34 static Class1() {}
35
36 static String input_path = "../../../../TestFiles/";
37 static String output_path = "../../../../TestFiles/Output/";
38
39 static void SimpleConvert(String input_filename, String output_filename)
40 {
41 // Start with a PDFDoc (the conversion destination)
42 using (PDFDoc pdfdoc = new PDFDoc())
43 {
44 // perform the conversion with no optional parameters
45 pdftron.PDF.Convert.OfficeToPDF(pdfdoc, input_path + input_filename, null);
46
47 // save the result
48 pdfdoc.Save(output_path + output_filename, SDFDoc.SaveOptions.e_linearized);
49
50 // And we're done!
51 Console.WriteLine("Saved " + output_filename);
52 }
53 }
54
55 static void FlexibleConvert(String input_filename, String output_filename)
56 {
57 // Start with a PDFDoc (the conversion destination)
58 using (PDFDoc pdfdoc = new PDFDoc())
59 {
60 OfficeToPDFOptions options = new OfficeToPDFOptions();
61 options.SetSmartSubstitutionPluginPath(input_path);
62 // create a conversion object -- this sets things up but does not yet
63 // perform any conversion logic.
64 // in a multithreaded environment, this object can be used to monitor
65 // the conversion progress and potentially cancel it as well
66 DocumentConversion conversion = pdftron.PDF.Convert.StreamingPDFConversion(
67 pdfdoc, input_path + input_filename, options);
68
69 // actually perform the conversion
70 // this particular method will not throw on conversion failure, but will
71 // return an error status instead
72 if (conversion.TryConvert() == DocumentConversionResult.e_document_conversion_success)
73 {
74 int num_warnings = conversion.GetNumWarnings();
75
76 // print information about the conversion
77 for (int i = 0; i < num_warnings; ++i)
78 {
79 Console.WriteLine("Warning: " + conversion.GetWarningString(i));
80 }
81
82 // save the result
83 pdfdoc.Save(output_path + output_filename, SDFDoc.SaveOptions.e_linearized);
84 // done
85 Console.WriteLine("Saved " + output_filename);
86 }
87 else
88 {
89 Console.WriteLine("Encountered an error during conversion: " + conversion.GetErrorString());
90 }
91 }
92 }
93
94 /// <summary>
95 /// The main entry point for the application.
96 /// </summary>
97 static void Main(string[] args)
98 {
99 PDFNet.Initialize(PDFTronLicense.Key);
100
101 try
102 {
103 // first the one-line conversion method
104 SimpleConvert("Fishermen.docx", "Fishermen.pdf");
105
106 // then the more flexible line-by-line conversion API
107 FlexibleConvert("the_rime_of_the_ancient_mariner.docx", "the_rime_of_the_ancient_mariner.pdf");
108
109 // conversion of RTL content
110 FlexibleConvert("factsheet_Arabic.docx", "factsheet_Arabic.pdf");
111 }
112 catch (pdftron.Common.PDFNetException e)
113 {
114 Console.WriteLine(e.Message);
115 }
116 catch (Exception e)
117 {
118 Console.WriteLine("Unrecognized Exception: " + e.Message );
119 }
120
121 PDFNet.Terminate();
122 Console.WriteLine("Done.");
123 }
124 }
125}
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/OfficeToPDFOptions.h>
11#include "../../LicenseKey/CPP/LicenseKey.h"
12
13//------------------------------------------------------------------------------
14// The following sample illustrates how to use the PDF::Convert utility class
15// to convert MS Office files to PDF
16//
17// This conversion is performed entirely within the PDFNet and has *no*
18// external or system dependencies dependencies -- Conversion results will be
19// the same whether on Windows, Linux or Android.
20//
21// Please contact us if you have any questions.
22//------------------------------------------------------------------------------
23
24using namespace pdftron;
25using namespace PDF;
26
27UString input_path = "../../TestFiles/";
28UString output_path = "../../TestFiles/Output/";
29
30void SimpleDocxConvert(UString input_filename, UString output_filename)
31{
32 // Start with a PDFDoc (the conversion destination)
33 PDFDoc pdfdoc;
34
35 // perform the conversion with no optional parameters
36 Convert::OfficeToPDF(pdfdoc, input_path + input_filename, NULL);
37
38 // save the result
39 pdfdoc.Save(output_path + output_filename, SDF::SDFDoc::e_linearized, NULL);
40
41 // And we're done!
42 std::cout << "Saved " << output_filename << std::endl;
43}
44
45void FlexibleDocxConvert(UString input_filename, UString output_filename)
46{
47 // Start with a PDFDoc (the conversion destination)
48 PDFDoc pdfdoc;
49
50 OfficeToPDFOptions options;
51
52 // set up smart font substitutions to improve conversion results
53 // in situations where the original fonts are not available
54 options.SetSmartSubstitutionPluginPath(input_path);
55
56 // create a conversion object -- this sets things up but does not yet
57 // perform any conversion logic.
58 // in a multithreaded environment, this object can be used to monitor
59 // the conversion progress and potentially cancel it as well
60 DocumentConversion conversion = Convert::StreamingPDFConversion(
61 pdfdoc, input_path + input_filename, &options);
62
63 // Print the progress of the conversion.
64 /*
65 std::cout << "Status: " << conversion.GetProgress()*100 << "%, "
66 << conversion.GetProgressLabel() << std::endl;
67 */
68
69 // actually perform the conversion
70 // this particular method will not throw on conversion failure, but will
71 // return an error status instead
72
73 while (conversion.GetConversionStatus() == DocumentConversion::eIncomplete)
74 {
75 conversion.ConvertNextPage();
76 // print out the progress status as we go
77 /*
78 std::cout << "Status: " << conversion.GetProgress()*100 << "%, "
79 << conversion.GetProgressLabel() << std::endl;
80 */
81 }
82
83 if(conversion.GetConversionStatus() == DocumentConversion::eSuccess)
84 {
85 int num_warnings = conversion.GetNumWarnings();
86
87 // print information about the conversion
88 for (int i = 0; i < num_warnings; ++i)
89 {
90 std::cout << "Conversion Warning: "
91 << conversion.GetWarningString(i) << std::endl;
92 }
93
94 // save the result
95 pdfdoc.Save(output_path + output_filename, SDF::SDFDoc::e_linearized, NULL);
96 // done
97 std::cout << "Saved " << output_filename << std::endl;
98 }
99 else
100 {
101 std::cout << "Encountered an error during conversion: "
102 << conversion.GetErrorString() << std::endl;
103 }
104
105
106}
107
108
109int main(int argc, char *argv[])
110{
111 // The first step in every application using PDFNet is to initialize the
112 // library. The library is usually initialized only once, but calling
113 // Initialize() multiple times is also fine.
114 int ret = 0;
115
116 PDFNet::Initialize(LicenseKey);
117 PDFNet::SetResourcesPath("../../../Resources");
118
119 try
120 {
121 // first the one-line conversion function
122 SimpleDocxConvert("Fishermen.docx", "Fishermen.pdf");
123
124 // then the more flexible line-by-line conversion API
125 FlexibleDocxConvert("the_rime_of_the_ancient_mariner.docx",
126 "the_rime_of_the_ancient_mariner.pdf");
127
128 // conversion of RTL content
129 FlexibleDocxConvert("factsheet_Arabic.docx", "factsheet_Arabic.pdf");
130 }
131 catch (Common::Exception& e)
132 {
133 std::cout << e << std::endl;
134 ret = 1;
135 }
136 catch (...)
137 {
138 std::cout << "Unknown Exception" << std::endl;
139 ret = 1;
140 }
141
142 PDFNet::Terminate();
143 std::cout << "Done.\n";
144 return ret;
145}
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
16// to convert MS Office files to PDF
17//
18// This conversion is performed entirely within the PDFNet and has *no*
19// external or system dependencies dependencies -- Conversion results will be
20// the same whether on Windows, Linux or Android.
21//
22// Please contact us if you have any questions.
23//------------------------------------------------------------------------------
24
25// Relative path to the folder containing the test files.
26var inputPath = "../../TestFiles/"
27var outputPath = "../../TestFiles/Output/"
28
29func SimpleDocxConvert(inputFileName string, outputFileName string){
30 // Start with a PDFDoc (the conversion destination)
31 pdfdoc := NewPDFDoc()
32
33 // perform the conversion with no optional parameters
34 ConvertOfficeToPDF(pdfdoc, inputPath + inputFileName, NewConversionOptions())
35
36 // save the result
37 pdfdoc.Save(outputPath + outputFileName, uint(SDFDocE_linearized))
38
39 // And we're done!
40 fmt.Println("Saved " + outputFileName )
41}
42
43func FlexibleDocxConvert(inputFileName string , outputFileName string){
44 // Start with a PDFDoc (the conversion destination)
45 pdfdoc := NewPDFDoc()
46
47 options := NewOfficeToPDFOptions()
48
49 // set up smart font substitutions to improve conversion results
50 // in situations where the original fonts are not available
51 options.SetSmartSubstitutionPluginPath(inputPath)
52
53 // create a conversion object -- this sets things up but does not yet
54 // perform any conversion logic.
55 // in a multithreaded environment, this object can be used to monitor
56 // the conversion progress and potentially cancel it as well
57 conversion := ConvertStreamingPDFConversion(pdfdoc, inputPath + inputFileName, options)
58
59 // Print the progress of the conversion.
60 // print( "Status: " + str(conversion.GetProgress()*100) +"%, " +
61 // conversion.GetProgressLabel())
62
63 // actually perform the conversion
64 // this particular method will not throw on conversion failure, but will
65 // return an error status instead
66 for {
67 if (conversion.GetConversionStatus() != DocumentConversionEIncomplete){
68 break
69 }
70 conversion.ConvertNextPage()
71 // print out the progress status as we go
72 // print("Status: " + str(conversion.GetProgress()*100) + "%, " +
73 // conversion.GetProgressLabel() )
74 }
75
76 if(conversion.GetConversionStatus() == DocumentConversionESuccess){
77 numWarnings := conversion.GetNumWarnings()
78 // print information about the conversion
79 for i := uint(0); i < numWarnings; i++ {
80 fmt.Println("Conversion Warning: " + conversion.GetWarningString(i) )
81 i = i + 1
82 }
83 // save the result
84 pdfdoc.Save(outputPath + outputFileName, uint(SDFDocE_linearized))
85 // done
86 fmt.Println("Saved " + outputFileName )
87 }else{
88 fmt.Println("Encountered an error during conversion: " + conversion.GetErrorString() )
89 }
90}
91
92func main(){
93 // The first step in every application using PDFNet is to initialize the
94 // library. The library is usually initialized only once, but calling
95 // Initialize() multiple times is also fine.
96 PDFNetInitialize(PDFTronLicense.Key)
97 PDFNetSetResourcesPath("../../Resources")
98
99 // first the one-line conversion function
100 SimpleDocxConvert("simple-word_2007.docx", "simple-word_2007.pdf")
101
102 // then the more flexible line-by-line conversion API
103 FlexibleDocxConvert("the_rime_of_the_ancient_mariner.docx", "the_rime_of_the_ancient_mariner.pdf")
104 PDFNetTerminate()
105
106}
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.Convert;
8import com.pdftron.pdf.DocumentConversion;
9import com.pdftron.pdf.PDFDoc;
10import com.pdftron.pdf.PDFNet;
11import com.pdftron.pdf.OfficeToPDFOptions;
12import com.pdftron.sdf.SDFDoc;
13
14//---------------------------------------------------------------------------------------
15// The following sample illustrates how to use the PDF.Convert utility class to convert
16// MS Office files to PDF
17//
18// This conversion is performed entirely within the PDFNet and has *no* external or
19// system dependencies dependencies -- Conversion results will be the same whether
20// on Windows, Linux or Android.
21//
22// Please contact us if you have any questions.
23//---------------------------------------------------------------------------------------
24public class OfficeToPDFTest {
25
26 static String input_path = "../../TestFiles/";
27 static String output_path = "../../TestFiles/Output/";
28
29 public static void main(String[] args) {
30 PDFNet.initialize(PDFTronLicense.Key());
31 PDFNet.setResourcesPath("../../../Resources");
32
33 // first the one-line conversion interface
34 simpleDocxConvert("Fishermen.docx", "Fishermen.pdf");
35
36 // then the more flexible line-by-line interface
37 flexibleDocxConvert("the_rime_of_the_ancient_mariner.docx", "the_rime_of_the_ancient_mariner.pdf");
38
39 // conversion of RTL content
40 flexibleDocxConvert("factsheet_Arabic.docx", "factsheet_Arabic.pdf");
41
42 PDFNet.terminate();
43 }
44
45 public static void simpleDocxConvert(String inputFilename, String outputFilename) {
46 try (PDFDoc pdfdoc = new PDFDoc()) {
47
48 // perform the conversion with no optional parameters
49 Convert.officeToPdf(pdfdoc, input_path + inputFilename, null);
50
51 // save the result
52 pdfdoc.save(output_path + outputFilename, SDFDoc.SaveMode.INCREMENTAL, null);
53 // output PDF pdfdoc
54
55 // And we're done!
56 System.out.println("Done conversion " + output_path + outputFilename);
57 } catch (PDFNetException e) {
58 System.out.println("Unable to convert MS Office document, error:");
59 e.printStackTrace();
60 System.out.println(e);
61 }
62 }
63
64 public static void flexibleDocxConvert(String inputFilename, String outputFilename) {
65 try {
66 OfficeToPDFOptions options = new OfficeToPDFOptions();
67 options.setSmartSubstitutionPluginPath(input_path);
68
69 // create a conversion object -- this sets things up but does not yet
70 // perform any conversion logic.
71 // in a multithreaded environment, this object can be used to monitor
72 // the conversion progress and potentially cancel it as well
73 DocumentConversion conversion = Convert.streamingPdfConversion(
74 input_path + inputFilename, options);
75
76 System.out.println(inputFilename + ": " + Math.round(conversion.getProgress() * 100.0)
77 + "% " + conversion.getProgressLabel());
78
79 // actually perform the conversion
80 while (conversion.getConversionStatus() == DocumentConversion.e_incomplete) {
81 conversion.convertNextPage();
82 System.out.println(inputFilename + ": " + Math.round(conversion.getProgress() * 100.0)
83 + "% " + conversion.getProgressLabel());
84 }
85
86 if (conversion.tryConvert() == DocumentConversion.e_success) {
87 int num_warnings = conversion.getNumWarnings();
88
89 // print information about the conversion
90 for (int i = 0; i < num_warnings; ++i) {
91 System.out.println("Warning: " + conversion.getWarningString(i));
92 }
93
94 // save the result
95 try (PDFDoc doc = conversion.getDoc()) {
96 doc.save(output_path + outputFilename, SDFDoc.SaveMode.INCREMENTAL, null);
97 }
98
99 // done
100 System.out.println("Done conversion " + output_path + outputFilename);
101 } else {
102 System.out.println("Encountered an error during conversion: " + conversion.getErrorString());
103 }
104 } catch (PDFNetException e) {
105 System.out.println("Unable to convert MS Office document, error:");
106 e.printStackTrace();
107 System.out.println(e);
108 }
109 }
110
111}
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
8// to convert MS Office files to PDF
9//
10// This conversion is performed entirely within the PDFNet and has *no*
11// external or system dependencies dependencies -- Conversion results will be
12// the same whether on Windows, Linux or Android.
13//
14// Please contact us if you have any questions.
15//------------------------------------------------------------------------------
16
17const { PDFNet } = require('@pdftron/pdfnet-node');
18const PDFTronLicense = require('../LicenseKey/LicenseKey');
19
20((exports) => {
21 'use strict';
22
23 exports.runOfficeToPDF = () => {
24
25 const inputPath = '../TestFiles/';
26 const outputPath = inputPath + 'Output/';
27
28 const simpleDocxConvert = async (inputFilename, outputFilename) => {
29 // perform the conversion with no optional parameters
30 const pdfdoc = await PDFNet.Convert.officeToPdfWithPath(inputPath + inputFilename);
31
32 // save the result
33 await pdfdoc.save(outputPath + outputFilename, PDFNet.SDFDoc.SaveOptions.e_linearized);
34
35 // And we're done!
36 console.log('Saved ' + outputFilename);
37 }
38
39 const flexibleDocxConvert = async (inputFilename, outputFilename) => {
40 // Start with a PDFDoc (the conversion destination)
41 const pdfdoc = await PDFNet.PDFDoc.create();
42 pdfdoc.initSecurityHandler();
43
44 const options = new PDFNet.Convert.OfficeToPDFOptions();
45
46 // set up smart font substitutions to improve conversion results
47 // in situations where the original fonts are not available
48 options.setSmartSubstitutionPluginPath(inputPath);
49
50 // create a conversion object -- this sets things up but does not yet
51 // perform any conversion logic.
52 // in a multithreaded environment, this object can be used to monitor
53 // the conversion progress and potentially cancel it as well
54 const conversion = await PDFNet.Convert.streamingPdfConversionWithPdfAndPath(
55 pdfdoc, inputPath + inputFilename, options);
56
57 // Print the progress of the conversion.
58 /*
59 console.log('Status: ' + await conversion.getProgress() * 100 + '%, '
60 + await conversion.getProgressLabel());
61 */
62
63 // actually perform the conversion
64 // this particular method will not throw on conversion failure, but will
65 // return an error status instead
66
67 while (await conversion.getConversionStatus() === PDFNet.DocumentConversion.Result.e_Incomplete) {
68 await conversion.convertNextPage();
69 // print out the progress status as we go
70 /*
71 console.log('Status: ' + await conversion.getProgress() * 100 + '%, '
72 + await conversion.getProgressLabel());
73 */
74 }
75
76 if (await conversion.getConversionStatus() === PDFNet.DocumentConversion.Result.e_Success) {
77 const num_warnings = await conversion.getNumWarnings();
78
79 // print information about the conversion
80 for (let i = 0; i < num_warnings; ++i) {
81 console.log('Conversion Warning: ' + await conversion.getWarningString(i));
82 }
83
84 // save the result
85 await pdfdoc.save(outputPath + outputFilename, PDFNet.SDFDoc.SaveOptions.e_linearized);
86 // done
87 console.log('Saved ' + outputFilename);
88 }
89 else {
90 console.log('Encountered an error during conversion: '
91 + await conversion.getErrorString());
92 }
93 }
94
95
96 const main = async () => {
97
98 PDFNet.addResourceSearchPath('../Resources');
99
100 try {
101 // first the one-line conversion function
102 await simpleDocxConvert('Fishermen.docx', 'Fishermen.pdf');
103
104 // then the more flexible line-by-line conversion API
105 await flexibleDocxConvert('the_rime_of_the_ancient_mariner.docx',
106 'the_rime_of_the_ancient_mariner.pdf');
107
108 // conversion of RTL content
109 await flexibleDocxConvert('factsheet_Arabic.docx', 'factsheet_Arabic.pdf');
110 } catch (err) {
111 console.log(err);
112 }
113
114 console.log('Done.');
115 };
116
117 PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
118 console.log('Error: ' + JSON.stringify(error));
119 }).then(function () { return PDFNet.shutdown(); });
120
121 };
122 exports.runOfficeToPDF();
123})(exports);
124// eslint-disable-next-line spaced-comment
125//# sourceURL=OfficeToPDFTest.js
1<?php
2//------------------------------------------------------------------------------
3// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
4// Consult legal.txt regarding legal and license information.
5//------------------------------------------------------------------------------
6if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
7include("../../../PDFNetC/Lib/PDFNetPHP.php");
8include("../../LicenseKey/PHP/LicenseKey.php");
9
10// Relative path to the folder containing the test files.
11$input_path = getcwd()."/../../TestFiles/";
12$output_path = $input_path."Output/";
13
14//------------------------------------------------------------------------------
15// The following sample illustrates how to use the PDF::Convert utility class
16// to convert MS Office files to PDF
17//
18// This conversion is performed entirely within the PDFNet and has *no*
19// external or system dependencies dependencies -- Conversion results will be
20// the same whether on Windows, Linux or Android.
21//
22// Please contact us if you have any questions.
23//------------------------------------------------------------------------------
24
25
26function SimpleDocxConvert($input_filename, $output_filename)
27{
28 global $input_path, $output_path;
29
30 // Start with a PDFDoc (the conversion destination)
31 $pdfdoc = new PDFDoc();
32
33 // perform the conversion with no optional parameters
34 Convert::OfficeToPDF($pdfdoc, $input_path.$input_filename, NULL);
35
36 // save the result
37 $pdfdoc->Save($output_path.$output_filename, SDFDoc::e_linearized);
38
39 // And we're done!
40 echo nl2br("Saved ".$output_filename . "\n");
41}
42
43
44function FlexibleDocxConvert($input_filename, $output_filename)
45{
46 global $input_path, $output_path;
47
48 // Start with a PDFDoc (the conversion destination)
49 $pdfdoc = new PDFDoc();
50
51 $options = new OfficeToPDFOptions(); //ConversionOptions();
52
53 // set up smart font substitutions to improve conversion results
54 // in situations where the original fonts are not available
55 $options->SetSmartSubstitutionPluginPath($input_path);
56
57 // create a conversion object -- this sets things up but does not yet
58 // perform any conversion logic.
59 // in a multithreaded environment, this object can be used to monitor
60 // the conversion progress and potentially cancel it as well
61 $conversion = Convert::StreamingPDFConversion($pdfdoc, $input_path.$input_filename, $options);
62
63 // Print the progress of the conversion.
64 /*
65 echo "Status: "$conversion->GetProgress()*100 . "%, ".
66 $conversion->GetProgressLabel();
67 */
68
69 // actually perform the conversion
70 // this particular method will not throw on conversion failure, but will
71 // return an error status instead
72 while ($conversion->GetConversionStatus() == DocumentConversion::eIncomplete)
73 {
74 $conversion->ConvertNextPage();
75 // print out the progress status as we go
76 /*
77 echo (nl2br("Status: " . $conversion->GetProgress()*100 . "%, ".
78 $conversion->GetProgressLabel() ));
79 */
80 }
81
82 if($conversion->GetConversionStatus() == DocumentConversion::eSuccess)
83 {
84 $num_warnings = $conversion->GetNumWarnings();
85
86 // print information about the conversion
87 for ($i = 0; $i < $num_warnings; ++$i)
88 {
89 echo(nl2br("Conversion Warning: ".$conversion->GetWarningString($i) ));
90 }
91
92 // save the result
93 $pdfdoc->Save($output_path . $output_filename, SDFDoc::e_linearized);
94 // done
95 echo(nl2br("Saved " . $output_filename ."\n"));
96 }
97 else
98 {
99 echo(nl2br("Encountered an error during conversion: " . $conversion->GetErrorString() ));
100 }
101
102}
103
104
105
106
107function main()
108{
109 // The first step in every application using PDFNet is to initialize the
110 // library. The library is usually initialized only once, but calling
111 // Initialize() multiple times is also fine.
112
113 global $LicenseKey;
114 PDFNet::Initialize($LicenseKey);
115 PDFNet::SetResourcesPath("../../../Resources");
116
117 // first the one-line conversion function
118 SimpleDocxConvert("simple-word_2007.docx", "simple-word_2007.pdf");
119
120 // then the more flexible line-by-line conversion API
121 FlexibleDocxConvert("the_rime_of_the_ancient_mariner.docx", "the_rime_of_the_ancient_mariner.pdf");
122 PDFNet::Terminate();
123 echo(nl2br("Done.\n"));
124}
125
126main()
127
128?>
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
11sys.path.append("../../LicenseKey/PYTHON")
12from LicenseKey import *
13
14# Relative path to the folder containing the test files.
15input_path = "../../TestFiles/"
16output_path = "../../TestFiles/Output/"
17
18#------------------------------------------------------------------------------
19# The following sample illustrates how to use the PDF.Convert utility class
20# to convert MS Office files to PDF
21#
22# This conversion is performed entirely within the PDFNet and has *no*
23# external or system dependencies dependencies -- Conversion results will be
24# the same whether on Windows, Linux or Android.
25#
26# Please contact us if you have any questions.
27#------------------------------------------------------------------------------
28
29def SimpleDocxConvert(input_filename, output_filename):
30 # Start with a PDFDoc (the conversion destination)
31 pdfdoc = PDFDoc()
32
33 # perform the conversion with no optional parameters
34 Convert.OfficeToPDF(pdfdoc, input_path + input_filename, None)
35
36 # save the result
37 pdfdoc.Save(output_path + output_filename, SDFDoc.e_linearized)
38
39 # And we're done!
40 print("Saved " + output_filename )
41
42def FlexibleDocxConvert(input_filename, output_filename):
43 # Start with a PDFDoc (the conversion destination)
44 pdfdoc = PDFDoc()
45
46 options = OfficeToPDFOptions()
47
48 # set up smart font substitutions to improve conversion results
49 # in situations where the original fonts are not available
50 options.SetSmartSubstitutionPluginPath(input_path)
51
52 # create a conversion object -- this sets things up but does not yet
53 # perform any conversion logic.
54 # in a multithreaded environment, this object can be used to monitor
55 # the conversion progress and potentially cancel it as well
56 conversion = Convert.StreamingPDFConversion(pdfdoc, input_path + input_filename, options)
57
58 # Print the progress of the conversion.
59 # print( "Status: " + str(conversion.GetProgress()*100) +"%, " +
60 # conversion.GetProgressLabel())
61
62 # actually perform the conversion
63 # this particular method will not throw on conversion failure, but will
64 # return an error status instead
65 while (conversion.GetConversionStatus() == DocumentConversion.eIncomplete):
66 conversion.ConvertNextPage()
67 # print out the progress status as we go
68 # print("Status: " + str(conversion.GetProgress()*100) + "%, " +
69 # conversion.GetProgressLabel() )
70
71 if(conversion.GetConversionStatus() == DocumentConversion.eSuccess):
72 num_warnings = conversion.GetNumWarnings()
73 # print information about the conversion
74 i = 0
75 for i in range(num_warnings):
76 print("Conversion Warning: " + conversion.GetWarningString(i) )
77 i = i + 1
78
79 # save the result
80 pdfdoc.Save(output_path + output_filename, SDFDoc.e_linearized)
81 # done
82 print("Saved " + output_filename )
83 else:
84 print("Encountered an error during conversion: " + conversion.GetErrorString() )
85
86def main():
87 # The first step in every application using PDFNet is to initialize the
88 # library. The library is usually initialized only once, but calling
89 # Initialize() multiple times is also fine.
90 PDFNet.Initialize(LicenseKey)
91 PDFNet.SetResourcesPath("../../../Resources")
92
93 # first the one-line conversion function
94 SimpleDocxConvert("simple-word_2007.docx", "simple-word_2007.pdf")
95
96 # then the more flexible line-by-line conversion API
97 FlexibleDocxConvert("the_rime_of_the_ancient_mariner.docx", "the_rime_of_the_ancient_mariner.pdf")
98 PDFNet.Terminate()
99
100 print("Done.")
101
102if __name__ == '__main__':
103 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
14# to convert MS Office files to PDF
15#
16# This conversion is performed entirely within the PDFNet and has *no*
17# external or system dependencies dependencies -- Conversion results will be
18# the same whether on Windows, Linux or Android.
19#
20# Please contact us if you have any questions.
21#------------------------------------------------------------------------------
22
23# Relative path to the folder containing the test files.
24$inputPath = "../../TestFiles/"
25$outputPath = "../../TestFiles/Output/"
26
27def SimpleDocxConvert(input_filename, output_filename)
28 # Start with a PDFDoc (the conversion destination)
29 pdfdoc = PDFDoc.new()
30
31 # perform the conversion with no optional parameters
32 inputFile = $inputPath + input_filename
33 Convert.OfficeToPDF(pdfdoc, inputFile, nil)
34
35 # save the result
36 outputFile = $outputPath + output_filename
37 pdfdoc.Save(outputFile, SDFDoc::E_linearized)
38
39 # And we're done!
40 puts "Saved " + output_filename
41end
42
43def FlexibleDocxConvert(input_filename, output_filename)
44 # Start with a PDFDoc (the conversion destination)
45 pdfdoc = PDFDoc.new()
46
47 options = OfficeToPDFOptions.new()
48
49 # set up smart font substitutions to improve conversion results
50 # in situations where the original fonts are not available
51 inputFile = $inputPath
52 options.SetSmartSubstitutionPluginPath(inputFile)
53
54 # create a conversion object -- this sets things up but does not yet
55 # perform any conversion logic.
56 # in a multithreaded environment, this object can be used to monitor
57 # the conversion progress and potentially cancel it as well
58 inputFile = $inputPath + input_filename
59 conversion = Convert.StreamingPDFConversion(pdfdoc, inputFile, options)
60
61 # Print the progress of the conversion.
62 # puts "Status " + (conversion.GetProgress()*100).to_s + "%, " +
63 # conversion.GetProgressLabel()
64
65 # actually perform the conversion
66 # this particular method will not throw on conversion failure, but will
67 # return an error status instead
68 while (conversion.GetConversionStatus() == DocumentConversion::EIncomplete)
69 conversion.ConvertNextPage()
70 # print out the progress status as we go
71 # puts "Status " + (conversion.GetProgress()*100).to_s + "%, " +
72 # conversion.GetProgressLabel()
73 end
74
75 if(conversion.GetConversionStatus() == DocumentConversion::ESuccess)
76 num_warnings = conversion.GetNumWarnings()
77 # print information about the conversion
78 for i in 0..num_warnings-1
79 puts "Conversion Warning " + conversion.GetWarningString(i)
80 end
81
82 # save the result
83 outputFile = $outputPath + output_filename
84 pdfdoc.Save(outputFile, SDFDoc::E_linearized)
85 # done
86 puts "Saved " + output_filename
87 else
88 puts "Encountered an error during conversion " + conversion.GetErrorString()
89 end
90
91end
92
93
94def main()
95 # The first step in every application using PDFNet is to initialize the
96 # library. The library is usually initialized only once, but calling
97 # Initialize() multiple times is also fine.
98 PDFNet.Initialize(PDFTronLicense.Key)
99 PDFNet.SetResourcesPath("../../../Resources")
100
101 # first the one-line conversion function
102 SimpleDocxConvert("simple-word_2007.docx", "simple-word_2007.pdf")
103
104 # then the more flexible line-by-line conversion API
105 FlexibleDocxConvert("the_rime_of_the_ancient_mariner.docx", "the_rime_of_the_ancient_mariner.pdf")
106 PDFNet.Terminate
107 puts "Done."
108end
109
110main()
1'
2' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3'
4
5Imports System
6
7Imports pdftron
8Imports pdftron.Common
9Imports pdftron.Filters
10Imports pdftron.SDF
11Imports pdftron.PDF
12
13
14' The following sample illustrates how to use the PDF::Convert utility class to convert
15' .docx files to PDF
16'
17' This conversion is performed entirely within the PDFNet and has *no* external or
18' system dependencies dependencies
19'
20' Please contact us if you have any questions.
21Module OfficeToPDFTestVB
22 Dim pdfNetLoader As PDFNetLoader
23 Sub New()
24 pdfNetLoader = pdftron.PDFNetLoader.Instance()
25 End Sub
26
27 ' Relative path to the folder containing test files.
28 Dim input_path As String = "../../../../TestFiles/"
29 Dim output_path As String = "../../../../TestFiles/Output/"
30
31 Private Sub SimpleConvert(ByVal input_filename As String, ByVal output_filename As String)
32 ' Start with a PDFDoc (the conversion destination)
33 Using pdfdoc As PDFDoc = New PDFDoc
34
35 ' perform the conversion with no optional parameters
36 pdftron.PDF.Convert.OfficeToPDF(pdfdoc, input_path + input_filename, Nothing)
37
38 ' save the result
39 pdfdoc.Save(output_path + output_filename, SDFDoc.SaveOptions.e_linearized)
40
41 ' And we're done!
42 Console.WriteLine("Saved " + (output_path + output_filename))
43 End Using
44 End Sub
45
46 Private Sub FlexibleConvert(ByVal input_filename As String, ByVal output_filename As String)
47 ' Start with a PDFDoc (the conversion destination)
48 Using pdfdoc As PDFDoc = New PDFDoc
49 Dim options As OfficeToPDFOptions = New OfficeToPDFOptions
50 options.SetResourceDocPath("SomePath")
51 ' perform the conversion with no optional parameters
52 Using conversion As DocumentConversion = pdftron.PDF.Convert.StreamingPDFConversion(pdfdoc, input_path + input_filename, options)
53
54 If conversion.TryConvert() = DocumentConversionResult.e_document_conversion_success Then
55 Dim num_warnings As Integer = conversion.GetNumWarnings()
56 For i As Integer = 0 To num_warnings - 1
57 Console.WriteLine("Warning: " + conversion.GetWarningString(i))
58 Next i
59
60 ' save the result
61 pdfdoc.Save(output_path + output_filename, SDFDoc.SaveOptions.e_linearized)
62
63 ' And we're done!
64 Console.WriteLine("Saved " + (output_path + output_filename))
65 Else
66 Console.WriteLine("Error: " + conversion.GetErrorString())
67 End If
68 End Using
69 End Using
70 End Sub
71
72
73
74 Sub Main()
75
76 PDFNet.Initialize(PDFTronLicense.Key)
77
78 Try
79 ' first the one-line conversion method
80 SimpleConvert("Fishermen.docx", "Fishermen.pdf")
81
82 ' Then the more flexible conversion process
83 FlexibleConvert("simple-word_2007.docx", "simple-word_2007_b.pdf")
84
85 ' conversion of RTL content
86 FlexibleConvert("factsheet_Arabic.docx", "factsheet_Arabic.pdf")
87
88 Catch ex As PDFNetException
89
90 Console.WriteLine(ex.Message)
91
92 Catch ex As Exception
93
94 MsgBox(ex.Message)
95
96 End Try
97
98 PDFNet.Terminate()
99
100 End Sub
101
102End Module
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales