Files
bentopdf/public/workers/table-of-contents.worker.js
abdullahalam123 1fe05ec59f ci: Improve Docker build workflow and update dependencies
- Add release type detection to distinguish between version tags and edge builds
- Implement separate Docker build steps for release and edge builds with appropriate tags
- Add edge and SHA-based image tags for main branch builds
- Update nginx configuration to support Vietnamese (vi) language routing
- Simplify nginx location block to handle static files and fallback to index.html
- Remove javascript-obfuscator and ts-migrate from dependencies
- Update README with simplified self-hosting instructions using npx http-server
- Consolidate multiple server setup examples into single recommended approach
- Update build preview command to use npm run preview instead of npx serve
- Improve localization files for German, English, Vietnamese, and Chinese
- Update worker files and TypeScript logic files for improved functionality
- Enhance PDF tool pages with better structure and internationalization support
2025-12-13 20:57:32 +05:30

63 lines
1.6 KiB
JavaScript

const baseUrl = self.location.href.substring(0, self.location.href.lastIndexOf('/workers/') + 1);
self.importScripts(baseUrl + 'coherentpdf.browser.min.js');
function generateTableOfContentsInWorker(
pdfData,
title,
fontSize,
fontFamily,
addBookmark
) {
try {
const uint8Array = new Uint8Array(pdfData);
const pdf = coherentpdf.fromMemory(uint8Array, '');
coherentpdf.startGetBookmarkInfo(pdf);
const bookmarkCount = coherentpdf.numberBookmarks();
coherentpdf.endGetBookmarkInfo();
if (bookmarkCount === 0) {
coherentpdf.deletePdf(pdf);
self.postMessage({
status: 'error',
message:
'This PDF does not have any bookmarks. Please add bookmarks first using the Bookmark tool.',
});
return;
}
coherentpdf.tableOfContents(pdf, fontFamily, fontSize, title, addBookmark);
const outputBytes = coherentpdf.toMemory(pdf, false, false);
const outputBytesBuffer = outputBytes.buffer;
coherentpdf.deletePdf(pdf);
self.postMessage(
{
status: 'success',
pdfBytes: outputBytesBuffer,
},
[outputBytesBuffer]
);
} catch (error) {
self.postMessage({
status: 'error',
message:
error instanceof Error
? error.message
: 'Unknown error occurred during table of contents generation.',
});
}
}
self.onmessage = (e) => {
if (e.data.command === 'generate-toc') {
generateTableOfContentsInWorker(
e.data.pdfData,
e.data.title,
e.data.fontSize,
e.data.fontFamily,
e.data.addBookmark
);
}
};