diff --git a/package-lock.json b/package-lock.json index 53a3a59..4693f9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,8 +37,6 @@ "@types/node-forge": "^1.3.14", "@types/papaparse": "^5.5.2", "archiver": "^7.0.1", - "bentopdf-pdfium": "file:vendor/bentopdf-pdfium/bentopdf-pdfium-3f6b6114b166.tgz", - "bentopdf-viewer": "file:vendor/bentopdf-viewer/bentopdf-viewer-3f6b6114b166.tgz", "blob-stream": "^0.1.3", "bwip-js": "^4.8.0", "cropperjs": "^1.6.2", @@ -48,7 +46,6 @@ "heic2any": "^0.0.4", "highlight.js": "^11.12.0", "html2canvas": "^1.4.1", - "hyper-compress-wasm": "file:vendor/hyper-compress-wasm/hyper-compress-wasm-1.0.3.tgz", "i18next": "^25.8.13", "i18next-browser-languagedetector": "^8.2.1", "i18next-http-backend": "^4.0.2", @@ -4528,22 +4525,6 @@ ], "license": "MIT" }, - "node_modules/bentopdf-pdfium": { - "version": "0.0.0-3f6b6114b166", - "resolved": "file:vendor/bentopdf-pdfium/bentopdf-pdfium-3f6b6114b166.tgz", - "integrity": "sha512-KedXrcBtrLgR9JMWi9odfz+oMeOHPcPWvn9fevOaNAZA6eMmYOYUOT3EzZeZVqytX7GoZ5A63nuYuPSrBUJfCw==", - "license": "AGPL-3.0" - }, - "node_modules/bentopdf-viewer": { - "version": "2.9.1", - "resolved": "file:vendor/bentopdf-viewer/bentopdf-viewer-3f6b6114b166.tgz", - "integrity": "sha512-2sL3JXDeHW5MID3Hw3zxdMjkzMgoPNiERarAsjiJ+w8j2hd6sK7o4gkn0KuEPkgIxwuH3RSlRatqG7fxcNDKpA==", - "license": "MIT", - "dependencies": { - "preact": "^10.17.0", - "tailwind-merge": "^3.4.0" - } - }, "node_modules/bidi-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/bidi-js/-/bidi-js-1.0.3.tgz", @@ -7244,15 +7225,6 @@ "url": "https://github.com/sponsors/typicode" } }, - "node_modules/hyper-compress-wasm": { - "version": "1.0.3", - "resolved": "file:vendor/hyper-compress-wasm/hyper-compress-wasm-1.0.3.tgz", - "integrity": "sha512-utOyNU/cTtMlCe+ik1ggYcuvINy8K4nDBHMA7VVeKTQlM0tWMJVWvY93R345sNOa49tr3nEeCDgGoNpp43ZQUQ==", - "license": "AGPL-3.0-only", - "engines": { - "node": ">=22" - } - }, "node_modules/i18next": { "version": "25.10.2", "resolved": "https://registry.npmjs.org/i18next/-/i18next-25.10.2.tgz", diff --git a/package.json b/package.json index 533f5b9..fb75cf4 100644 --- a/package.json +++ b/package.json @@ -101,8 +101,6 @@ "@types/node-forge": "^1.3.14", "@types/papaparse": "^5.5.2", "archiver": "^7.0.1", - "bentopdf-pdfium": "file:vendor/bentopdf-pdfium/bentopdf-pdfium-3f6b6114b166.tgz", - "bentopdf-viewer": "file:vendor/bentopdf-viewer/bentopdf-viewer-3f6b6114b166.tgz", "blob-stream": "^0.1.3", "bwip-js": "^4.8.0", "cropperjs": "^1.6.2", @@ -112,7 +110,6 @@ "heic2any": "^0.0.4", "highlight.js": "^11.12.0", "html2canvas": "^1.4.1", - "hyper-compress-wasm": "file:vendor/hyper-compress-wasm/hyper-compress-wasm-1.0.3.tgz", "i18next": "^25.8.13", "i18next-browser-languagedetector": "^8.2.1", "i18next-http-backend": "^4.0.2", diff --git a/simple-index.html b/simple-index.html index cd6140b..3a97da1 100644 --- a/simple-index.html +++ b/simple-index.html @@ -69,191 +69,4 @@ -
- -
-

- PDF Tools -

-

- Select a tool to get started -

-
- -
-
-
- - - - - - - - -
-
- -
-
- - - - - - - - - - - {{> settings-modal }} - - - {{> warning-modal }} - - - - - -
- - - - - - - - - - +

PDF 图片工具站

文件仅在浏览器内处理,不上传。请保留原件;大文件可能受设备内存限制。当前仅提供 JPG/PNG 转 PDF、完整文件合并、拆分与 PNG 导出。压缩、Office、OCR、签名和编辑未开放。

图片转 PDF合并 PDF拆分 PDFPDF 转 PNG
\ No newline at end of file diff --git a/src/js/i18n/i18n.ts b/src/js/i18n/i18n.ts index 4307b74..3217c36 100644 --- a/src/js/i18n/i18n.ts +++ b/src/js/i18n/i18n.ts @@ -83,7 +83,7 @@ export const getLanguageFromUrl = (): SupportedLanguage => { return langMatch[1] as SupportedLanguage; } - return 'en'; + return 'zh'; }; export const LANGUAGE_CHOICE_KEY = 'bentopdf-language'; diff --git a/src/js/logic/image-to-pdf-page.ts b/src/js/logic/image-to-pdf-page.ts index 82e6dbe..258fda8 100644 --- a/src/js/logic/image-to-pdf-page.ts +++ b/src/js/logic/image-to-pdf-page.ts @@ -6,7 +6,7 @@ import { enableFileListReorder, moveItem, } from '@/js/utils/sortable-file-list.js'; -import { loadPyMuPDF } from '@/js/utils/pymupdf-loader.js'; +import { convertImagesToPdfFile } from '@/js/utils/images-to-pdf-lib.js'; import type { PyMuPDFInstance } from '@/types'; import { getSelectedQuality, @@ -175,12 +175,6 @@ function updateUI() { } } -async function ensurePyMuPDF(): Promise { - if (!pymupdf) { - pymupdf = (await loadPyMuPDF()) as PyMuPDFInstance; - } - return pymupdf; -} async function convertToPdf() { if (files.length === 0) { @@ -205,10 +199,10 @@ async function convertToPdf() { } showLoader('Loading engine...'); - const mupdf = await ensurePyMuPDF(); + showLoader('Converting images to PDF...'); - const pdfBlob = await mupdf.imagesToPdf(processedFiles); + const pdfBlob = await convertImagesToPdfFile(processedFiles); downloadFile(pdfBlob, 'images_to_pdf.pdf'); diff --git a/src/js/logic/merge-pdf-page.ts b/src/js/logic/merge-pdf-page.ts index 7333139..551e083 100644 --- a/src/js/logic/merge-pdf-page.ts +++ b/src/js/logic/merge-pdf-page.ts @@ -7,11 +7,8 @@ import { cleanupLazyRendering, } from '../utils/render-utils.js'; import { initPagePreview } from '../utils/page-preview.js'; -import { isCpdfAvailable } from '../utils/cpdf-helper.js'; -import { - showWasmRequiredDialog, - WasmProvider, -} from '../utils/wasm-provider.js'; +const isCpdfAvailable = () => true; +const showWasmRequiredDialog = (_:string) => {}; import { t, trText, onPageReady } from '../i18n/i18n'; import { createIcons, icons } from 'lucide'; @@ -45,9 +42,18 @@ const mergeState: MergeState = { mergeSuccess: false, }; -const mergeWorker = new Worker( - import.meta.env.BASE_URL + 'workers/merge.worker.js' -); +// Modified subset: run upstream mergePdfs on main thread (helper module uses DOM). +import { mergePdfs } from '../utils/pdf-operations.js'; +const mergeWorker: any = { + onmessage: null, onerror:null, + postMessage: async ({files,jobs}: any) => { + try { + if(jobs.some((j:any)=>j.rangeType!=='all'))throw new Error('仅支持完整文件合并'); + const bytes=await mergePdfs(jobs.map((j:any)=>new Uint8Array(files.find((f:any)=>f.name===j.fileName).data))); + mergeWorker.onmessage?.({data:{status:'success',pdfBytes:bytes.buffer}}); + } catch(e){mergeWorker.onmessage?.({data:{status:'error',message:String(e)}});} + }, terminate:()=>{} +}; function initializeFileListSortable() { const fileList = document.getElementById('file-list'); @@ -397,7 +403,7 @@ export async function merge() { command: 'merge', files: filesToMerge, jobs: jobs, - cpdfUrl: WasmProvider.getUrl('cpdf')! + 'coherentpdf.browser.min.js', + cpdfUrl: '', retainPageLabels: retainCheckbox?.checked ?? false, removeDuplicateFonts: removeDuplicateFontsCheckbox?.checked ?? false, }; @@ -521,7 +527,7 @@ export async function refreshMergeUI() { rangeDiv.className = 'mt-2 flex items-center gap-2'; const inputWrapper = document.createElement('div'); - inputWrapper.className = 'flex-1'; + inputWrapper.className = 'hidden'; const label = document.createElement('label'); label.htmlFor = `range-${safeFileName}`; diff --git a/src/js/logic/split-pdf-page.ts b/src/js/logic/split-pdf-page.ts index 7031707..03d0a38 100644 --- a/src/js/logic/split-pdf-page.ts +++ b/src/js/logic/split-pdf-page.ts @@ -1,3 +1,4 @@ +import { splitPdf } from '../utils/pdf-operations.js'; import { showLoader, hideLoader, showAlert } from '../ui.js'; import { t, trText, onPageReady } from '../i18n/i18n'; import { createIcons, icons } from 'lucide'; @@ -15,8 +16,8 @@ import { cleanupLazyRendering, } from '../utils/render-utils.js'; import { initPagePreview } from '../utils/page-preview.js'; -import { isCpdfAvailable } from '../utils/cpdf-helper.js'; -import { showWasmRequiredDialog } from '../utils/wasm-provider.js'; +const isCpdfAvailable = () => true; +const showWasmRequiredDialog = (_:string) => {}; import JSZip from 'jszip'; import { loadPdfDocument } from '../utils/load-pdf-document.js'; import type { QpdfInstanceExtended } from '@/types'; @@ -332,18 +333,7 @@ onPageReady(() => { return sourceBytes; }; - const ensureQpdf = async (): Promise => { - if (qpdf) return qpdf; - const instance = await initializeQpdf(); - instance.FS.writeFile(inputPath, await getSourceBytes()); - qpdf = instance; - return instance; - }; - - const extractPages = async (indices: number[]): Promise => { - const instance = await ensureQpdf(); - return extractPagesWithQpdf(instance, inputPath, indices); - }; + const extractPages = async (indices:number[]):Promise => splitPdf(await getSourceBytes(),indices); switch (splitMode) { case 'range': { @@ -382,61 +372,7 @@ onPageReady(() => { if (oneFilePerUnit) outputGroups = [...new Set(indicesToExtract)].map((i) => [i]); break; - case 'bookmarks': { - if (!isCpdfAvailable()) { - showWasmRequiredDialog('cpdf'); - hideLoader(); - return; - } - const { getCpdf } = await import('../utils/cpdf-helper.js'); - const cpdf = await getCpdf(); - const pdf = cpdf.fromMemory( - new Uint8Array(await getSourceBytes()), - '' - ); - - cpdf.startGetBookmarkInfo(pdf); - const bookmarkCount = cpdf.numberBookmarks(); - const bookmarkLevel = ( - document.getElementById('bookmark-level') as HTMLSelectElement - )?.value; - - const splitPages: number[] = []; - for (let i = 0; i < bookmarkCount; i++) { - const level = cpdf.getBookmarkLevel(i); - const page = cpdf.getBookmarkPage(pdf, i); - - if (bookmarkLevel === 'all' || level === parseInt(bookmarkLevel)) { - if (page > 1 && !splitPages.includes(page - 1)) { - splitPages.push(page - 1); - } - } - } - cpdf.endGetBookmarkInfo(); - cpdf.deletePdf(pdf); - - if (splitPages.length === 0) { - throw new Error( - trText('No bookmarks found at the selected level.') - ); - } - - const zip = new JSZip(); - const bookmarkGroups = bookmarkSplitGroups(splitPages, totalPages); - - for (let i = 0; i < bookmarkGroups.length; i++) { - const pdfBytes2 = await extractPages(bookmarkGroups[i]); - zip.file(`split-${i + 1}.pdf`, pdfBytes2); - } - - const zipBlob = await zip.generateAsync({ type: 'blob' }); - downloadFile(zipBlob, 'split-by-bookmarks.zip'); - hideLoader(); - showAlert('Success', 'PDF split successfully!', 'success', () => { - resetState(); - }); - return; - } + case 'bookmarks': throw new Error('本版本未开放书签拆分'); case 'n-times': { const nValue = parseInt( diff --git a/src/js/utils/helpers.ts b/src/js/utils/helpers.ts index fb421a4..6843ae9 100644 --- a/src/js/utils/helpers.ts +++ b/src/js/utils/helpers.ts @@ -1,4 +1,4 @@ -import createModule from '@neslinesli93/qpdf-wasm'; + import type { QpdfInstanceExtended } from '@/types'; import { showLoader, hideLoader, showAlert } from '../ui.js'; import { createIcons } from 'lucide'; @@ -167,27 +167,7 @@ let qpdfInstance: QpdfInstanceExtended | null = null; * Initialize qpdf-wasm singleton. * Subsequent calls return the same instance. */ -export async function initializeQpdf(): Promise { - if (qpdfInstance) return qpdfInstance; - - showLoader('Initializing PDF engine...'); - try { - qpdfInstance = (await createModule({ - locateFile: () => import.meta.env.BASE_URL + 'qpdf.wasm', - })) as unknown as QpdfInstanceExtended; - } catch (error) { - console.error('Failed to initialize qpdf-wasm:', error); - showAlert( - 'Initialization Error', - 'Could not load the PDF engine. Please refresh the page and try again.' - ); - throw error; - } finally { - hideLoader(); - } - - return qpdfInstance; -} +export async function initializeQpdf(): Promise { throw new Error('当前子集不提供 qpdf 引擎'); } export function initializeIcons(): void { createIcons({ diff --git a/src/js/utils/image-input-utils.ts b/src/js/utils/image-input-utils.ts index 40fb629..14400e0 100644 --- a/src/js/utils/image-input-utils.ts +++ b/src/js/utils/image-input-utils.ts @@ -1,117 +1,7 @@ -import heic2any from 'heic2any'; - -import { trText } from '../i18n/i18n.js'; - -export const IMAGE_EXTENSIONS = [ - '.jpg', - '.jpeg', - '.png', - '.bmp', - '.gif', - '.tiff', - '.tif', - '.pnm', - '.pgm', - '.pbm', - '.ppm', - '.pam', - '.jxr', - '.jpx', - '.jp2', - '.psd', - '.svg', - '.heic', - '.heif', - '.webp', -] as const; - -// TODO@alam00000: Implement image resolution -export const IMAGE_ACCEPT = IMAGE_EXTENSIONS.join(','); - -export const IMAGE_FORMATS_LABEL = - 'JPG, PNG, BMP, GIF, TIFF, PNM, PGM, PBM, PPM, PAM, JXR, JPX, JP2, PSD, SVG, HEIC, WebP'; - -export function getFileExtension(filename: string): string { - const dot = filename.lastIndexOf('.'); - return dot === -1 ? '' : filename.slice(dot).toLowerCase(); -} - -export function isValidImageFile(file: File): boolean { - const ext = getFileExtension(file.name); - if ((IMAGE_EXTENSIONS as readonly string[]).includes(ext)) { - return true; - } - return file.type.startsWith('image/'); -} - -export async function preprocessImageFile(file: File): Promise { - const ext = getFileExtension(file.name); - - if (ext === '.heic' || ext === '.heif') { - try { - const conversionResult = await heic2any({ - blob: file, - toType: 'image/png', - quality: 0.9, - }); - const blob = Array.isArray(conversionResult) - ? conversionResult[0] - : conversionResult; - return new File([blob], file.name.replace(/\.(heic|heif)$/i, '.png'), { - type: 'image/png', - }); - } catch (cause) { - console.error(`Failed to convert HEIC: ${file.name}`, cause); - throw new Error( - trText('Failed to process HEIC file: {{name}}', { name: file.name }), - { cause } - ); - } - } - - if (ext === '.webp') { - try { - return await new Promise((resolve, reject) => { - const img = new Image(); - const url = URL.createObjectURL(file); - img.onload = () => { - const canvas = document.createElement('canvas'); - canvas.width = img.width; - canvas.height = img.height; - const ctx = canvas.getContext('2d'); - if (!ctx) { - URL.revokeObjectURL(url); - reject(new Error(trText('Canvas context failed'))); - return; - } - ctx.drawImage(img, 0, 0); - canvas.toBlob((blob) => { - URL.revokeObjectURL(url); - if (blob) { - resolve( - new File([blob], file.name.replace(/\.webp$/i, '.png'), { - type: 'image/png', - }) - ); - } else { - reject(new Error(trText('Canvas toBlob failed'))); - } - }, 'image/png'); - }; - img.onerror = () => { - URL.revokeObjectURL(url); - reject(new Error(trText('Failed to load WebP image'))); - }; - img.src = url; - }); - } catch (cause) { - console.error(`Failed to convert WebP: ${file.name}`, cause); - throw new Error( - trText('Failed to process WebP file: {{name}}', { name: file.name }), - { cause } - ); - } - } - - return file; -} +// Modified subset: PNG/JPEG only. No bundled HEIC native codecs. +export const IMAGE_EXTENSIONS=['.jpg','.jpeg','.png'] as const; +export const IMAGE_ACCEPT=IMAGE_EXTENSIONS.join(','); +export const IMAGE_FORMATS_LABEL='JPG, PNG'; +export function getFileExtension(n:string){return n.slice(n.lastIndexOf('.')).toLowerCase();} +export function isValidImageFile(f:File){return IMAGE_EXTENSIONS.includes(getFileExtension(f.name) as any);} +export async function preprocessImageFile(f:File){if(!isValidImageFile(f))throw new Error('仅支持 JPG、PNG');return f;} diff --git a/src/js/utils/load-pdf-document.ts b/src/js/utils/load-pdf-document.ts index a5d6386..9ac6764 100644 --- a/src/js/utils/load-pdf-document.ts +++ b/src/js/utils/load-pdf-document.ts @@ -6,44 +6,7 @@ import { trText } from '../i18n/i18n.js'; type LoadOptions = Parameters[1]; type PDFDocumentInstance = Awaited>; -async function runQpdf( - pdf: Uint8Array, - args: string[] -): Promise { - try { - const qpdf = await initializeQpdf(); - qpdf.FS.writeFile('/input.pdf', pdf); - - try { - qpdf.callMain(['/input.pdf', ...args, '/output.pdf']); - } catch (e) { - console.warn('[loadPdfDocument] qpdf repair warning:', e); - } - - let repaired: Uint8Array | null = null; - try { - repaired = qpdf.FS.readFile('/output.pdf', { encoding: 'binary' }); - } catch (e) { - console.warn('[loadPdfDocument] Failed to read repaired output:', e); - } - - try { - qpdf.FS.unlink('/input.pdf'); - } catch (e) { - console.warn('[loadPdfDocument] Cleanup error:', e); - } - try { - qpdf.FS.unlink('/output.pdf'); - } catch (e) { - console.warn('[loadPdfDocument] Cleanup error:', e); - } - - return repaired; - } catch (e) { - console.warn('[loadPdfDocument] qpdf not available for repair:', e); - return null; - } -} +async function runQpdf(_pdf:Uint8Array,_args:string[]):Promise{return null;} function repairPdfBytes(pdf: Uint8Array): Promise { return runQpdf(pdf, ['--decrypt']); @@ -67,7 +30,7 @@ export async function loadPdfDocument( options?: LoadOptions ): Promise { const loadOpts = { - ignoreEncryption: true, + ignoreEncryption: false, throwOnInvalidObject: false, ...options, }; diff --git a/src/js/utils/pdf-decrypt.ts b/src/js/utils/pdf-decrypt.ts index fe71486..034848b 100644 --- a/src/js/utils/pdf-decrypt.ts +++ b/src/js/utils/pdf-decrypt.ts @@ -1,177 +1,6 @@ -import { getCpdf, isCpdfAvailable } from './cpdf-helper'; -import { isPyMuPDFAvailable, loadPyMuPDF } from './pymupdf-loader'; -import type { CpdfInstance } from '@/types'; - -import { trText } from '../i18n/i18n.js'; - -export type PdfDecryptEngine = 'cpdf' | 'pymupdf'; - -export interface PdfDecryptResult { - bytes: Uint8Array; - engine: PdfDecryptEngine; -} - -const DECRYPT_LOG_PREFIX = '[PDF Decrypt]'; - -function getErrorMessage(error: unknown): string { - if (error instanceof Error && error.message) { - return error.message; - } - - return String(error); -} - -function normalizeErrorMessage(error: unknown): string { - const message = getErrorMessage(error).trim(); - const cpdfReasonMatch = message.match(/Pdf\.PDFError\("([^"]+)"\)/); - if (cpdfReasonMatch?.[1]) { - return cpdfReasonMatch[1]; - } - - const trailingErrorMatch = message.match(/ERROR:\s*[^:]+:\s*(.+)$/); - if (trailingErrorMatch?.[1]) { - return trailingErrorMatch[1].trim(); - } - - return message; -} - -function copyBytes(bytes: Uint8Array): Uint8Array { - return Uint8Array.from(bytes); -} - -function cleanupCpdfDocument(cpdf: CpdfInstance, pdf: unknown): void { - if (!cpdf || !pdf) { - return; - } - - try { - cpdf.deletePdf(pdf); - } catch (cleanupError) { - console.warn( - `${DECRYPT_LOG_PREFIX} Failed to cleanup CoherentPDF document: ${normalizeErrorMessage(cleanupError)}` - ); - } -} - -async function decryptWithCpdf( - inputBytes: Uint8Array, - password: string -): Promise { - const cpdf = await getCpdf(); - cpdf.setSlow(); - - let pdf: unknown | null = null; - - try { - pdf = cpdf.fromMemory(new Uint8Array(inputBytes), password); - - if (cpdf.isEncrypted(pdf)) { - try { - cpdf.decryptPdf(pdf, password); - } catch { - cpdf.decryptPdfOwner(pdf, password); - } - } - - const outputBytes = cpdf.toMemory(pdf, false, false); - pdf = null; - - if (!(outputBytes instanceof Uint8Array) || outputBytes.length === 0) { - throw new Error(trText('CoherentPDF produced an empty decrypted file.')); - } - - return copyBytes(outputBytes); - } catch (error) { - if (pdf) { - cleanupCpdfDocument(cpdf, pdf); - } - - throw new Error(normalizeErrorMessage(error), { cause: error }); - } -} - -async function decryptWithPyMuPDF( - inputBytes: Uint8Array, - password: string -): Promise { - const pymupdf = await loadPyMuPDF(); - const document = await pymupdf.open( - new Blob([new Uint8Array(inputBytes)], { type: 'application/pdf' }) - ); - - try { - if (document.needsPass || document.isEncrypted) { - const authenticated = document.authenticate(password); - if (!authenticated) { - const error = new Error(trText('Invalid PDF password.')); - error.name = 'PasswordError'; - throw error; - } - } - - const outputBytes = document.save(); - if (!(outputBytes instanceof Uint8Array) || outputBytes.length === 0) { - throw new Error(trText('PyMuPDF produced an empty decrypted file.')); - } - - return copyBytes(outputBytes); - } finally { - document.close(); - } -} - -export async function decryptPdfBytes( - inputBytes: Uint8Array, - password: string -): Promise { - const errors: string[] = []; - - if (isCpdfAvailable()) { - console.info(`${DECRYPT_LOG_PREFIX} Trying CoherentPDF decryption`); - try { - const result: PdfDecryptResult = { - bytes: await decryptWithCpdf(inputBytes, password), - engine: 'cpdf', - }; - console.info( - `${DECRYPT_LOG_PREFIX} Decryption succeeded with CoherentPDF` - ); - return result; - } catch (error) { - const errorMessage = normalizeErrorMessage(error); - console.warn( - `${DECRYPT_LOG_PREFIX} Decryption with CoherentPDF failed. Falling back to PyMuPDF. Reason: ${errorMessage}` - ); - errors.push(`CoherentPDF: ${errorMessage}`); - } - } else { - console.info( - `${DECRYPT_LOG_PREFIX} CoherentPDF is not configured, skipping to PyMuPDF` - ); - errors.push(trText('CoherentPDF: not configured.')); - } - - if (isPyMuPDFAvailable()) { - console.info(`${DECRYPT_LOG_PREFIX} Trying PyMuPDF decryption`); - try { - const result: PdfDecryptResult = { - bytes: await decryptWithPyMuPDF(inputBytes, password), - engine: 'pymupdf', - }; - console.info(`${DECRYPT_LOG_PREFIX} Decryption succeeded with PyMuPDF`); - return result; - } catch (error) { - const errorMessage = normalizeErrorMessage(error); - console.warn( - `${DECRYPT_LOG_PREFIX} PyMuPDF decryption failed: ${errorMessage}` - ); - errors.push(`PyMuPDF: ${errorMessage}`); - } - } else { - console.warn(`${DECRYPT_LOG_PREFIX} PyMuPDF is not configured`); - errors.push(trText('PyMuPDF: not configured.')); - } - - throw new Error(errors.join('\n')); +// Modified public subset: encrypted inputs are not accepted; no fallback CDN engine. +export type PdfDecryptEngine = 'unsupported'; +export interface PdfDecryptResult {bytes:Uint8Array;engine:PdfDecryptEngine;} +export async function decryptPdfBytes(_input:Uint8Array,_password:string):Promise{ + throw new Error('当前版本不支持加密 PDF,请先在可信软件中解密后重试。'); } diff --git a/src/js/utils/wasm-provider.ts b/src/js/utils/wasm-provider.ts index c99bed2..b51c733 100644 --- a/src/js/utils/wasm-provider.ts +++ b/src/js/utils/wasm-provider.ts @@ -10,9 +10,9 @@ interface WasmProviderConfig { const STORAGE_KEY = 'bentopdf:wasm-providers'; const CDN_DEFAULTS: Record = { - pymupdf: 'https://cdn.jsdelivr.net/npm/@bentopdf/pymupdf-wasm@0.11.16/', + pymupdf: '/vendor/pymupdf-0.11.16/', ghostscript: 'https://cdn.jsdelivr.net/npm/@bentopdf/gs-wasm@0.1.1/assets/', - cpdf: 'https://cdn.jsdelivr.net/npm/coherentpdf@2.5.5/dist/', + cpdf: '/vendor/coherentpdf-2.5.5/', }; function envOrDefault(envVar: string | undefined, fallback: string): string { @@ -130,7 +130,7 @@ class WasmProviderManager { } private getEnvDefault(packageName: WasmPackage): string | undefined { - return ENV_DEFAULTS[packageName]; + return new URL(ENV_DEFAULTS[packageName], location.origin).href; } private saveConfig(): void { @@ -142,7 +142,7 @@ class WasmProviderManager { } getUrl(packageName: WasmPackage): string | undefined { - const stored = this.config[packageName]; + const stored = undefined; if (stored) { if (this.isTrustedUrl(stored)) return stored; console.warn( diff --git a/src/pages/compress-pdf.html b/src/pages/compress-pdf.html index 4b8d2e7..402fe3a 100644 --- a/src/pages/compress-pdf.html +++ b/src/pages/compress-pdf.html @@ -1,5 +1,5 @@ - + @@ -27,40 +27,25 @@ /> - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + @@ -95,7 +80,7 @@ - {{> navbar }} +
- {{> footer }} - - - + + + + - - + + - + - + - - + + diff --git a/src/pages/image-to-pdf.html b/src/pages/image-to-pdf.html index fcdc96d..2974fa7 100644 --- a/src/pages/image-to-pdf.html +++ b/src/pages/image-to-pdf.html @@ -1,5 +1,5 @@ - + @@ -11,7 +11,7 @@ /> @@ -21,40 +21,25 @@ /> - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + @@ -92,7 +77,7 @@ - {{> navbar }} +
Images to PDF -

- Convert JPG, PNG, BMP, GIF, TIFF, PNM, PGM, PBM, PPM, PAM, JXR, JPX, - JP2, PSD, SVG, HEIC, WebP to PDF. +

+ 将 JPG、PNG 图片转换为 PDF。

-
-

- How It Works -

-
-
-
- 1 -
-
-

Upload File

-

- Click or drag and drop your file to begin -

-
-
-
-
- 2 -
-
-

Process

-

- Click the process button to start -

-
-
-
-
- 3 -
-
-

Download

-

- Save your processed file instantly -

-
-
-
-
+ -
-

- Related PDF Tools -

- -
+ -
-

- Frequently Asked Questions -

-
-
- - Which image formats can I combine into a PDF? - - -

- JPG, JPEG, PNG, BMP, GIF, TIFF, PNM, PGM, PBM, PPM, PAM, JXR, JPX, - JP2, PSD, SVG, HEIC, HEIF, and WebP. You can mix formats in one - batch, and each image becomes its own page in a single - images_to_pdf.pdf file. -

-
-
- - What do the High, Medium, and Low quality settings change? - - -

- High Quality embeds your images as they are, with no resizing or - re-encoding. Medium re-encodes each image as a JPEG at 75% quality - and caps the longest side at 2500 pixels, and Low uses 50% quality - with a 1500 pixel cap, which gives much smaller files for email. -

-
-
- - Will transparent PNGs keep their transparency? - - -

- Only at High Quality, where files are embedded untouched. Medium and - Low convert every image to JPEG, which has no alpha channel, so - transparent areas are flattened rather than kept. -

-
-
- - How do I control the page order? - - -

- Pages follow the order of the file list, which is the order you - selected or dropped the images. To change it, remove an image with - the trash icon and add it again with Add More Files so it goes to - the end. -

-
-
- - Can I set the page size to A4 or Letter? - - -

- Not in this tool. Each page takes the dimensions of its image, so a - tall phone photo produces a tall page and a landscape scan a wide - one. If you need uniform paper sizes afterward, run the result - through - Fix Page Size. -

-
-
- - Do iPhone HEIC photos need converting first? - - -

- No. HEIC and HEIF files are decoded in the browser and turned into - PNG before they're embedded, and WebP is handled the same way. This - happens automatically and doesn't need an extra step. -

-
-
- - Are my photos uploaded anywhere? - - -

- No. Decoding, compression, and PDF assembly all run in your browser, - so the images never leave your device. Large batches of - full-resolution photos take longer and use more memory on your - machine because of that. -

-
-
- - Is there a separate tool if all my images are JPGs? - - -

- JPG to PDF - gives the same result with a simpler interface, and there are - dedicated PNG, HEIC, WebP, and TIFF converters as well. This tool is - the one to reach for when your files are in mixed or less common - formats such as PSD, JXR, or PNM. -

-
-
-
- {{> footer }} - - - + + + + + - - + + - + - + - - + + diff --git a/src/pages/merge-pdf.html b/src/pages/merge-pdf.html index 1a7c3d9..b637feb 100644 --- a/src/pages/merge-pdf.html +++ b/src/pages/merge-pdf.html @@ -1,5 +1,5 @@ - + @@ -27,40 +27,25 @@ /> - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + @@ -95,7 +80,7 @@ - {{> navbar }} +
-
-

- How It Works -

-
-
-
- 1 -
-
-

Upload PDFs

-

- Select or drag and drop multiple PDF files you want to merge -

-
-
-
-
- 2 -
-
-

Arrange Order

-

- Drag files up or down to reorder them in your preferred sequence -

-
-
-
-
- 3 -
-
-

Merge Files

-

- Click the merge button to combine all PDFs into a single document -

-
-
-
-
- 4 -
-
-

Download

-

- Save your merged PDF - all pages combined in the order you chose -

-
-
-
-
+ -
-

- Related PDF Tools -

- -
+ -
-

- Frequently Asked Questions -

-
-
- - Does merging keep bookmarks? - - -

- Yes. The merge is done with the CoherentPDF engine, which carries - each file's bookmarks into the combined document so the outline - stays navigable. Page content and annotations are copied as they - are. -

-
-
- - Can I merge only some pages from each file? - - -

- Yes. In File Mode, type a range such as 1-3, 5 in the Pages box next - to a file to include just those pages, or leave it blank for the - whole file. In Page Mode every page from every file appears as a - thumbnail you can drag into any sequence, including interleaving - pages from different documents. -

-
-
- - What order will the files be in? - - -

- The order shown in the list, top to bottom. Drag entries to - rearrange them before merging, and use Add More Files to append - documents without losing the arrangement you already have. -

-
-
- - Why do page numbers look wrong in the merged PDF? - - -

- By default the merged file uses plain numbering from 1 to N. If the - originals used page labels such as i, ii, iii or A-1, turn on Keep - original page labels to preserve them, keeping in mind that two - files with the same labels will produce duplicates. To print visible - numbers on the pages themselves, use - Page Numbers. -

-
-
- - Why is the merged file so large? - - -

- Each file's fonts and images are copied as they are, so the result - is roughly the combined size of the inputs, and when several files - embed the same font each copy is kept. Check Remove duplicate fonts - to fold identical fonts into one; for more savings, run the result - through - Compress PDF. -

-
-
- - Can I merge PDFs that have different page sizes or orientations? - - -

- Yes. Pages keep their own size and rotation, so a landscape A3 - drawing can follow a portrait Letter page without being scaled. For - a uniform size afterward, run the merged file through - Fix Page Size. -

-
-
- - Are the PDFs uploaded to a server to be merged? - - -

- No. The files are combined inside your browser by the CoherentPDF - WebAssembly module and the merged PDF is written to your downloads - folder, so contracts and statements never leave your machine. -

-
-
- - Can I merge password-protected PDFs? - - -

- If a file needs a password to open, the tool asks for it when you - add the file and then merges the decrypted pages. The merged output - has no password; add one afterward with - Protect PDF - if needed. -

-
-
-
- {{> footer }} - - - + + + + + - - + + - + - + - - + + diff --git a/src/pages/pdf-to-png.html b/src/pages/pdf-to-png.html index b107173..c6b7d4e 100644 --- a/src/pages/pdf-to-png.html +++ b/src/pages/pdf-to-png.html @@ -1,5 +1,5 @@ - + @@ -18,43 +18,25 @@ /> - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + @@ -91,7 +73,7 @@ - {{> navbar }} +
-
-

- How It Works -

-
-
-
- 1 -
-
-

Upload File

-

- Click or drag and drop your file to begin -

-
-
-
-
- 2 -
-
-

Process

-

- Click the process button to start -

-
-
-
-
- 3 -
-
-

Download

-

- Save your processed file instantly -

-
-
-
-
+ -
-

- Related PDF Tools -

- -
+ -
-

- Frequently Asked Questions -

-
-
- - What resolution do the PNGs have? - - -

- Scale 1.0x renders at 72 pixels per inch of page, so a Letter page - becomes 612 by 792 pixels. The default 2.0x doubles that to 1224 by - 1584, and 3.0x gives 1836 by 2376, which is 216 pixels per inch. -

-
-
- - Can I export at 300 DPI for print? - - -

- Not directly. The slider tops out at 3.0x, about 216 DPI on a - standard page, and there's no field for entering a custom DPI in - this tool. -

-
-
- - Is the background transparent? - - -

- No. Pages are drawn onto a white background, so areas with no - content come out white rather than transparent, even though PNG - supports transparency. -

-
-
- - Can I convert only certain pages to PNG? - - -

- Every page is converted; there's no page-range field. Pull out the - pages you need with - Extract Pages - first, then convert that smaller file. -

-
-
- - How are the files named? - - -

- A one-page PDF downloads as filename.png. Multi-page documents - download as filename_pngs.zip containing page_1.png, page_2.png, and - so on in document order. -

-
-
- - Why are the PNG files so large? - - -

- PNG is lossless, so a full page at 2.0x is often several megabytes, - especially for scans and photos. If some compression is acceptable, - PDF to JPG - or PDF to WebP produce far smaller images from the same pages. -

-
-
- - Do annotations and filled form fields appear in the images? - - -

- Visible markup such as highlights, stamps, and filled form fields is - rendered as it appears on the page. The text inside pop-up comments - isn't drawn, only the note icon. -

-
-
- - Is the PDF rendered on a server? - - -

- No. Rendering uses PDF.js inside your browser and the ZIP is built - locally, so the document never leaves your computer. If the PDF - needs a password, you're asked for it first. -

-
-
-
- {{> footer }} - - - + + + + + - - + + - + - + - - + + diff --git a/src/pages/split-pdf.html b/src/pages/split-pdf.html index 3ddb5da..08fff34 100644 --- a/src/pages/split-pdf.html +++ b/src/pages/split-pdf.html @@ -1,5 +1,5 @@ - + @@ -24,43 +24,25 @@ /> - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + @@ -97,7 +79,7 @@ - {{> navbar }} +
-
-

- How It Works -

-
-
-
- 1 -
-
-

Upload PDF

-

- Select the PDF file you want to split or extract pages from -

-
-
-
-
- 2 -
-
-

- Choose Split Method -

-

- Select specific pages, page ranges, or split into individual pages -

-
-
-
-
- 3 -
-
-

- Preview & Select -

-

- View page thumbnails and select exactly which pages you want -

-
-
-
-
- 4 -
-
-

- Split & Download -

-

- Download extracted pages as separate PDFs or as a ZIP file -

-
-
-
-
+ -
-

- Related PDF Tools -

- -
+ -
-

- Frequently Asked Questions -

-
-
- - How do I extract a range of pages from a PDF? - - -

- Choose Extract by Page Range and type the pages you want, such as - 1-5, 8, 11-13. By default the selected pages are combined into one - PDF; switch the output to One PDF per range and each comma-separated - range becomes its own file inside split-pages.zip. -

-
-
- - Can I split a PDF into one file per page? - - -

- Yes. Pick Split All Pages into Separate Files and every page is - written to its own PDF, named page-1.pdf, page-2.pdf, and so on, - bundled in split-pages.zip. -

-
-
- - How do I split a PDF every N pages? - - -

- Choose Split N Times and enter the chunk size. A 23-page file split - every 5 pages produces five PDFs, and the tool warns you beforehand - that the last one will hold only 3 pages. The files download as - split-n-times.zip. -

-
-
- - Can I split a PDF by chapters or bookmarks? - - -

- Yes, if the PDF has bookmarks. Choose Split by Bookmarks and a level - (All, or level 0 through 3), and a new file starts at each - bookmark's page, giving you split-1.pdf, split-2.pdf, and so on in - split-by-bookmarks.zip. A PDF with no bookmarks at the chosen level - shows an error instead. -

-
-
- - How do I separate odd and even pages? - - -

- Select Split by Even/Odd Pages and pick even or odd; the matching - pages are extracted into one PDF in their original order. This is a - common step for double-sided printing on a single-sided printer. -

-
-
- - Can I pick pages visually instead of typing numbers? - - -

- Yes. Select Pages Visually shows a thumbnail of every page; click - the ones you want and they're extracted in page order. Combined - output gives one PDF, and the separate option gives one file per - page in a ZIP. -

-
-
- - Does splitting reduce the quality of the pages? - - -

- No. Pages are copied by QPDF without re-rendering, so text, images, - fonts, and vector graphics stay exactly as they were in the - original. -

-
-
- - Is my PDF uploaded when I split it? - - -

- No. The page extraction and ZIP packaging run in your browser, and - the resulting files are saved directly from your device. -

-
-
-
- {{> footer }} - - - + + + + + - - + + - + - + - - + +