Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
pdf-lib.js - after merging multiple pdf files, filled data in form fields become invisible

pdf-lib.js - after merging multiple pdf files, filled data in form fields become invisible

On individually viewing the files, everything is fine and the data just comes up fine.

The issue:

Example: If a pdf file has filled data(say abc.pdf) in it and after merging the pdf files to one single file, the merging is fine, but the filled data becomes invisible while viewing in the iframe. If we click on the field, it becomes visible.

Below is my code.

async function mergePDFDocuments(documents) {
  const mergedPdf = await PDFLib.PDFDocument.create();

  for (let document of documents) {
    
    let existingPdfBytes = await fetch(document).then(res => res.arrayBuffer())
    document = await PDFLib.PDFDocument.load(existingPdfBytes);

    const copiedPages = await mergedPdf.copyPages(document, document.getPageIndices());
    copiedPages.forEach((page) => mergedPdf.addPage(page));    
  }
  const pdfDataUri = await mergedPdf.saveAsBase64({
      dataUri: true
  });
  
  let iframe = document.createElement('iframe')
  iframe.setAttribute('style', 'width: 100%; height: 100%;')
  iframe.setAttribute('src', pdfDataUri)
  iframe.setAttribute('class', 'custom-pdf-frame')
  document.body.appendChild(iframe)
  
}

Basically it combines all the pdf files and sets the iframe src to the base64 string.

I opened abc.pdf in Acrobat Professional 8.1 and set the background color of a field to white and loaded the file in browser. That field showed the data just fine. Other fields showed their data only on clicking the field.

Not sure what I am missing in the code. Or is there an option to change the background color of the fields in the combined pdf file using pdf-lib.js?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Maybe Try:

const pdfDataUri = await mergedPdf.saveAsBase64({
      dataUri: true,
      updateFieldAppearances: true
  });

I use it like this:

var pdfBytes = await pdfDoc.save({
        updateFieldAppearances: true
    });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda