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

234
Visualizações
PDFMake Base64 generates malformed document

I'm using PDFMake to generate some PDF reports on client side. When I specify the definition for document and pass it to createPdf(DEFINITION_HERE) I get my PDF and it looks nice and shiny. But I'm saving it in the DB as Base64 encoded string and when I try to reopen it with data URI (ie: data:application/pdf;base64,JVBER...) the document is completely malformed.

My DB call looks like this:

await pdfFile.getDataUrl(async (result: string) => {
      await myServiceLayer.generatePdfReport(result, fileName, creator);
});

Anyone else had this issue with PDFMake library? Any ideas on what could be the cause of this?

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

0

OK, so after trying different things and debugging left and right, I stumbled upon this:

https://github.com/bpampuch/pdfmake/issues/318

So I removed call to .download() on my PDF file and checked for Base64 again, now it had correct value and file looks as it should.

So in a nutshell, if we call multiple methods on PDFMake, usually something will get messed up.

I had my .download() call just before my .getBase64() as I wanted to first download the file for the user and then also store it in DB as Base64, as .download() happened .getBase64() kept on giving me Base64 output which resulted in malformed PDF file.

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