让木偶师生成的PDF文件通过可访问性报告。

4
我正在使用 Puppeteer 构建 PDF 文件,生成的 PDF 看起来很好,但在 PDF 辅助功能报告中失败了。主要问题是 PDF 的标题和语言。我尝试通过 EXIF 值(TitleLanguage)来设置两者,标题在某些情况下确实显示了,但仍然未能通过 Acrobat Pro 的辅助功能检查报告。我使用另一个辅助功能检查报告(http://checkers.eiii.eu/en/pdfcheck/),在那里标题设置成功了,但语言没有设置成功。
我已经使用 --export-tagged-pdf 作为启动参数,修复了许多其他问题。是否有人知道如何通过辅助功能报告呢?主要是语言参数。我使用 Node.js 生成 PDF,即使有另一个库可以在事后编辑 PDF,那也会非常有帮助,但我还没有想出来。

你解决了吗? - oct51
1
我能够通过使用额外的 pdf-lib 包修改现有的 PDF 文件来满足标题和语言要求。不幸的是,我无法满足“书签”要求。 - oct51
1个回答

1
面对同样的问题,我成功获取了所有必需的元数据和XMP数据,除了PDF-UA标识符。我使用JS库“pdf-lib”(https://pdf-lib.js.org/docs/api/classes/pdfdocument)设置元数据,并使用exiftool-vendored注入XMP模式数据。
  const pdfLib = require('pdf-lib');
  const exiftool = require("exiftool-vendored").exiftool
  const fs = require('fs');
  const distexiftool = require('dist-exiftool');

  const pdfData = await fs.readFile('your-pdf-document.pdf');
  const pdfDoc = await pdfLib.PDFDocument.load(pdfData);

  const nowDate = new Date();
  const meta_creator = "The author";
  const meta_author = "The author";
  const meta_producer = "The producer";
  const meta_title = "Your PDF title";
  const meta_subject = "Your PDF subject";
  const meta_creadate = `${nowDate.getFullYear()}-${nowDate.getMonth()+1}-${nowDate.getDate()}`;
  const meta_keywords = ["keyword1", "keyword2", "keyword3", "keyword4"];

  // Implement PDF Title
  pdfDoc.setSubject(meta_subject);

  // Implement required "DisplayDocTitle" pdf var
  pdfDoc.setTitle(meta_title, {
    showInWindowTitleBar: true,
    updateMetadata: true
  });

  // Implement PDF language
  pdfDoc.setLanguage("en-EN");

  // Save file in order exiftool can load it
  const pdfBytes = await pdfDoc.save();
  await fs.promises.writeFile("your-pdf-document.pdf", pdfBytes);

  // We use "distexiftool" to get the TAGS from PDF/UA well formed XMP file "pdfUA-ID.xmp" and assign data to "your-pdf-document.pdf"
  execFile(distexiftool, ["-j","-xmp<=pdfUA-ID.xmp", "your-pdf-document.pdf"], (error, stdout, stderr) => {
        if (error) {
            console.error(`exec error: ${error}`);
            return;
        }
        afterTagsOperation()
    });

    async function afterTagsOperation(){
      // Open the file and write XMP tags with exiftool
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Author': meta_author });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Creator': meta_creator });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:CreateDate': meta_creadate });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Producer': meta_producer });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Title': meta_title });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Subject': meta_subject });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Keywords': meta_keywords });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Trapped': 'false' });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:DocumentID': `uuid:${nowDate.getTime()}` });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Title': meta_title });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Subject': meta_subject });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Keywords': meta_keywords });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Trapped': 'false' });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:Identifier': nowDate.getTime() });
      await exiftool.write("your-pdf-document.pdf", { 'xmp:PDFVersion': `v${nowDate.getTime()}` });
      await exiftool.write("your-pdf-document.pdf", { 'xmp-xmpMM:DocumentID': `uuid:${nowDate.getTime()}` });
      await exiftool.write("your-pdf-document.pdf", { 'xmp-dc:format': `application/pdf` });
      await exiftool.write("your-pdf-document.pdf", { 'xmp-dc:title': meta_title });

      // We save the file
      const pdfBytes = await pdfDoc.save();
      await fs.promises.writeFile("your-pdf-document.pdf", pdfBytes);
    }



嗨,安德烈,我刚刚编辑了我的回答,因为我找到了一种方法来获取PDF / UA缺失的标识符,即通过将合规性XMP文件中的TAGS分配给PDF文件,然后更改一些标记以定制数据。 - Foxlab

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接