Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
chore: reduce memory and compress doc
Marc Seitz2fb484cd0f0e
diff --git a/pages/api/mupdf/convert-page.ts b/pages/api/mupdf/convert-page.tsindex c2a37c01..721f16f1 100644--- a/pages/api/mupdf/convert-page.ts+++ b/pages/api/mupdf/convert-page.ts@@ -53,12 +53,19 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {// Convert the response to a bufferconst pdfData = await response.arrayBuffer();// Create a MuPDF instance- var doc = mupdf.Document.openDocument(pdfData, "application/pdf");+ var doc = new mupdf.PDFDocument(pdfData);+ console.log("Original document size:", pdfData.byteLength);++ // compress the pdf+ var pdfDoc = doc.saveToBuffer("compress=true,linearize=true,garbage=true");+ console.log("Compressed document size:", pdfDoc.getLength());++ var newDoc = new mupdf.PDFDocument(pdfDoc);// Scale the document to 300 DPIconst doc_to_screen = mupdf.Matrix.scale(216 / 72, 216 / 72); // scale 3x // to 216 DPI- let page = doc.loadPage(pageNumber - 1); // 0-based page index+ let page = newDoc.loadPage(pageNumber - 1); // 0-based page indexif (pageNumber === 1) {// get the orientation of the document and update document versiondiff --git a/vercel.json b/vercel.jsonindex 0e81476c..9a5af153 100644--- a/vercel.json+++ b/vercel.json@@ -1,7 +1,7 @@{"functions": {"pages/api/mupdf/convert-page.ts": {- "memory": 3009+ "memory": 2048}}}