WebViewer Version:
Do you have an issue with a specific file(s)?
no
Can you reproduce using one of our samples or online demos?
Are you using the WebViewer server?
no
Does the issue only happen on certain browsers?
no
Is your issue related to a front-end framework?
yes
Is your issue related to annotations?
no
Please give a brief summary of your issue:
(Think of this as an email subject)
Comparing PDF files by overlaying PDF files and creating comparison PDFs does not work
Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
I act based on two examples from the documentation:
example 1
example 2
my implementation:
import type { WebViewerInstance } from '@pdftron/webviewer'
interface CompareFile {
blob: Blob | null
extension?: string
}
interface RunOverlayCompareParams {
firstFile: CompareFile
instance: WebViewerInstance
secondFile: CompareFile
}
export const runOverlayCompare = async ({
firstFile,
instance,
secondFile,
}: RunOverlayCompareParams) => {
if (!firstFile?.blob || !secondFile?.blob || !instance) {
return
}
try {
const { Core, UI } = instance
const { PDFNet } = Core
const loadAsPDFDoc = async (file: CompareFile) => {
const doc = await Core.createDocument(file.blob || '', {
extension: file.extension || 'pdf',
})
return doc.getPDFDoc()
}
const [doc1, doc2] = await Promise.all([loadAsPDFDoc(firstFile), loadAsPDFDoc(secondFile)])
const getPages = async (pdfDoc: any) => {
const pages: any[] = []
const itr = await pdfDoc.getPageIterator(1)
for (itr; await itr.hasNext(); itr.next()) {
const p = await itr.current()
pages.push(p)
}
return pages
}
const [pages1, pages2] = await Promise.all([getPages(doc1), getPages(doc2)])
const outDoc = await PDFNet.PDFDoc.create()
outDoc.lock()
const maxPages = Math.max(pages1.length, pages2.length)
for (let i = 0; i < maxPages; i++) {
let p1 = pages1[i]
let p2 = pages2[i]
if (!p1) {
p1 = await doc1.pageCreate()
}
if (!p2) {
p2 = await doc2.pageCreate()
}
await outDoc.appendVisualDiff(p1, p2)
}
outDoc.unlock()
UI.loadDocument(outDoc, {
extension: 'pdf',
filename: 'visual-diff.pdf',
})
} catch (e) {
console.error('Overlay compare failed:', e)
}
}
init webViewer:
const webViewer = await WebViewer(
{
css: './css.css',
disabledElements: disabledElementsByMode,
fullAPI: true,
licenseKey,
path: './webviewer',
},
ref.current
)
const { PDFNet, annotationManager } = webViewer.Core
const { enableElements, setLanguage, setToolbarGroup } = webViewer.UI
await PDFNet.initialize(licenseKey)
but errors pop up:
-
if you initialize PDFNet in the runOverlayCompare function:
-
if you access an existing instance and take values from it:

