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

345
Views
Excel JS workbook to PDF (File gets corrupt)

I have downloaded a file through some options, using filesaver or [a]download, but only with the xlsx extension. When I try to download it as a .pdf, the file is downloaded, but it does get corrupted, and I am not able to view it, while the excel file is okay. The excel workbook is created using excel Js.

The piece of code that represents the problem is below.

private exportExcel(workbook: any, filename: string) {
    workbook.xlsx.writeBuffer().then((data) => {
      console.log(data);

      let blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });

      const anchor = document.createElement('a');
      const url = URL.createObjectURL(blob);
      anchor.href = url;
      anchor.download = filename;
      document.body.appendChild(anchor);
      anchor.click();
      document.body.removeChild(anchor);
      URL.revokeObjectURL(url);

      const urlpdf = URL.createObjectURL(new Blob([data], {type: "application/pdf"}));
      fetch(urlpdf).then(res => res.blob()).then(blob => {
        const data = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = data;
        a.download = 'file';
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        URL.revokeObjectURL(data);
      })
   }).catch(err => console.log(err))
  }

I have tryed it using fetch, not using blob (then I get an error) but none of the options exports a valid .pdf. Thanks in advance.

I am using angular framework

about 4 years ago · Juan Pablo Isaza
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!