小编Nic*_*bba的帖子

将 PDF 与 PDF-LIB 合并

我正在尝试复制合并 2 个 pdf 文件的官方示例,但我想让用户上传两个文件,而不是硬编码文件名。当文件名被硬编码时(参见 url2),该代码可以很好地工作,但是当尝试从输入标记检索文件名时,该代码不起作用。我究竟做错了什么?

async function copyPages() {
    // Fetch first existing PDF document
    const url1 = document.getElementById('file1').file[0].name
    //const url1 = 'Patient_Card.pdf'
    const doc1 = await fetch(url1).then(res => res.arrayBuffer())

    // Fetch second existing PDF document
    const url2 = 'Patient_Card.pdf'
    const doc2 = await fetch(url2).then(res => res.arrayBuffer())

    // Load a PDFDocument from each of the existing PDFs
    const pdf1 = await PDFDocument.load(doc1)
    const pdf2 = await PDFDocument.load(doc2)

    // Create a new PDFDocument
    const mergedPdf = await PDFDocument.create();

    const copiedPagesA …
Run Code Online (Sandbox Code Playgroud)

javascript pdf

4
推荐指数
1
解决办法
8863
查看次数

标签 统计

javascript ×1

pdf ×1