Office to PDF

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.

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.

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 Web SDK and Office Document Conversion Library.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6(exports => {
7
8
9 const Core = exports.Core;
10 const PDFNet = Core.PDFNet;
11 const convertOfficeToPDF = (inputUrl, outputName, l) =>
12 Core.officeToPDFBuffer(inputUrl, { l }).then(buffer => {
13 saveBufferAsPDFDoc(buffer, outputName);
14 console.log(`Finished downloading ${outputName}`);
15 });
16
17 exports.runOfficeToPDF = (fileName, type) => {
18 const inputDir = '../../files/';
19
20 PDFNet.initialize()
21 .then(() => convertOfficeToPDF(inputDir + fileName, `converted_${type}.pdf`))
22 .then(() => {
23 console.log('Test Complete!');
24 })
25 .catch(err => {
26 console.log('An error was encountered! :(', err);
27 });
28 };
29})(window);
30// eslint-disable-next-line spaced-comment
31//# sourceURL=OfficeToPDFTest.js

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales