diff --git a/libs/printing/src/render.test.tsx b/libs/printing/src/render.test.tsx
index d02a9be745..010db4fdd5 100644
--- a/libs/printing/src/render.test.tsx
+++ b/libs/printing/src/render.test.tsx
@@ -111,6 +111,21 @@ test('page can be longer than letter when using LetterRoll', async () => {
});
});
+test('page can not be longer than 100 inches when using LetterRoll', async () => {
+ const outputPath = tmpNameSync();
+ const pdfData = await renderToPdf({
+ document: ,
+ outputPath,
+ paperDimensions: PAPER_DIMENSIONS.LetterRoll,
+ });
+
+ const pdf = await parsePdf(pdfData);
+ expect(pdf.numPages).toEqual(3);
+ const { height, width } = (await pdf.getPage(1)).getViewport({ scale: 1 });
+ expect(width * PDF_SCALING).toEqual(1700); // letter
+ expect(height * PDF_SCALING).toEqual(20000); // maximum length
+});
+
test('bmd 150 page is 13.25"', async () => {
const outputPath = tmpNameSync();
const pdfData = await renderToPdf({
diff --git a/libs/printing/src/render.tsx b/libs/printing/src/render.tsx
index 011154e6a5..473f23774b 100644
--- a/libs/printing/src/render.tsx
+++ b/libs/printing/src/render.tsx
@@ -24,7 +24,7 @@ export const PAPER_DIMENSIONS = {
// their own, followed by a mostly blank line. This causes stripes in the printed page.
Bmd150: { width: 7.975, height: 13.25 },
Letter: { width: 8.5, height: 11 },
- LetterRoll: { width: 8.5, height: Infinity },
+ LetterRoll: { width: 8.5, height: 100 }, // If we make the height infinite the canvas conversion to an image can seg fault. Break into pages beyond 100 inches.
} satisfies Record;
export interface MarginDimensions {
@@ -112,16 +112,13 @@ export async function renderToPdf(
// be in the PDF, which allows us to determine the necessary height to fit
// the page to the content. viewport height here is irrelevant, but we have to
// set something.
- const viewportHeight =
- // Viewport height can't be infinity
- height === Infinity ? PAPER_DIMENSIONS.Letter.height : height;
await page.setViewportSize({
// Noninteger values are not supported
width: Math.floor(
(width - horizontalMargin) * PLAYWRIGHT_PIXELS_PER_INCH
),
height: Math.floor(
- (viewportHeight - verticalMargin) * PLAYWRIGHT_PIXELS_PER_INCH
+ (height - verticalMargin) * PLAYWRIGHT_PIXELS_PER_INCH
),
});
@@ -175,15 +172,24 @@ export async function renderToPdf(
waitUntil: 'load',
});
+ const isLetterRoll = height === PAPER_DIMENSIONS.LetterRoll.height;
+
const contentHeight =
(await getContentHeight(page)) / PLAYWRIGHT_PIXELS_PER_INCH +
verticalMargin;
+
buffers.push(
await page.pdf({
path: outputPath,
width: inchesToText(width),
height: inchesToText(
- height === Infinity ? Math.max(viewportHeight, contentHeight) : height
+ /* if printing on a roll remove any unneeded height but never be smaller then a standard page */
+ isLetterRoll
+ ? Math.min(
+ Math.max(contentHeight, PAPER_DIMENSIONS.Letter.height),
+ height
+ )
+ : height
),
margin: {
top: inchesToText(marginDimensions.top),