Some test text!


Convert PDF to image (JPG, PNG, BMP, TIFF) in Javascript

Sample Javascript code to use PDFTron SDK's built-in rasterizer to render PDF images on the fly and save the resulting images in various raster image formats (such as PNG, JPEG, BMP, TIFF). Learn more about our Javascript PDF Library and PDF Conversion Library.

Get StartedSamplesDownload

To run this sample, get started with a free trial of PDFTron SDK.

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

const { PDFNet } = require('../../lib/pdfnet.js');

((exports) => {

  exports.runPDFDrawTest = () => {

    const main = async() => {
      console.log('Beginning Test');
      const ret = 0;
      const inputUrl = '../TestFiles/';
      const doc = await PDFNet.PDFDoc.createFromFilePath(inputUrl + 'newsletter.pdf');

      console.log('PDFNet and PDF document initialized and locked');

      const pdfdraw = await PDFNet.PDFDraw.create(92);
      const itr = await doc.getPageIterator(1);
      const currPage = await itr.current();
      await pdfdraw.export(currPage, '../TestFiles/Output/newsletter.png', 'PNG');
      await pdfdraw.export(currPage, '../TestFiles/Output/newsletter.tif', 'TIFF');

      return ret;

    // add your own license key as the second parameter, e.g. PDFNet.runWithCleanup(main, 'YOUR_LICENSE_KEY')
// eslint-disable-next-line spaced-comment
//# sourceURL=PDFDrawTest.js

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more