Some test text!

< Web samples

Convert Office Documents (Excel, Word, PowerPoint) to PDF using Javascript

Sample Javascript code for using PDFTron 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 Office Document Conversion Library.

Step 1: Get your free trial license key, or sign in

Start Trial
Sign in

Step 2: Add the code:

// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.

((exports) => {
  'use strict';

  const convertOfficeToPDF = (inputUrl, outputName, l) => PDFNet.Convert.office2PDFBuffer(inputUrl, { l: l }).then((buffer) => {
    saveBufferAsPDFDoc(buffer, outputName);
    console.log('Finished downloading ' + outputName);

  exports.runOfficeToPDF = () => {
    const inputDir = '../TestFiles/';
    const docxFilename = 'simple-word_2007.docx';
    const pptxFilename = 'simple-powerpoint_2007.pptx';
    const xlsxFilename = 'simple-excel_2007.xlsx';

    const l = window.sampleL; // replace with your own license key and remove the license-key.js script tag;
      .then(() => convertOfficeToPDF(inputDir + docxFilename, 'converted_docx.pdf', l))
      .then(() => convertOfficeToPDF(inputDir + pptxFilename, 'converted_pptx.pdf', l))
      .then(() => convertOfficeToPDF(inputDir + xlsxFilename, 'converted_xlsx.pdf', l))
      .then(() => {
        console.log('Test Complete!');
      .catch((err) => {
        console.log('An error was encountered! :(', err);
// eslint-disable-next-line spaced-comment
//# sourceURL=OfficeToPDFTest.js