I have an error when I try to compare both files
This is my code:
import React, { useRef, useEffect } from “react”;
import PropTypes from “prop-types”;
import WebViewer, {runWithoutCleanup} from “@pdftron/webviewer”;
export const licenseKey = ‘license key here’;
const CompareFeature = ({ useFileUrl, resourceId, resourceType }) => {
const pdfUrl = useFileUrl(resourceId, resourceType);
const docView = useRef(null);
useEffect((callback, license_key) => {
WebViewer(
{
licenseKey: licenseKey,
path: “/webviewer”,
enableMeasurement: true,
fullAPI: true,
},
docView.current
).then((instance) => {
// now you can access APIs through the WebViewer instance
const { Core } = instance;
const { PDFNet } = instance.Core;
async function main() {
await PDFNet.initialize();
// Start with a PDFDoc (open source documents to compare)
const doc1 = await PDFNet.PDFDoc.createFromURL(pdfUrl);
const doc2 = await PDFNet.PDFDoc.createFromURL(pdfUrl);
// Create an options object
const options = await PDFNet.PDFDoc.createTextDiffOptions();
// Before color is 100% red, 25% opacity
options.setColorA({ R: 1, G: 0, B: 0 });
options.setOpacityA(0.25);
// After color is 100% blue, 25% opacity
options.setColorB({ R: 0, G: 0, B: 1 });
options.setOpacityB(0.25);
// // Compare and highlight text differences
// await doc1.highlightTextDiff(doc2, options);
//
// // Compare and highlight text differences in doc1 and doc2
// await doc1.highlightTextDiff(doc2, options);
// Exclude footer area from page 1
const exclusion = [{ x1: 0, y1: 0, x2: 612, y2: 72 }];
options.addIgnoreZonesForPage(exclusion, 1);
// // Compare and highlight text differences
// await doc1.highlightTextDiff(doc2, options);
}
PDFNet.runWithoutCleanup(main, licenseKey)
.then((res) => {
console.log(res, 'res')
if (res.succeeded) {
console.log(res)
} else {
console.log(res, 'res erre')
}
})
.catch((e) => console.log(e,'err'));
Core.documentViewer.addEventListener("documentLoaded", () => {
// adding an event listener for when a document is loaded
});
Core.documentViewer.addEventListener("pageNumberUpdated", () => {
// adding an event listener for when the page number has changed
});
});
}, []);
return
;};
CompareFeature.propTypes = {
useFileUrl: PropTypes.func,
setFileUrl: PropTypes.func,
resourceId: PropTypes.string,
setLoading: PropTypes.func,
};
export default CompareFeature;