Added infinite height support.
This commit is contained in:
parent
aa4d2c6873
commit
4653430c0f
@ -18,18 +18,18 @@
|
||||
}
|
||||
|
||||
.previewWrapper {
|
||||
width: <%= (width * scale) + 'mm' || '50mm' %>;
|
||||
height: <%= (height * scale) + 'mm' || '50mm' %>;
|
||||
width: <%= (scaledWidth) || '50mm' %>;
|
||||
height: <%= (scaledHeight) || '50mm' %>;
|
||||
}
|
||||
.previewDocument {
|
||||
width: <%= (width) + 'mm' || '50mm' %>;
|
||||
height: <%= (height) + 'mm' || '50mm' %>;
|
||||
width: <%= (width) || '50mm' %>;
|
||||
height: <%= (height) || '50mm' %>;
|
||||
transform: scale(<%= scale || '1' %>);
|
||||
transform-origin: top left;
|
||||
}
|
||||
.renderDocument {
|
||||
width: <%= (width * scale) + 'mm' || '50mm' %>;
|
||||
height: <%= (height * scale) + 'mm' || '50mm' %>;
|
||||
width: <%= (scaledWidth) || '50mm' %>;
|
||||
height: <%= (scaledHeight) || '50mm' %>;
|
||||
transform: scale(<%= scale || '1' %>);
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -1 +1 @@
|
||||
<div class="renderDocument"><%- content %></div>
|
||||
<div class="renderDocument" id="content"><%- content %></div>
|
||||
|
||||
@ -30,13 +30,22 @@ export async function generatePDF(html, options = {}) {
|
||||
waitUntil: 'networkidle0'
|
||||
});
|
||||
|
||||
var height = `${options?.height || '50'}mm`;
|
||||
|
||||
if (options.height == 'auto') {
|
||||
console.log('Calculating height');
|
||||
const calculatedHeight = await page.evaluate(() => {
|
||||
return document.getElementById('content').scrollHeight;
|
||||
});
|
||||
|
||||
height = `${calculatedHeight}px`;
|
||||
}
|
||||
// Generate PDF with specified dimensions
|
||||
const pdfBuffer = await page.pdf({
|
||||
format: options.format || undefined,
|
||||
width: options.width ? `${options.width}mm` : undefined,
|
||||
height: options.height ? `${options.height}mm` : undefined,
|
||||
printBackground: true,
|
||||
preferCSSPageSize: true,
|
||||
width: options.width ? `${options.width}mm` : undefined,
|
||||
height: height ? `${height}` : undefined,
|
||||
margin: {
|
||||
top: '0mm',
|
||||
right: '0mm',
|
||||
|
||||
@ -430,8 +430,14 @@ export class TemplateManager {
|
||||
documentTemplate.parent.content == null ||
|
||||
typeof documentTemplate.parent.content !== 'string'
|
||||
) {
|
||||
console.log(
|
||||
'Parent template content is required and must be a string.',
|
||||
documentTemplate.parent.content
|
||||
);
|
||||
return {
|
||||
error: 'Parent template content is required and must be a string.'
|
||||
error:
|
||||
'Parent template content is required and must be a string.' +
|
||||
documentTemplate.parent.content
|
||||
};
|
||||
}
|
||||
templateWithParentContent = await ejs.render(
|
||||
@ -481,12 +487,18 @@ export class TemplateManager {
|
||||
return { error: 'Failed to render inner template content.' };
|
||||
}
|
||||
|
||||
const infiniteHeight = documentSize.infiniteHeight == true;
|
||||
|
||||
const baseHtml = await ejs.render(
|
||||
baseTemplate,
|
||||
{
|
||||
content: innerHtml,
|
||||
width: documentSize.width,
|
||||
height: documentSize.height,
|
||||
width: `${documentSize.width}mm`,
|
||||
height: infiniteHeight ? 'fit-content' : `${documentSize.height}mm`,
|
||||
scaledWidth: `${documentSize.width * scale}mm`,
|
||||
scaledHeight: infiniteHeight
|
||||
? 'auto'
|
||||
: `${documentSize.height * scale}mm`,
|
||||
scale: `${scale}`,
|
||||
baseCSS: baseCSS,
|
||||
previewPaginationScript: preview ? previewPaginationScript : ''
|
||||
@ -497,7 +509,8 @@ export class TemplateManager {
|
||||
const previewObject = {
|
||||
html: baseHtml,
|
||||
width: documentSize.width,
|
||||
height: documentSize.height
|
||||
height: infiniteHeight ? 'auto' : documentSize.height,
|
||||
infiniteHeight: infiniteHeight
|
||||
};
|
||||
|
||||
return previewObject;
|
||||
@ -552,7 +565,8 @@ export class TemplateManager {
|
||||
// Generate PDF using PDF factory
|
||||
const pdfBuffer = await generatePDF(baseHtml, {
|
||||
width: renderedTemplate.width,
|
||||
height: renderedTemplate.height
|
||||
height: renderedTemplate.height,
|
||||
infiniteHeight: renderedTemplate.infiniteHeight
|
||||
});
|
||||
|
||||
const pdfObject = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user