linkService 未定义 pdfjs nextjs
linkService is undefined pdfjs nextjs
我目前正在使用 pdfjs 来显示提供的 pdf 中的注释,但是在尝试呈现时,它显示 link服务未定义,我找不到解决此问题的方法。这是一段代码,如果它可能有帮助的话:
function renderPage(pageNumber: number, canvas: HTMLCanvasElement, loadedPdf: { getPage: (arg0: any) => Promise<any>}){
loadedPdf.getPage(pageNumber).then(async function (page) {
viewport = page.getViewport({scale: 1.5});
if (!!canvas) {
canvas.height = viewport.height;
canvas.width = viewport.width;
}
const renderContext = {
canvasContext: canvas.getContext('2d'),
viewport: viewport
}
page.render(renderContext);
// annotation processing portion
const view = page.view;
const annotations = await page.getAnnotations();
let annotationContainer = document.getElementById("annotation-layer");
if(!!annotationContainer) {
canvas.appendChild(annotationContainer);
annotationContainer.style.left = canvas.offsetLeft + "px";
annotationContainer.style.top = canvas.offsetTop + "px";
annotationContainer.style.height = canvas.height + "px";
annotationContainer.style.width = canvas.width + "px";
}
pdfjsLib.AnnotationLayer.render({
linkService: undefined,
downloadManager: undefined,
renderForms: false,
viewport: viewport.clone({dontFlip: true}),
div: annotationContainer,
annotations: annotations,
page: page
});
});
}
查看图书馆后,我需要为 link 服务提供 IPDFLinkService。如何解决这个问题?有人可以帮忙吗?
如果您不介意,可以尝试使用旧版本,即安装 pdfjs-dist 版本 2.6.347。对于 linkService,添加 pdfjsLib.LinkTarget.BLANK 即您的注释层渲染现在变为:
pdfjsLib.AnnotationLayer.render({
downloadManager: undefined,
renderInteractiveForms: false,
viewport: viewport.clone({dontFlip: true}),
div: annotationContainer,
annotations: annotations,
linkService: pdfjsLib.LinkTarget.BLANK,
page: page
});
我目前正在使用 pdfjs 来显示提供的 pdf 中的注释,但是在尝试呈现时,它显示 link服务未定义,我找不到解决此问题的方法。这是一段代码,如果它可能有帮助的话:
function renderPage(pageNumber: number, canvas: HTMLCanvasElement, loadedPdf: { getPage: (arg0: any) => Promise<any>}){
loadedPdf.getPage(pageNumber).then(async function (page) {
viewport = page.getViewport({scale: 1.5});
if (!!canvas) {
canvas.height = viewport.height;
canvas.width = viewport.width;
}
const renderContext = {
canvasContext: canvas.getContext('2d'),
viewport: viewport
}
page.render(renderContext);
// annotation processing portion
const view = page.view;
const annotations = await page.getAnnotations();
let annotationContainer = document.getElementById("annotation-layer");
if(!!annotationContainer) {
canvas.appendChild(annotationContainer);
annotationContainer.style.left = canvas.offsetLeft + "px";
annotationContainer.style.top = canvas.offsetTop + "px";
annotationContainer.style.height = canvas.height + "px";
annotationContainer.style.width = canvas.width + "px";
}
pdfjsLib.AnnotationLayer.render({
linkService: undefined,
downloadManager: undefined,
renderForms: false,
viewport: viewport.clone({dontFlip: true}),
div: annotationContainer,
annotations: annotations,
page: page
});
});
}
查看图书馆后,我需要为 link 服务提供 IPDFLinkService。如何解决这个问题?有人可以帮忙吗?
如果您不介意,可以尝试使用旧版本,即安装 pdfjs-dist 版本 2.6.347。对于 linkService,添加 pdfjsLib.LinkTarget.BLANK 即您的注释层渲染现在变为:
pdfjsLib.AnnotationLayer.render({
downloadManager: undefined,
renderInteractiveForms: false,
viewport: viewport.clone({dontFlip: true}),
div: annotationContainer,
annotations: annotations,
linkService: pdfjsLib.LinkTarget.BLANK,
page: page
});