Convert image to PDF in JavaScript
Convert TIFF, BMP, PNG, JPG to PDF using WebViewer SDK in the browser without server-side dependencies. (You can also check out our online Image To PDF demo now.)
Using WebViewer
WebViewer supports loading images by default using initialDoc, or loadDocument API. After loading the document, you can get the document and save it as a PDF or download it.
WebViewer constructor
Load the image with the WebViewer constructor and it will load with the Viewer.
WebViewer({
...,
initialDoc: 'https://myserver.com/myfile.png',
}, document.getElementById('viewer'));Display & view documents using JavaScript Full sample code shows how to call WebViewer constructor to instantiate and load document. You can load local/remote files of your choice.
Load document
Load the image with the load document method after WebViewer is initalized.
WebViewer(...)
.then(instance => {
instance.UI.loadDocument('https://myserver.com/myfile.png', { filename: 'myfile.png' });
});Display & view documents using JavaScript Full sample code shows how to call WebViewer constructor to instantiate and load document. You can load local/remote files of your choice.
Load TIFF
WebViewer allows loading TIFF, TIF files in the sample below.
Without WebViewer UI
This code sample demonstrates how to convert image to PDF without initializing WebViewer UI.
Last updated
Was this helpful?