I tried this but it doesn't work. I've also added a few more methods. Already asked about Chat GPT but doesn't work.
try { // 从HTML生成PDF const pdf = await page.pdf({path:'custom.pdf', format: 'A4', pageRanges: '1' }); await browser.close(); return pdf; } catch (error) { console.error('生成PDF时出错:', error); }
tHSIS code will not work because the path option in the pdf() method is only used to specify the temporary file created during the PDF generation process. The actual PDF file will be saved in the default download directory. To set a fixed PDF name, you need to intercept the server's response and modify the Content-Disposition header. The following code shows how to do this: