Available Now: Explore our latest release with enhanced accessibility and powerful IDP features
By Apryse | 2023 Aug 17
4 min
Tags
javascript
docx to pdf
office conversion
In the modern business landscape, sharing, converting and archiving documents in a reliable and universally accessible format is paramount. PDF stands out as a versatile and widely supported format that ensures consistent presentation across different platforms. Converting Office documents such as Word, Excel, and PowerPoint files into PDFs is a common requirement.
The Apryse PDF SDK can be used with multiple languages and frameworks to convert Office Documents to PDF, with both client-side (within the browser) and server-side conversions. In this blog post, we'll explore how to convert Office documents to PDF using the Apryse SDK and JavaScript, running entirely within the browser.
If you have Office installed, then creating a PDF is simple.
The awesome thing about this solution is that there is no need for Office to be installed, either on your machine or on a server somewhere.
That’s right. The conversion occurs entirely without the need for Office.
When the conversion is performed within the browser it can start immediately without the delay associated with it being uploaded to a server. Furthermore, from a security point of view, a browser-based conversion means that the document never leaves your machine. This entirely removes the need for it to be transferred over the internet and stored, even briefly, on someone else’s server, with the associated risks of user data being stolen or shared.
From the website owner’s point of view, conversions don’t require high-powered (and expensive) servers, and the risk of malicious users uploading dangerous files onto the server is entirely avoided.
Having the conversion occur within the browser does require the conversion code to be transferred to the browser. This is only about 11MB, and after the first load, it will be fetched from the local cache rather than over the network.
If you don't already have an Apryse account, go to https://dev.apryse.com and register a new account with Apryse. This allows Apryse to grant you a demo license key which will be used with the Apryse SDK to enable demo functionality.
Figure 1- The Developer Portal
Log into https://dev.apryse.com with your registered account. For this guide, we’ll be developing a JavaScript Web application, so select Web platform.
Click on the reveal button to get your personalized trial key.
Figure 2 - Download Center Platform and Trial Key
This sample uses version 10.3 of the Apryse WebViewer SDK and the trial license key which you have just revealed.
The sample is intended to show how a single document in a hard-coded location can be converted to PDF.
In reality, you are likely to want to be able to specify which document is to be converted and what you want to do with the PDF once the conversion is complete, as the code should be considered to be an example of how to convert a file and see the result, rather than as a template of how to write an entire document processing solution.
<html>
<body>
<script src="./core/webviewer-core.min.js"></script>
<script>
(async function() {
Core.setWorkerPath('./core');
const licenseKey = 'Insert commercial license key here after purchase
// make sure that you use a real license key, rather than just using the
// text above, otherwise you will get an error when the conversion occurs
await Core.PDFNet.initialize();
// perform the conversion with no optional parameters
const buf = await Core.officeToPDFBuffer('Fishermen.docx', { l: licenseKey });
const blob = new Blob([buf], { type: 'application/pdf' });
// optionally save the blob to a file or upload to a server
// in this example the blob will be displayed within the browser
var link=window.URL.createObjectURL(blob);
window.location=link;
})()
</script>
</body>
</html>
Figure 3 - output from the httpserver
As soon as the page loads, the Fisherman.docx file is converted into a PDF, and the resulting document is displayed within the browser, from where the user can view or save it.
Figure 4 - An example Word document, now converted to a PDF
In production, of course, you might prefer to save the PDF directly to a file or upload it to a server using whatever mechanism that you write.
Absolutely not. In addition to converting from Word, the SDK can convert from Excel and PowerPoint, including using the legacy Office formats of .doc, .xls, and .ppt.
Excel spreadsheets can be converted into a multiple-page PDF with each page laid out in the same way as the original spreadsheet.
Figure 5 - An example Excel spreadsheet now converted to a PDF (source: https://create.microsoft.com/en-us/template/small-business-cash-flow-forecast-f7200e29-427a-4653-afde-52f846e590a1)
And PowerPoint presentations can also be converted into multi-page PDFs.
Figure 6 - A PowerPoint presentation now converted to a PDF
It is also possible to convert .txt, .odt, .rtf and .doc files to PDF in the same way.
Apryse offers a simple mechanism for converting Office documents to PDF without Office being installed. These powerful conversion capabilities, coupled with the ease of integration provided by its JavaScript library, make it the best choice for developers aiming to enhance their document processing workflows. Whether you're building a document management system, an online collaboration platform, or any other application involving Office documents, Apryse can help you provide a seamless and efficient conversion process.
With Apryse's capabilities at your disposal, you can enhance your application's functionality and provide users with a reliable way to convert and work with Office documents in PDF format.
Apryse's JavaScript library provides developers with an easy-to-use API that enables seamless integration into web applications. This library enables you to not only convert Office documents to PDF but also perform a variety of PDF-related operations, such as editing, annotating, and extracting content.
Apryse is a leading provider of cross-platform PDF development tools. With its comprehensive PDF processing capabilities, it offers an excellent solution for converting Office documents to PDF.
You can check out our interactive demo for a demonstration of how document conversions work in the ApryseWebViewer, or see the documentation for the Web SDK to get started quickly. Don’t forget, you can also reach out to us on Discord if you have any issues.
Tags
javascript
docx to pdf
office conversion
Apryse
Share this post
PRODUCTS
Enterprise
Small Business
Popular Content