Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!