mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-05 11:52:48 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98467f4809 | ||
|
|
151060204d | ||
|
|
3019195fe5 | ||
|
|
3673b6e434 | ||
|
|
ad915b7527 |
@@ -180,7 +180,7 @@ The easiest way to self-host is to download the pre-built distribution file from
|
||||
**Navigate to the extracted Folder:**
|
||||
```bash
|
||||
# Navigate to the extracted folder
|
||||
cd dist-1.6.2 # Replace with your version
|
||||
cd dist-1.7.3 # Replace with your version
|
||||
```
|
||||
|
||||
**Serve with Python:**
|
||||
|
||||
+2
-2
@@ -261,7 +261,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -331,7 +331,7 @@
|
||||
</footer>
|
||||
|
||||
<script type="module" src="src/js/utils/lucide-init.ts"></script>
|
||||
|
||||
<script type="module" src="src/version.ts"></script>
|
||||
<script type="module" src="src/js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+2
-2
@@ -133,7 +133,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -203,7 +203,7 @@
|
||||
</footer>
|
||||
|
||||
<script type="module" src="src/js/utils/lucide-init.ts"></script>
|
||||
|
||||
<script type="module" src="src/version.ts"></script>
|
||||
<script type="module" src="src/js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -319,7 +319,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -389,7 +389,7 @@
|
||||
</footer>
|
||||
|
||||
<script type="module" src="src/js/utils/lucide-init.ts"></script>
|
||||
|
||||
<script type="module" src="src/version.ts"></script>
|
||||
<script type="module" src="src/js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+3
-2
@@ -594,7 +594,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -664,8 +664,9 @@
|
||||
</footer>
|
||||
|
||||
<script type="module" src="src/js/utils/lucide-init.ts"></script>
|
||||
<script type="module" src="src/version.ts"></script>
|
||||
<script type="module" src="src/js/main.ts"></script>
|
||||
<script type="module" src="src/js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -35,6 +35,6 @@ http {
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header Cross-Origin-Opener-Policy "same-origin" always;
|
||||
add_header Cross-Origin-Embedder-Policy "require-corp" always;
|
||||
add_header Cross-Origin-Resource-Policy "cross-origin" always;
|
||||
}
|
||||
}
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "bento-pdf",
|
||||
"version": "1.6.2",
|
||||
"version": "1.7.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "bento-pdf",
|
||||
"version": "1.6.2",
|
||||
"version": "1.7.3",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fontsource/cedarville-cursive": "^5.2.7",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "bento-pdf",
|
||||
"private": true,
|
||||
"version": "1.7.3",
|
||||
"version": "1.7.4",
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
+2
-2
@@ -244,7 +244,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -313,7 +313,7 @@
|
||||
</div>
|
||||
</footer>
|
||||
<script type="module" src="src/js/utils/lucide-init.ts"></script>
|
||||
|
||||
<script type="module" src="src/version.ts"></script>
|
||||
<script type="module" src="src/js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
declare const coherentpdf: typeof import('../../src/types/coherentpdf.global').coherentpdf;
|
||||
|
||||
interface AddAttachmentsMessage {
|
||||
command: 'add-attachments';
|
||||
pdfBuffer: ArrayBuffer;
|
||||
attachmentBuffers: ArrayBuffer[];
|
||||
attachmentNames: string[];
|
||||
}
|
||||
|
||||
interface AddAttachmentsSuccessResponse {
|
||||
status: 'success';
|
||||
modifiedPDF: ArrayBuffer;
|
||||
}
|
||||
|
||||
interface AddAttachmentsErrorResponse {
|
||||
status: 'error';
|
||||
message: string;
|
||||
}
|
||||
|
||||
type AddAttachmentsResponse = AddAttachmentsSuccessResponse | AddAttachmentsErrorResponse;
|
||||
@@ -0,0 +1,69 @@
|
||||
self.importScripts('/coherentpdf.browser.min.js');
|
||||
|
||||
function addAttachmentsToPDFInWorker(pdfBuffer, attachmentBuffers, attachmentNames) {
|
||||
try {
|
||||
const uint8Array = new Uint8Array(pdfBuffer);
|
||||
|
||||
let pdf;
|
||||
try {
|
||||
pdf = coherentpdf.fromMemory(uint8Array, '');
|
||||
} catch (error) {
|
||||
self.postMessage({
|
||||
status: 'error',
|
||||
message: `Failed to load PDF. Error: ${error.message || error}`
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Add each attachment to the PDF
|
||||
for (let i = 0; i < attachmentBuffers.length; i++) {
|
||||
try {
|
||||
const attachmentData = new Uint8Array(attachmentBuffers[i]);
|
||||
const attachmentName = attachmentNames[i];
|
||||
|
||||
// Attach file at document level (page 0)
|
||||
coherentpdf.attachFileFromMemory(attachmentData, attachmentName, pdf);
|
||||
} catch (error) {
|
||||
console.warn(`Failed to attach file ${attachmentNames[i]}:`, error);
|
||||
self.postMessage({
|
||||
status: 'error',
|
||||
message: `Failed to attach file ${attachmentNames[i]}: ${error.message || error}`
|
||||
});
|
||||
coherentpdf.deletePdf(pdf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Save the modified PDF
|
||||
const modifiedBytes = coherentpdf.toMemory(pdf, false, false);
|
||||
coherentpdf.deletePdf(pdf);
|
||||
|
||||
const buffer = modifiedBytes.buffer.slice(
|
||||
modifiedBytes.byteOffset,
|
||||
modifiedBytes.byteOffset + modifiedBytes.byteLength
|
||||
);
|
||||
|
||||
self.postMessage({
|
||||
status: 'success',
|
||||
modifiedPDF: buffer
|
||||
}, [buffer]);
|
||||
|
||||
} catch (error) {
|
||||
self.postMessage({
|
||||
status: 'error',
|
||||
message: error instanceof Error
|
||||
? error.message
|
||||
: 'Unknown error occurred while adding attachments.'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
self.onmessage = (e) => {
|
||||
if (e.data.command === 'add-attachments') {
|
||||
addAttachmentsToPDFInWorker(
|
||||
e.data.pdfBuffer,
|
||||
e.data.attachmentBuffers,
|
||||
e.data.attachmentNames
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -1,10 +1,40 @@
|
||||
import { showLoader, hideLoader, showAlert } from '../ui';
|
||||
import { readFileAsArrayBuffer, downloadFile } from '../utils/helpers';
|
||||
import { state } from '../state';
|
||||
|
||||
const worker = new Worker('/workers/add-attachments.worker.js');
|
||||
|
||||
let attachments: File[] = [];
|
||||
|
||||
worker.onmessage = (e) => {
|
||||
const data = e.data;
|
||||
|
||||
if (data.status === 'success' && data.modifiedPDF !== undefined) {
|
||||
hideLoader();
|
||||
|
||||
downloadFile(
|
||||
new Blob([new Uint8Array(data.modifiedPDF)], { type: 'application/pdf' }),
|
||||
`attached-${state.files[0].name}`
|
||||
);
|
||||
|
||||
showAlert('Success', `${attachments.length} file(s) attached successfully.`);
|
||||
clearAttachments();
|
||||
} else if (data.status === 'error') {
|
||||
hideLoader();
|
||||
showAlert('Error', data.message || 'Unknown error occurred.');
|
||||
clearAttachments();
|
||||
}
|
||||
};
|
||||
|
||||
worker.onerror = (error) => {
|
||||
hideLoader();
|
||||
console.error('Worker error:', error);
|
||||
showAlert('Error', 'Worker error occurred. Check console for details.');
|
||||
clearAttachments();
|
||||
};
|
||||
|
||||
export async function addAttachments() {
|
||||
if (!state.pdfDoc) {
|
||||
if (!state.files || state.files.length === 0) {
|
||||
showAlert('Error', 'Main PDF is not loaded.');
|
||||
return;
|
||||
}
|
||||
@@ -15,37 +45,37 @@ export async function addAttachments() {
|
||||
|
||||
showLoader('Embedding files into PDF...');
|
||||
try {
|
||||
const pdfDoc = state.pdfDoc;
|
||||
const pdfFile = state.files[0];
|
||||
const pdfBuffer = (await readFileAsArrayBuffer(pdfFile)) as ArrayBuffer;
|
||||
|
||||
const attachmentBuffers: ArrayBuffer[] = [];
|
||||
const attachmentNames: string[] = [];
|
||||
|
||||
for (let i = 0; i < attachments.length; i++) {
|
||||
const file = attachments[i];
|
||||
showLoader(`Attaching ${file.name} (${i + 1}/${attachments.length})...`);
|
||||
|
||||
const fileBytes = await readFileAsArrayBuffer(file);
|
||||
|
||||
await pdfDoc.attach(fileBytes as ArrayBuffer, file.name, {
|
||||
mimeType: file.type || 'application/octet-stream',
|
||||
description: `Attached file: ${file.name}`,
|
||||
creationDate: new Date(),
|
||||
modificationDate: new Date(file.lastModified),
|
||||
});
|
||||
showLoader(`Reading ${file.name} (${i + 1}/${attachments.length})...`);
|
||||
|
||||
const fileBuffer = (await readFileAsArrayBuffer(file)) as ArrayBuffer;
|
||||
attachmentBuffers.push(fileBuffer);
|
||||
attachmentNames.push(file.name);
|
||||
}
|
||||
|
||||
const pdfBytes = await pdfDoc.save();
|
||||
downloadFile(
|
||||
new Blob([pdfBytes], { type: 'application/pdf' }),
|
||||
`attached-${state.files[0].name}`
|
||||
);
|
||||
showLoader('Attaching files to PDF...');
|
||||
|
||||
const message = {
|
||||
command: 'add-attachments',
|
||||
pdfBuffer: pdfBuffer,
|
||||
attachmentBuffers: attachmentBuffers,
|
||||
attachmentNames: attachmentNames
|
||||
};
|
||||
|
||||
const transferables = [pdfBuffer, ...attachmentBuffers];
|
||||
worker.postMessage(message, transferables);
|
||||
|
||||
showAlert(
|
||||
'Success',
|
||||
`${attachments.length} file(s) attached successfully.`
|
||||
);
|
||||
} catch (error: any) {
|
||||
console.error('Error attaching files:', error);
|
||||
showAlert('Error', `Failed to attach files: ${error.message}`);
|
||||
} finally {
|
||||
hideLoader();
|
||||
showAlert('Error', `Failed to attach files: ${error.message}`);
|
||||
clearAttachments();
|
||||
}
|
||||
}
|
||||
@@ -88,6 +118,11 @@ export function setupAddAttachmentsTool() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!state.files || state.files.length === 0) {
|
||||
console.error('No PDF file loaded for adding attachments.');
|
||||
return;
|
||||
}
|
||||
|
||||
optionsDiv.classList.remove('hidden');
|
||||
|
||||
attachmentInput.addEventListener('change', (e) => {
|
||||
|
||||
+6
-4
@@ -5,7 +5,7 @@ import { createIcons, icons } from 'lucide';
|
||||
import * as pdfjsLib from 'pdfjs-dist';
|
||||
import '../css/styles.css';
|
||||
import { formatStars } from './utils/helpers.js';
|
||||
import '../version.js';
|
||||
import { APP_VERSION, injectVersion } from '../version.js';
|
||||
|
||||
const init = () => {
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = new URL(
|
||||
@@ -29,9 +29,11 @@ const init = () => {
|
||||
simpleNav.innerHTML = `
|
||||
<div class="container mx-auto px-4">
|
||||
<div class="flex justify-start items-center h-16">
|
||||
<div class="flex-shrink-0 flex items-center">
|
||||
<div class="flex-shrink-0 flex items-center cursor-pointer" id="home-logo">
|
||||
<img src="images/favicon.svg" alt="Bento PDF Logo" class="h-8 w-8">
|
||||
<span class="text-white font-bold text-xl ml-2">BentoPDF</span>
|
||||
<span class="text-white font-bold text-xl ml-2">
|
||||
<a href="index.html">BentoPDF</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -95,7 +97,7 @@ const init = () => {
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version-simple">1.6.2</span>
|
||||
Version <span id="app-version-simple">${APP_VERSION}</span>
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -186,8 +186,9 @@
|
||||
</div>
|
||||
</footer>
|
||||
<script type="module" src="../js/utils/lucide-init.ts"></script>
|
||||
<script type="module" src="../version.ts"></script>
|
||||
<script type="module" src="../js/logic/add-stamps.ts"></script>
|
||||
<script type="module" src="../js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -420,7 +420,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -489,8 +489,9 @@
|
||||
</div>
|
||||
</footer>
|
||||
<script type="module" src="../js/utils/lucide-init.ts"></script>
|
||||
<script type="module" src="../version.ts"></script>
|
||||
<script type="module" src="../js/logic/bookmark-pdf.ts"></script>
|
||||
<script type="module" src="../js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -186,7 +186,8 @@
|
||||
</footer>
|
||||
<script type="module" src="../js/logic/json-to-pdf.ts"></script>
|
||||
<script type="module" src="../js/utils/lucide-init.ts"></script>
|
||||
<script type="module" src="../version.ts"></script>
|
||||
<script type="module" src="../js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -180,7 +180,8 @@
|
||||
</footer>
|
||||
<script type="module" src="../js/logic/pdf-to-json.ts"></script>
|
||||
<script type="module" src="../js/utils/lucide-init.ts"></script>
|
||||
<script type="module" src="../version.ts"></script>
|
||||
<script type="module" src="../js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
+2
-2
@@ -234,7 +234,7 @@
|
||||
© 2025 BentoPDF. All rights reserved.
|
||||
</p>
|
||||
<p class="text-gray-500 text-xs mt-2">
|
||||
Version <span id="app-version">1.7.3</span>
|
||||
Version <span id="app-version"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -303,7 +303,7 @@
|
||||
</div>
|
||||
</footer>
|
||||
<script type="module" src="src/js/utils/lucide-init.ts"></script>
|
||||
|
||||
<script type="module" src="src/version.ts"></script>
|
||||
<script type="module" src="src/js/mobileMenu.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user