首页 > 解决方案 > pdftron 复制错误的文本

问题描述

我想使用pdftron并且一切正常,但是当我从 pdf 复制文本时,一些字符会转换为空白正方形和问号,有什么想法吗?

是我的pdf。

如下所示: 在此处输入图像描述

我写了这段代码:

WebViewer({
    path: '/assets/plugins/pdftron',
    initialDoc: '/practical.pdf',
    fullAPI: true,
    disableLogs: true
}, document.getElementById('pdf')).then((instance) => {
    // PDFNet is only available with full API enabled
    const { PDFNet, docViewer } = instance;

    let Feature = instance.Feature;
    instance.disableFeatures([Feature.NotesPanel]);

    docViewer.on('documentLoaded', () => {
        // call methods relating to the loaded document
    });


    instance.textPopup.add({
        type: 'actionButton',
        img: '/language.svg',
        onClick: () => {
            const quads = docViewer.getSelectedTextQuads(docViewer.getCurrentPage());
            const text = docViewer.getSelectedText();
            $("#out-pdf").html(text);
            console.log(quads);
        },
    });
});

标签: javascriptlaravelpdftron

解决方案


文档似乎确实导致提取不正确。PDF 规范没有定义提取,因此每个查看器处理案例的方式都略有不同。在您的情况下,文档中可能包含格式错误或不完整的字体或 unicode 映射。我们为我们的核心组件添加了多个修复程序,并且这些修复程序可以正确提取。不幸的是,当前版本的 WebViewer 还没有包含这些修复。我们无法给出修复将在 WebViewer 上发布的确切时间表,但至少应该是我们下一个主要版本的一部分。现在我会尝试看看你是否可以重新创建文档,看看是否有帮助。我们看到和测试的大多数文档都没有提取问题。


推荐阅读