Some test text!

menu
How to load a tiff file?keyboard_arrow_down

How to load a TIFF file in WebViewer?

WebViewer requires the Full API to load a TIFF file. See this guide for how to setup full API.

You can then use the full API to manually create a document, add the TIFF image to the document and load the document in WebViewer:

WebViewer({
    //your configurations here...
    fullAPI: true
  }, document.getElementById('viewer'))
.then(function(instance) {
  var PDFNet = instance.PDFNet;

  PDFNet.runWithoutCleanup(function() {
    // variables to hold values
    var width = null;
    var height = null;
    var newDoc = null;
    var writer = null; // ElementWriter, used to write elements to the page
    var element = null;
    var matrix = null;
    var img = null;

    //create an empty document
    return PDFNet.PDFDoc.create()
      .then(function(doc) {
        newDoc = doc;
        newDoc.initSecurityHandler();
        newDoc.lock();

        //get image
        return PDFNet.Image.createFromURL(newDoc, "/files/test.tif");
      })
      .then(function(newImg) {
        img = newImg;
        //get image dimension
        return Promise.all([img.getImageWidth(), img.getImageHeight()]);
      })
      .then(function(results) {
        width = results[0];
        height = results[1];
        //create the matrix for this image
        return PDFNet.Matrix2D.create(width, 0, 0, height, 0, 0);
      })
      .then(function(newMatrix) {
        matrix = newMatrix;

        //ElementBuilder, used to build new element Objects
        return PDFNet.ElementBuilder.create();
      })
      .then(function(builder) {
        //create element use the builder
        return builder.createImageFromMatrix(img, matrix);
      })
      .then(function(newElement) {
        element = newElement;
        //create writer
        return PDFNet.ElementWriter.create();
      })
      .then(function(newWriter) {
        writer = newWriter;
        //define page dimensions
        return PDFNet.Rect.init(0, 0, width, height);
      })
      .then(function(pageRect) {
        //create page
        return newDoc.pageCreate(pageRect);
      })
      .then(function(page) {
        writer.beginOnPage(
          page,
          PDFNet.ElementWriter.WriteMode.e_overlay
        );
        // add image to new page
        writer.writePlacedElement(element);
        writer.end();
        newDoc.pagePushBack(page);
        instance.loadDocument(newDoc);
      });
  });
});

Get the answers you need: Support

close

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.