var resourceURL = "/resource/"; window.CoreControls.forceBackendType("ems"); var urlSearch = new URLSearchParams(location.hash); var custom = JSON.parse(urlSearch.get("custom")); resourceURL = resourceURL + custom.namespacePrefix; /** * The following `window.CoreControls.set*` functions point WebViewer to the * optimized source code specific for the Salesforce platform, to ensure the * uploaded files stay under the 5mb limit */ // office workers window.CoreControls.setOfficeWorkerPath(resourceURL + "DIRSCORE__office"); window.CoreControls.setOfficeAsmPath(resourceURL + "DIRSCORE__office_asm"); window.CoreControls.setOfficeResourcePath(resourceURL + "DIRSCORE__office_resource"); // pdf workers window.CoreControls.setPDFResourcePath(resourceURL + "DIRSCORE__resource"); if (custom.fullAPI) { window.CoreControls.setPDFWorkerPath(resourceURL + "DIRSCORE__pdf_full"); window.CoreControls.setPDFAsmPath(resourceURL + "DIRSCORE__asm_full"); } else { window.CoreControls.setPDFWorkerPath(resourceURL + "DIRSCORE__pdf_lean"); window.CoreControls.setPDFAsmPath(resourceURL + "DIRSCORE__asm_lean"); } // external 3rd party libraries window.CoreControls.setExternalPath(resourceURL + "DIRSCORE__external"); window.CoreControls.setCustomFontURL("https://pdftron.s3.amazonaws.com/custom/ID-zJWLuhTffd3c/vlocity/webfontsv20/"); window.addEventListener("message", receiveMessage, false); function receiveMessage(event) { if (event.isTrusted && typeof event.data === "object") { switch (event.data.type) { case "OPEN_DOCUMENT": event.target.readerControl.loadDocument(event.data.file, { officeOptions: { disableBrowserFontSubstitution: true } }); break; case "OPEN_DOCUMENT_BLOB": const { blob, extension, filename, documentId } = event.data.payload; event.target.readerControl.loadDocument(blob, { extension, filename, documentId, officeOptions: { disableBrowserFontSubstitution: true } }); break; case "DOCUMENT_SAVED": readerControl.showErrorMessage("Document saved!"); break; case "CLOSE_DOCUMENT": event.target.readerControl.closeDocument(); break; default: break; } } } (async (exports) => { window.count = 0; const PDFNet = exports.PDFNet; let CoreControls = null; let Annotations = null; const getDiffOptions = async () => { const redColor = new Annotations.Color(200, 0, 0, 1); const blueColor = new Annotations.Color(0, 200, 200, 1); const options = await PDFNet.createDiffOptions(); // instead of Annotations.Color, we can pass in an objects in the form {R: 200, G: 0, B: 0, A: 1} options.setColorA(redColor); options.setColorB(blueColor); //options.setBlendMode(5); return options; }; const init = async () => { CoreControls = window.CoreControls; Annotations = window.Annotations; CoreControls.enableFullPDF(true); await PDFNet.initialize(); }; function cssapply(element,color) { setTimeout(() => { let versionbtn = document.querySelector('[data-element='+element); if (versionbtn !== null && versionbtn !== undefined) { versionbtn.style.width = "70px"; versionbtn.style.color = color; } }, 2000); } window.addEventListener("viewerLoaded", async () => { readerControl.setReadOnly(true); await init(); let headerKey='';let headerVal=''; if(custom.comparedocdata[0].usesystemaccount) { headerKey="usesystemaccount"; headerVal='true'; } else if(custom.comparedocdata[0].userinfo!='') { headerKey="userinfo"; headerVal=custom.comparedocdata[0].userinfo; } else{ headerKey="userid"; headerVal=custom.comparedocdata[0].userid; } const doc1 = await PDFNet.PDFDoc.createFromURL( custom.comparedocdata[0].docContentURL, { filename: custom.comparedocdata[0].fileName, customHeaders: { // Authorization: custom.comparedocdata[0].authToken, tenantid: custom.comparedocdata[0].tenantid, client_id: custom.comparedocdata[0].client_id, client_secret: custom.comparedocdata[0].client_secret, [headerKey]:headerVal }, withCredentials: false } ); if(custom.comparedocdata[1].usesystemaccount) { headerKey="usesystemaccount"; headerVal='true'; } else if(custom.comparedocdata[1].userinfo!='') { headerKey="userinfo"; headerVal=custom.comparedocdata[1].userinfo; } else{ headerKey="userid"; headerVal=custom.comparedocdata[1].userid; } const doc2 = await PDFNet.PDFDoc.createFromURL( custom.comparedocdata[1].docContentURL, { filename: custom.comparedocdata[1].fileName, customHeaders: { // Authorization: custom.comparedocdata[1].authToken, tenantid: custom.comparedocdata[1].tenantid, client_id: custom.comparedocdata[1].client_id, client_secret: custom.comparedocdata[1].client_secret, [headerKey]:headerVal }, withCredentials: false } ); const compareDoc = async (doc1, doc2) => { const newDoc = await PDFNet.PDFDoc.create(); newDoc.lock(); const options = await getDiffOptions(); const pages = []; const itr = await doc1.getPageIterator(1); const itr2 = await doc2.getPageIterator(1); let i = 0; for (itr; await itr.hasNext(); itr.next()) { const page = await itr.current(); pages[i] = [page]; i++; } i = 0; for (itr2; await itr2.hasNext(); itr2.next()) { const page = await itr2.current(); (pages[i] || (pages[i] = [null])).push(page); i++; } pages.forEach(async ([p1, p2]) => { if (!p1) { p1 = new PDFNet.Page(0); } if (!p2) { p2 = new PDFNet.Page(0); } await newDoc.appendTextDiffDoc(p1, p2); }); await newDoc.unlock(); let frame = window.frameElement; readerControl.setHeaderItems(header => { header.push({ type: "actionButton", className: "row", dataElement: "versionnum1", label: "Version " + custom.comparedocdata[0].versionnum }); header.push({ type: "actionButton", className: "row", dataElement: "versionnum2", label: "Version " + custom.comparedocdata[1].versionnum }); }); cssapply("versionnum1", "red"); cssapply("versionnum2","aqua"); readerControl.loadDocument(newDoc); }; await compareDoc(doc1, doc2); }); })(window);