Section:

Open TIFF documents in Salesforce

Getting Started

We recommend the Overview page to learn how to correctly use a config.js before getting started with using Webviewer.

Open Document

To view and load .tiff files first will be different than loading a standard document file. First you'll need to configure the lwc component pdftronWvInstance to divert any tiff files uploaded or selected files and create another iframeWindow.postMessage to the config file and transport the tiff file payload.

JavaScript

1handleBlobSelected(record) {
2 const blobby = new Blob([_base64ToArrayBuffer(record.body)], {
3 type: mimeTypes[record.FileExtension]
4 });
5
6 const payload = {
7 blob: blobby,
8 extension: record.cv.FileExtension,
9 filename: record.cv.Title + "." + record.cv.FileExtension,
10 documentId: record.cv.Id
11 };
12
13 switch (payload.extension){
14 case 'tiff':
15 this.iframeWindow.postMessage({ type: 'OPEN_TIFF_BLOB', payload }, '*');
16 break;
17 default:
18 this.iframeWindow.postMessage({ type: 'OPEN_DOCUMENT_BLOB', payload }, '*');
19 break;
20 }
21 }

Recieve Message

In your config file, recieveMessage method would receive the tiff file payload. 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:

JavaScript

1window.addEventListener("message", receiveMessage, false);
2
3function receiveMessage(event) {
4 if (event.isTrusted && typeof event.data === 'object') {
5 switch (event.data.type) {
6 case 'OPEN_TIFF_BLOB':
7 loadTIFF(event.data.payload)
8 break;
9 default:
10 break;
11 }
12 }
13}
14
15async function loadTIFF(payload){
16 var blob = payload.blob;
17
18 await PDFNet.runWithoutCleanup(async () => {
19 var newDoc = await PDFNet.PDFDoc.create();
20 newDoc.initSecurityHandler();
21 newDoc.lock();
22
23 let bufferTiff = await blob.arrayBuffer();
24 const tiffFile = await PDFNet.Filter.createFromMemory(bufferTiff);
25 await PDFNet.Convert.fromTiff(newDoc, tiffFile);
26 const buffer = await newDoc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_linearized);
27 newDoc.unlock();
28 instance.loadDocument(newDoc);
29 });
30}

If you want to download from the Webviewer instance, it would be converted to a pdf file.

Sample project

You can review the Salesforce PDF App to showcase an end-to-end example of search, and how you can leverage it for redaction and content replacing on our Github repository.

Live demo

Check out this live Demo (hosted outside of Salesforce).

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales