mirror of
https://github.com/documenso/documenso.git
synced 2026-07-25 17:35:05 +10:00
fix: match cert and audit log page dimensions to source document (#2473)
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import type { PDFPage } from '@cantoo/pdf-lib';
|
||||
import type { PDF } from '@libpdf/core';
|
||||
|
||||
import { PDF_SIZE_A4_72PPI } from '../../constants/pdf';
|
||||
|
||||
const MIN_CERT_PAGE_WIDTH = 300;
|
||||
const MIN_CERT_PAGE_HEIGHT = 300;
|
||||
|
||||
/**
|
||||
* Gets the effective page size for PDF operations.
|
||||
@@ -16,3 +22,20 @@ export const getPageSize = (page: PDFPage) => {
|
||||
|
||||
return cropBox;
|
||||
};
|
||||
|
||||
export const getLastPageDimensions = (pdfDoc: PDF): { width: number; height: number } => {
|
||||
const lastPage = pdfDoc.getPage(pdfDoc.getPageCount() - 1);
|
||||
|
||||
if (!lastPage) {
|
||||
return PDF_SIZE_A4_72PPI;
|
||||
}
|
||||
|
||||
const width = Math.round(lastPage.width);
|
||||
const height = Math.round(lastPage.height);
|
||||
|
||||
if (width < MIN_CERT_PAGE_WIDTH || height < MIN_CERT_PAGE_HEIGHT) {
|
||||
return PDF_SIZE_A4_72PPI;
|
||||
}
|
||||
|
||||
return { width, height };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user