add id to pdf file name

pull/11/head
Dan Gowans 2025-04-29 14:57:07 -04:00
parent 0dcdfaaa8a
commit 2c506711fb
2 changed files with 30 additions and 11 deletions

View File

@ -20,7 +20,13 @@ export async function handler(request, response, next) {
const reportData = await getReportData(printConfig, request.query);
const reportPath = path.join('views', 'print', 'pdf', `${printName}.ejs`);
function pdfCallbackFunction(pdf) {
response.setHeader('Content-Disposition', `${attachmentOrInline}; filename=${camelcase(printConfig?.title ?? 'export')}.pdf`);
let exportFileNameId = '';
if ((printConfig?.params.length ?? 0) > 0) {
// eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-template-expressions
exportFileNameId = `-${request.query[printConfig?.params[0] ?? '']}`;
}
const exportFileName = `${camelcase(printConfig?.title ?? 'export')}${exportFileNameId}.pdf`;
response.setHeader('Content-Disposition', `${attachmentOrInline}; filename=${exportFileName}`);
response.setHeader('Content-Type', 'application/pdf');
response.send(pdf);
}
@ -32,8 +38,8 @@ export async function handler(request, response, next) {
}
const pdf = await convertHTMLToPDF(ejsData, {
format: 'letter',
printBackground: true,
preferCSSPageSize: true
preferCSSPageSize: true,
printBackground: true
}, {
usePackagePuppeteer: true
});

View File

@ -53,9 +53,18 @@ export async function handler(
const reportPath = path.join('views', 'print', 'pdf', `${printName}.ejs`)
function pdfCallbackFunction(pdf: Buffer): void {
let exportFileNameId = ''
if ((printConfig?.params.length ?? 0) > 0) {
// eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-template-expressions
exportFileNameId = `-${request.query[printConfig?.params[0] ?? '']}`
}
const exportFileName = `${camelcase(printConfig?.title ?? 'export')}${exportFileNameId}.pdf`
response.setHeader(
'Content-Disposition',
`${attachmentOrInline}; filename=${camelcase(printConfig?.title ?? 'export')}.pdf`
`${attachmentOrInline}; filename=${exportFileName}`
)
response.setHeader('Content-Type', 'application/pdf')
@ -73,13 +82,17 @@ export async function handler(
return
}
const pdf = await convertHTMLToPDF(ejsData, {
const pdf = await convertHTMLToPDF(
ejsData,
{
format: 'letter',
printBackground: true,
preferCSSPageSize: true
}, {
preferCSSPageSize: true,
printBackground: true
},
{
usePackagePuppeteer: true
})
}
)
pdfCallbackFunction(Buffer.from(pdf))
}