For the complete documentation index, see llms.txt. This page is also available as Markdown.
ConversionOffice

Office to PDF Sample Code

Requirements

These packages are required to use these features in production. Trial keys have unlimited access to all features

Web SDKPackage: Office ConversionLive demo

Sample JavaScript 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.

Implementation steps

To convert Office files to PDF with WebViewer:

Step 1: Follow get started in your preferred web stack for WebViewer. Step 2: Add the sample code provided in this guide.

//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

(exports => {


  const Core = exports.Core;
  const PDFNet = Core.PDFNet;
  const convertOfficeToPDF = (inputUrl, outputName, l) =>
    Core.officeToPDFBuffer(inputUrl, { l }).then(buffer => {
      saveBufferAsPDFDoc(buffer, outputName);
      console.log(`Finished downloading ${outputName}`);
    });

  exports.runOfficeToPDF = (fileName, type) => {
    const inputDir = '../../files/';

    PDFNet.initialize()
      .then(() => convertOfficeToPDF(inputDir + fileName, `converted_${type}.pdf`))
      .then(() => {
        console.log('Test Complete!');
      })
      .catch(err => {
        console.log('An error was encountered! :(', err);
      });
  };
})(window);
// eslint-disable-next-line spaced-comment
//# sourceURL=OfficeToPDFTest.js