Hello,
I’m trying to do something simple. I have a button and when it is clicked i want to create a PDF and it must download. The code is almost the same from this page ( Create Document (pdf-lib) - JSFiddle - Code Playground )
Backend
export async function button1_click ( event ) {
const pdfDoc = **await** PDFDocument . create ();
const timesRomanFont = **await** pdfDoc . embedFont ( StandardFonts . TimesRoman );
const page = pdfDoc . addPage ();
const { width , height } = page . getSize ()
const fontSize = 30 ;
page . drawText ( 'Creating PDFs in JavaScript is awesome!' , {
x : 50 ,
y : height - 4 * fontSize ,
size : fontSize ,
font : timesRomanFont ,
color : rgb ( 0 , 0.53 , 0.71 ),
});
const pdfBytes = **await** pdfDoc . save ();
download ( pdfBytes , " pdf-lib_creation_example.pdf " , "application/pdf" );
}
Here is the problem. The last line (download) is not executed so I cannot get the PDF. I added the npm downloadjs (v1.4.7) and included this line at the begining import { download } from ‘downloadjs’ ;
What am I missing?