From de9c21b3de93175e131fd4ebb3f3af87a069dedd Mon Sep 17 00:00:00 2001 From: Omar Ahmed Hassan <98468609+omar-ahmed42@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:21:14 +0200 Subject: [PATCH] Fix: page break insertion functionality in Multi Tool (#2350) Fix page break insertion functionality - Page Break insertion functionality now successfully inserts page breaks upon request --- .../static/js/multitool/PdfContainer.js | 45 ++++--------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/src/main/resources/static/js/multitool/PdfContainer.js b/src/main/resources/static/js/multitool/PdfContainer.js index d87fd6cb5..1fa836c31 100644 --- a/src/main/resources/static/js/multitool/PdfContainer.js +++ b/src/main/resources/static/js/multitool/PdfContainer.js @@ -165,43 +165,14 @@ class PdfContainer { async addFilesBlank(nextSiblingElement) { - const pdfContent = ` - %PDF-1.4 - 1 0 obj - << /Type /Catalog /Pages 2 0 R >> - endobj - 2 0 obj - << /Type /Pages /Kids [3 0 R] /Count 1 >> - endobj - 3 0 obj - << /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] /Contents 5 0 R >> - endobj - 5 0 obj - << /Length 44 >> - stream - 0 0 0 595 0 842 re - W - n - endstream - endobj - xref - 0 6 - 0000000000 65535 f - 0000000010 00000 n - 0000000071 00000 n - 0000000121 00000 n - 0000000205 00000 n - 0000000400 00000 n - trailer - << /Size 6 /Root 1 0 R >> - startxref - 278 - %%EOF - `; - const blob = new Blob([pdfContent], { type: 'application/pdf' }); - const url = URL.createObjectURL(blob); - const file = new File([blob], "blank_page.pdf", { type: "application/pdf" }); - await this.addPdfFile(file, nextSiblingElement); + let doc = await PDFLib.PDFDocument.create(); + let docBytes = await doc.save(); + + const url = URL.createObjectURL(new Blob([docBytes], { type: 'application/pdf' })); + + const renderer = await this.toRenderer(url); + + await this.addPdfFile(renderer, doc, nextSiblingElement); }