Requirements These packages are required to use these features in production. Trial keys have unlimited access to all features.
 View DemoTo convert an MS Office file to a PDF document without any external third party dependencies.
C# C++ Go Java JavaScript Obj-C PHP Python Ruby VB 
1 // Start with a PDFDoc (the conversion destination) 
2 PDFDoc  doc  = new  PDFDoc (); 
3 
4 // perform the conversion with no optional parameters 
5 Convert. OfficeToPDF (doc, filename,  null ); 
1 // Start with a PDFDoc (the conversion destination) 
2 PDFDoc doc; 
3 
4 // perform the conversion with no optional parameters 
5 Convert :: OfficeToPDF (doc, filename,  NULL ); 
1 // Start with a PDFDoc (the conversion destination) 
2 doc  :=  NewPDFDoc () 
3 
4 // perform the conversion with no optional parameters 
5 ConvertOfficeToPDF (doc, filename,  NewConversionOptions ()) 
1 // Start with a PDFDoc (the conversion destination) 
2 PDFDoc  doc  =  new  PDFDoc (); 
3 
4 // perform the conversion with no optional parameters 
5 Convert. officeToPdf (doc, filename,  null ); 
1 const  { PDFNet }  =  require ( ' @pdftron/pdfnet-node ' ); 
2 
3 async function  main () { 
4   // perform the conversion with no optional parameters 
5   const  buf  = await  PDFNet.Convert. office2PDFBuffer (filename); 
6 
7   // end with a PDFDoc (the conversion destination) 
8   const  doc  = await  PDFNet.PDFDoc. createFromBuffer (buf); 
9 } 
10 
11 PDFNet. runWithCleanup (main,  ' YOUR_LICENSE_KEY ' ); 
1 // Start with a PDFDoc (the conversion destination) 
2 PTPDFDoc *  doc  =  [[PTPDFDoc  alloc ]  init ]; 
3 
4 // perform the conversion with no optional parameters 
5 [PTConvert  OfficeToPDF :doc  in_filename :filename  options : Nil ]; 
1 // Start with a PDFDoc (the conversion destination) 
2 $doc  = new  PDFDoc (); 
3 
4 // perform the conversion with no optional parameters 
5 Convert :: OfficeToPDF ($doc, $filename,  NULL ); 
1 # Start with a PDFDoc (the conversion destination) 
2 doc  =  PDFDoc() 
3 
4 # perform the conversion with no optional parameters 
5 Convert.OfficeToPDF(doc, filename,  None ) 
1 # Start with a PDFDoc (the conversion destination) 
2 doc =  PDFDoc . new () 
3 
4 # perform the conversion with no optional parameters 
5 Convert . OfficeToPDF (doc, filename,  nil ) 
1 ' Start with a PDFDoc (the conversion destination) 
2 Dim  doc  As  PDFDoc  = New  PDFDoc 
3 
4 ' perform the conversion with no optional parameters 
5 Convert . OfficeToPDF (doc, filename,  Nothing ) 
Convert MS Office files to PDF - Full Sample  Full sample code which illustrates how to convert MS Office files (Word, Excel, PowerPoint) to PDF. Samples available in Python, C# (.Net), C++, Go, Java, Node.js (JavaScript), PHP, Ruby, VB.
The converter will attempt to make use of any fonts installed on the system. Fonts (or alternatives) can also be provided as described below.
C# C++ Go Java JavaScript Obj-C PHP Python Ruby VB 
1 PDFNet. Initialize (); 
2 
3 // if fonts.json is at /home/user/webfonts/fonts.json 
4 // this can also be an https URL 
5 WebFontDownloader. SetCustomWebFontURL ( " file:///home/user/webfonts/ " ); 
6 
7 // allow PDFNet to access the network to download missing fonts when possible. 
8 WebFontDownloader. EnableDownloads (); 
1 PDFNet :: Initialize (); 
2 
3 // if fonts.json is at /home/user/webfonts/fonts.json 
4 // this can also be an https URL 
5 WebFontDownloader :: SetCustomWebFontURL ( " file:///home/user/webfonts/ " ); 
6 
7 // allow PDFNet to access the network to download missing fonts when possible. 
8 WebFontDownloader :: EnableDownloads (); 
1 PDFNetInitialize () 
2 
3 // if fonts.json is at /home/user/webfonts/fonts.json 
4 // this can also be an https URL 
5 WebFontDownloaderSetCustomWebFontURL ( " file:///home/user/webfonts/ " ) 
6 
7 // allow PDFNet to access the network to download missing fonts when possible. 
8 WebFontDownloaderEnableDownloads () 
1 PDFNet. initialize (); 
2 
3 // if fonts.json is at /home/user/webfonts/fonts.json 
4 // this can also be an https URL 
5 WebFontDownloader. setCustomWebFontURL ( " file:///home/user/webfonts/ " ); 
6 
7 // allow PDFNet to access the network to download missing fonts when possible. 
8 WebFontDownloader. enableDownloads (); 
1 const  { PDFNet }  =  require ( ' @pdftron/pdfnet-node ' ); 
2 
3 const  main  = async  ()  =>  { 
4   // if fonts.json is at /home/user/webfonts/fonts.json 
5   // this can also be an https URL 
6   WebFontDownloader. setCustomWebFontURL ( " file:///home/user/webfonts/ " ); 
7 
8   // allow PDFNet to access the network to download missing fonts when possible. 
9   WebFontDownloader. enableDownloads (); 
10 } 
11 
12 PDFNet. runWithCleanup (main,  ' YOUR_LICENSE_KEY ' ). then ( function (){ PDFNet. shutdown (); }); 
1 [PTPDFNet  Initialize ]; 
2 
3 // if fonts.json is at /home/user/webfonts/fonts.json 
4 // this can also be an https URL 
5 [PTWebFontDownloader  SetCustomWebFontURL : @" file:///home/user/webfonts/ " ]; 
6 
7 // allow PDFNet to access the network to download missing fonts when possible. 
8 [PTWebFontDownloader  EnableDownloads ]; 
1 PDFNet :: Initialize (); 
2 
3 // if fonts.json is at /home/user/webfonts/fonts.json 
4 // this can also be an https URL 
5 WebFontDownloader :: SetCustomWebFontURL ( " file:///home/user/webfonts/ " ); 
6 
7 // allow PDFNet to access the network to download missing fonts when possible. 
8 WebFontDownloader :: EnableDownloads (); 
1 PDFNet.Initialize() 
2 
3 # if fonts.json is at /home/user/webfonts/fonts.json 
4 # this can also be an https URL 
5 WebFontDownloader.SetCustomWebFontURL( " file:///home/user/webfonts/ " ) 
6 
7 # allow PDFNet to access the network to download missing fonts when possible. 
8 WebFontDownloader.EnableDownloads() 
1 PDFNet . Initialize () 
2 
3 # if fonts.json is at /home/user/webfonts/fonts.json 
4 # this can also be an https URL 
5 WebFontDownloader . SetCustomWebFontURL ( " file:///home/user/webfonts/ " ) 
6 
7 # allow PDFNet to access the network to download missing fonts when possible. 
8 WebFontDownloader . EnableDownloads () 
1 PDFNet. Initialize () 
2 
3 ' if fonts.json is at /home/user/webfonts/fonts.json 
4 ' this can also be an https URL 
5 WebFontDownloader. SetCustomWebFontURL ( " file:///home/user/webfonts/ " ) 
6 
7 ' allow PDFNet to access the network to download missing fonts when possible. 
8 WebFontDownloader. EnableDownloads () 
Self serving substitute fonts faq  A more detailed faq guide about creating substitute web fonts set when a font is not embedded in the document or available on the system.
Self serve font package  A curated package of fonts with great coverage of widely used font files. Simply extract and pass the path to the API above.
The converter can produce good results with no user-supplied fonts at all, but for the highest conversion quality, fonts can be provided in a .docx resource document. This document must be named pdftron_convert_resources.docx and can reside in either in the resource directory (use PDFNet.AddResourceSearchPath() to set this value), or at some arbitrary location, specified in the conversion options (set via OfficeToPDFOptions.SetResourceDocPath()). The file should have all the required fonts embedded within it (you can create a file like this by checking the "embed fonts in the file" option from the "Save" preferences within Word )
If no appropriate fonts are found on the system or in a resource .docx, then the converter will need to use it's own fallback font data. On desktop/server, this data is built into the library and will be automatically used. On mobile, the data is not part of the binary, but is included in the SDK package as a separate resource file: pdftron_layout_resources.plugin. This file can either be placed in the resource directory (set via PDFNet.AddResourceSearchPath()), or in some arbitrary location, specified in the conversion options.
When the conversion routine is able to find a matching font, it will embed that font in the resulting PDF. Otherwise, the converter will attempt to embed one of the PDF base 14 fonts if there is a close enough match, and failing that, will not embed the font at all.
Using pdftron-supplied smart substitution data, the conversion routine can produce PDF documents with fully embedded fonts that are a close match to the originals. To enable this option, either place the file pdftron_smart_substitution.plugin (included in the SDK download) in the resource directory (set via PDFNet.AddResourceSearchPath()), or specify it's path directly in the conversion options.
C# C++ Go Java JavaScript Obj-C PHP Python Ruby VB 
1 // Start with a PDFDoc (the conversion destination) 
2 using  ( PDFDoc  pdfdoc  = new  PDFDoc ()) 
3 { 
4   OfficeToPDFOptions  options  = new  OfficeToPDFOptions (); 
5   options. SetSmartSubstitutionPluginPath (input_path); 
6   // create a conversion object -- this sets things up but does not yet 
7   // perform any conversion logic. 
8   // in a multithreaded environment, this object can be used to monitor 
9   // the conversion progress and potentially cancel it as well 
10   DocumentConversion  conversion  =  pdftron.PDF.Convert. StreamingPDFConversion (pdfdoc, input_path  +  input_filename, options); 
11 
12   // actually perform the conversion 
13   // this particular method will not throw on conversion failure, but will 
14   // return an error status instead 
15   if  (conversion. TryConvert ()  ==  DocumentConversionResult.e_document_conversion_success) 
16   { 
17     // save the result 
18     pdfdoc. Save (output_path  +  output_filename, SDFDoc.SaveOptions.e_linearized); 
19   } 
20 } 
1 // Start with a PDFDoc (the conversion destination) 
2 PDFDoc pdfdoc; 
3 OfficeToPDFOptions options; 
4 
5 // set up smart font substitutions to improve conversion results 
6 // in situations where the original fonts are not available 
7 options. SetSmartSubstitutionPluginPath (input_path); 
8 
9 // create a conversion object -- this sets things up but does not yet 
10 // perform any conversion logic. 
11 // in a multithreaded environment, this object can be used to monitor 
12 // the conversion progress and potentially cancel it as well 
13 DocumentConversion conversion  =  Convert :: StreamingPDFConversion (pdfdoc, input_path  +  input_filename,  & options); 
14 
15 // actually perform the conversion 
16 // this particular method will not throw on conversion failure, but will 
17 // return an error status instead 
18 while  (conversion. GetConversionStatus ()  ==  DocumentConversion :: eIncomplete) 
19 { 
20   conversion. ConvertNextPage (); 
21 } 
22 if (conversion. GetConversionStatus ()  ==  DocumentConversion :: eSuccess) 
23 { 
24   // save the result 
25   pdfdoc. Save (output_path  +  output_filename, SDF :: SDFDoc :: e_linearized,  NULL ); 
26 } 
1 // Start with a PDFDoc (the conversion destination) 
2 doc  :=  NewPDFDoc () 
3 options  :=   NewOfficeToPDFOptions ()  
4 
5 // set up smart font substitutions to improve conversion results 
6 // in situations where the original fonts are not available 
7 options. SetSmartSubstitutionPluginPath (inputPath) 
8 
9 // create a conversion object -- this sets things up but does not yet 
10 // perform any conversion logic. 
11 // in a multithreaded environment, this object can be used to monitor 
12 // the conversion progress and potentially cancel it as well 
13 conversion  :=  ConvertStreamingPDFConversion (pdfdoc, inputPath  +  inputFileName, options) 
14 
15 // actually perform the conversion 
16 // this particular method will not throw on conversion failure, but will 
17 // return an error status instead 
18 for  { 
19   if  (conversion. GetConversionStatus ()  !=  DocumentConversionEIncomplete){ 
20     break 
21   } 
22   conversion. ConvertNextPage () 
23 } 
24 if (conversion. GetConversionStatus ()  ==  DocumentConversionESuccess) { 
25   // save the result 
26   pdfdoc. Save (outputPath  +  outputFileName,  uint (SDFDocE_linearized)) 
27 } 
1 OfficeToPDFOptions  options  =  new  OfficeToPDFOptions (); 
2 options. setSmartSubstitutionPluginPath (input_path); 
3 
4 // create a conversion object -- this sets things up but does not yet 
5 // perform any conversion logic. 
6 // in a multithreaded environment, this object can be used to monitor 
7 // the conversion progress and potentially cancel it as well 
8 DocumentConversion  conversion  =  Convert. streamingPdfConversion (input_path  +  inputFilename, options); 
9 
10 // actually perform the conversion 
11 while  (conversion. getConversionStatus ()  ==  DocumentConversion.e_incomplete) { 
12   conversion. convertNextPage (); 
13 } 
14 
15 if  (conversion. tryConvert ()  ==  DocumentConversion.e_success) { 
16   // save the result 
17   PDFDoc  doc  =  conversion. getDoc (); 
18   doc. save (output_path  +  outputFilename, SDFDoc.SaveMode.LINEARIZED,  null ); 
19 } 
1 const  { PDFNet }  =  require ( ' @pdftron/pdfnet-node ' ); 
2 
3 const  main  = async  ()  =>  { 
4   const  options  =  new  PDFNet.Convert. OfficeToPDFOptions (); 
5   options. setSmartSubstitutionPluginPath (input_path); 
6 
7   // create a conversion object -- this sets things up but does not yet 
8   // perform any conversion logic. 
9   const  conversion  = await  PDFNet.Convert. streamingPdfConversionWithPath (input_path  +  inputFilename, options); 
10 
11   // actually perform the conversion 
12   while  (conversion. getConversionStatus ()  ==  PDFNet.DocumentConversion.e_Incomplete) { 
13     conversion. convertNextPage (); 
14   } 
15   if  (conversion. getConversionStatus ()  ==  PDFNet.DocumentConversion.e_Success) { 
16     // save the result 
17     const  doc  = await  conversion. getDoc (); 
18     doc. save (output_path  +  outputFilename, PDFNet.SDFDoc.SaveOptions.e_linearized); 
19   } 
20 } 
21 
22 PDFNet. runWithCleanup (main,  ' YOUR_LICENSE_KEY ' ). then ( function (){ PDFNet. shutdown (); }); 
1 // Start with a PDFDoc (the conversion destination) 
2 PTPDFDoc *  pdfDoc  =  [[PTPDFDoc  alloc ]  init ]; 
3 
4 PTOfficeToPDFOptions *  options  =  [[PTOfficeToPDFOptions  alloc ]  init ]; 
5 [options  SetSmartSubstitutionPluginPath :input_path]; 
6 
7 // create a conversion object with optional parameters 
8 PTDocumentConversion *  conversion  =  [PTConvert  StreamingPDFConversionWithDoc : pdfDoc  in_filename :[ NSString  stringWithFormat : @" %@ / %@ " , input_path, input_filename  options :options]; 
9 
10 // convert each page, and report progress 
11 while ([conversion  GetConversionStatus ]  ==  e_ptIncomplete) 
12 { 
13   [conversion  ConvertNextPage ]; 
14 } 
15 if  ([conversion  TryConvert ]  ==  e_ptSuccess) 
16 { 
17   //save the result  
18   [pdfDoc  SaveToFile : [ NSString  stringWithFormat : @" %@ / %@ " , output_path, output_filename]  flags : e_ptlinearized]; 
19 } 
1 // Start with a PDFDoc (the conversion destination) 
2 $pdfdoc  = new  PDFDoc (); 
3 $options  = new  OfficeToPDFOptions ();  //ConversionOptions(); 
4 
5 // set up smart font substitutions to improve conversion results 
6 // in situations where the original fonts are not available 
7 $options -> SetSmartSubstitutionPluginPath ($input_path); 
8 
9 // create a conversion object -- this sets things up but does not yet 
10 // perform any conversion logic. 
11 // in a multithreaded environment, this object can be used to monitor 
12 // the conversion progress and potentially cancel it as well 
13 $conversion  =  Convert :: StreamingPDFConversion ($pdfdoc, $input_path . $input_filename, $options); 
14 
15 // actually perform the conversion 
16 // this particular method will not throw on conversion failure, but will 
17 // return an error status instead 
18 while  ($conversion -> GetConversionStatus ()  ==  DocumentConversion :: eIncomplete ) 
19 { 
20   $conversion -> ConvertNextPage (); 
21 } 
22 if ($conversion -> GetConversionStatus ()  ==  DocumentConversion :: eSuccess ) 
23 { 
24   // save the result 
25   $pdfdoc -> Save ($output_path  .  $output_filename,  SDFDoc :: e_linearized ,  NULL ); 
26 } 
1 # Start with a PDFDoc (the conversion destination) 
2 pdfdoc  =   PDFDoc() 
3 options  =   OfficeToPDFOptions()  
4 
5 # set up smart font substitutions to improve conversion results 
6 # in situations where the original fonts are not available 
7 options.SetSmartSubstitutionPluginPath(input_path) 
8 
9 # create a conversion object -- this sets things up but does not yet 
10 # perform any conversion logic. 
11 # in a multithreaded environment, this object can be used to monitor 
12 # the conversion progress and potentially cancel it as well 
13 conversion  =  Convert.StreamingPDFConversion(pdfdoc, input_path  +  input_filename, options) 
14 
15 # actually perform the conversion 
16 # this particular method will not throw on conversion failure, but will 
17 # return an error status instead 
18 while  (conversion.GetConversionStatus()  ==  DocumentConversion.eIncomplete): 
19   conversion.ConvertNextPage() 
20 
21 if (conversion.GetConversionStatus()  ==  DocumentConversion.eSuccess): 
22   # save the result 
23   pdfdoc.Save(output_path  +  output_filename, SDFDoc.e_linearized) 
1 # Start with a PDFDoc (the conversion destination) 
2 pdfdoc =  PDFDoc . new () 
3 options =  OfficeToPDFOptions . new ()  
4 
5 # set up smart font substitutions to improve conversion results 
6 # in situations where the original fonts are not available 
7 inputFile = $inputPath  
8 options. SetSmartSubstitutionPluginPath (inputFile) 
9 
10 # create a conversion object -- this sets things up but does not yet 
11 # perform any conversion logic. 
12 # in a multithreaded environment, this object can be used to monitor 
13 # the conversion progress and potentially cancel it as well 
14 inputFile = $inputPath  +  input_filename 
15 conversion =  Convert . StreamingPDFConversion (pdfdoc, inputFile, options) 
16 
17 # actually perform the conversion 
18 # this particular method will not throw on conversion failure, but will 
19 # return an error status instead 
20 while  (conversion. GetConversionStatus ()  ==  DocumentConversion :: EIncomplete ) 
21   conversion. ConvertNextPage () 
22 end 
23 
24 if (conversion. GetConversionStatus ()  ==  DocumentConversion :: ESuccess ) 
25   # save the result 
26   outputFile = $outputPath  +  output_filename 
27   pdfdoc. Save (outputFile,  SDFDoc :: E_linearized ) 
28 end 
1 Using pdfdoc  As  PDFDoc  = New  PDFDoc 
2   Dim  options  As  OfficeToPDFOptions  = New  OfficeToPDFOptions 
3 
4   ' set up smart font substitutions to improve conversion results 
5   ' in situations where the original fonts are not available 
6   options. SetSmartSubstitutionPluginPath (input_path) 
7 
8   ' # create a conversion object -- this sets things up but does not yet 
9   ' perform any conversion logic. 
10   ' in a multithreaded environment, this object can be used to monitor 
11   ' the conversion progress and potentially cancel it as well 
12   Using conversion  As  DocumentConversion  =  pdftron.PDF. Convert . StreamingPDFConversion (pdfdoc, input_path  +  input_filename, options) 
13 
14     ' actually perform the conversion 
15     ' this particular method will not throw on conversion failure, but will 
16     ' return an error status instead 
17     While  conversion. GetConversionStatus ()  =  DocumentConversionResult.e_document_conversion_incomplete 
18       conversion. ConvertNextPage () 
19     End  While 
20 
21     If  conversion. TryConvert ()  =  DocumentConversionResult.e_document_conversion_success  Then 
22       ' save the result 
23       pdfdoc. Save (output_path  +  output_filename, SDFDoc.SaveOptions.e_linearized) 
24     End If 
25   End  Using 
26 End  Using