add id to pdf file name
parent
0dcdfaaa8a
commit
2c506711fb
|
|
@ -20,7 +20,13 @@ export async function handler(request, response, next) {
|
||||||
const reportData = await getReportData(printConfig, request.query);
|
const reportData = await getReportData(printConfig, request.query);
|
||||||
const reportPath = path.join('views', 'print', 'pdf', `${printName}.ejs`);
|
const reportPath = path.join('views', 'print', 'pdf', `${printName}.ejs`);
|
||||||
function pdfCallbackFunction(pdf) {
|
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.setHeader('Content-Type', 'application/pdf');
|
||||||
response.send(pdf);
|
response.send(pdf);
|
||||||
}
|
}
|
||||||
|
|
@ -32,8 +38,8 @@ export async function handler(request, response, next) {
|
||||||
}
|
}
|
||||||
const pdf = await convertHTMLToPDF(ejsData, {
|
const pdf = await convertHTMLToPDF(ejsData, {
|
||||||
format: 'letter',
|
format: 'letter',
|
||||||
printBackground: true,
|
preferCSSPageSize: true,
|
||||||
preferCSSPageSize: true
|
printBackground: true
|
||||||
}, {
|
}, {
|
||||||
usePackagePuppeteer: true
|
usePackagePuppeteer: true
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,18 @@ export async function handler(
|
||||||
const reportPath = path.join('views', 'print', 'pdf', `${printName}.ejs`)
|
const reportPath = path.join('views', 'print', 'pdf', `${printName}.ejs`)
|
||||||
|
|
||||||
function pdfCallbackFunction(pdf: Buffer): void {
|
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(
|
response.setHeader(
|
||||||
'Content-Disposition',
|
'Content-Disposition',
|
||||||
`${attachmentOrInline}; filename=${camelcase(printConfig?.title ?? 'export')}.pdf`
|
`${attachmentOrInline}; filename=${exportFileName}`
|
||||||
)
|
)
|
||||||
|
|
||||||
response.setHeader('Content-Type', 'application/pdf')
|
response.setHeader('Content-Type', 'application/pdf')
|
||||||
|
|
@ -73,13 +82,17 @@ export async function handler(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const pdf = await convertHTMLToPDF(ejsData, {
|
const pdf = await convertHTMLToPDF(
|
||||||
|
ejsData,
|
||||||
|
{
|
||||||
format: 'letter',
|
format: 'letter',
|
||||||
printBackground: true,
|
preferCSSPageSize: true,
|
||||||
preferCSSPageSize: true
|
printBackground: true
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
usePackagePuppeteer: true
|
usePackagePuppeteer: true
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
pdfCallbackFunction(Buffer.from(pdf))
|
pdfCallbackFunction(Buffer.from(pdf))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue