Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

303
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda