How to load byte array of tiff file fetched from web api in web viewer

WebViewer Version:8.8.0

I fetched the byte array of tiff file from server. I wanted to load that file in web viewer. But I couldn’t load it.

Angular code I used is:

const imgByteArray = await this.getImage() //fetch the tiff file byte array from server.
const blob = new Blob([new Uint8Array(imgByteArray )], { type: ‘image/tiff’ }) //convert the byte array to blob
instance.UI.loadDocument(blob) //load the blob

Above code didn’t work so i tried with following code:

const img: any = await this.getImage()
const blob = new Blob([new Uint8Array(img)], { type: ‘image/tiff’ })
const url = URL.createObjectURL(blob)

  await instance.Core.PDFNet.runWithoutCleanup(async () => {
    //create an empty document
    doc = await instance.Core.PDFNet.PDFDoc.create();
    doc.initSecurityHandler();
    doc.lock();
   
    const tiffFile = await instance.Core.PDFNet.Filter.createURLFilter(url);
    await instance.Core.PDFNet.Convert.fromTiff(doc, tiffFile);
    const buffer = await doc.saveMemoryBuffer(instance.Core.PDFNet.SDFDoc.SaveOptions.e_linearized);
    doc.unlock();
  }, '');
  instance.UI.loadDocument(doc)

With this code, i got the following error:

Message: An error occurred while converting the TIFF.
Detailed error:
Exception:
Message: filter does not contain enough image data
Conditional expression: flt->Size() > 8
Version : 9.3.0-64b49865f
Platform : Emscripten
Architecture : Emscripten
Filename : Image.cpp
Function : CreateImagesFromMultipageTIFF
Linenumber : 1683

 Filename: Convert.cpp
 Function: FromTiff
 Linenumber: Ϳ��>ڂa�?

Error: Uncaught (in promise): Exception:
Message: An error occurred while converting the TIFF.
Detailed error:
Exception:
Message: filter does not contain enough image data
Conditional expression: flt->Size() > 8
Version : 9.3.0-64b49865f
Platform : Emscripten
Architecture : Emscripten
Filename : Image.cpp
Function : CreateImagesFromMultipageTIFF
Linenumber : 1683

 Filename: Convert.cpp
 Function: FromTiff
 Linenumber: Ϳ��>ڂa�?

Pls suggest how can we load the tiff file when we have byte array of the tiff.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hello,

Thank you for contacting WebViewer Support.

The error seems to be with the TIFF file conversion. I’d like to know if it is possible for you to provide a TIFF file that you’re trying to load so I can try to reproduce the same scenario and help you better on this.

Just confirming, did you use the fullAPI: true option on the WebViewer options?

Best Regards,

Dandara Navarro
Web Software Developer
PDFTron Systems, Inc.

Thank you for your response. I was able to figure out the problem. Issue was when fetching the tiff viewer. Instead of array buffer, it was returning the base64string of the tiff file.

1 Like

Hello,

Glad to hear it is working now.

I’ll close this ticket but feel free to open a new one if you have any problems.

Best Regards,

Dandara Navarro
Web Software Developer
PDFTron Systems, Inc.