From f58fea1f68fdd1b2aa6de2b89a8d30c76eba63b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Mon, 17 Aug 2026 10:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20PDF=20=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=20worker=20=E6=9C=AC=E5=9C=B0=E5=8C=96,=E7=A6=BB=E7=BA=BF/?= =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E4=B8=8D=E5=86=8D=E4=BE=9D=E8=B5=96=20CDN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/importer.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/importer.ts b/src/core/importer.ts index f9e067b..951c648 100644 --- a/src/core/importer.ts +++ b/src/core/importer.ts @@ -8,6 +8,8 @@ * ===================================================================== */ import type { Slide, SlideElement } from './types' import { createElement } from './sample' +// 本地打包 pdf.js worker(避免依赖 CDN,离线/桌面/内网可用) +import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.min.mjs?url' /** 允许的图片扩展名 */ const IMAGE_EXTS = new Set(['.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp', '.ico']) @@ -81,8 +83,7 @@ function readAsText(file: File): Promise { export async function extractPdfText(file: File): Promise { const pdfjsLib: any = await import('pdfjs-dist') - pdfjsLib.GlobalWorkerOptions.workerSrc = - `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.mjs` + pdfjsLib.GlobalWorkerOptions.workerSrc = pdfWorkerUrl const buffer = await readAsArrayBuffer(file) const pdf = await pdfjsLib.getDocument({ data: buffer }).promise