修复: PDF 导入 worker 本地化,离线/桌面不再依赖 CDN
This commit is contained in:
@@ -8,6 +8,8 @@
|
|||||||
* ===================================================================== */
|
* ===================================================================== */
|
||||||
import type { Slide, SlideElement } from './types'
|
import type { Slide, SlideElement } from './types'
|
||||||
import { createElement } from './sample'
|
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'])
|
const IMAGE_EXTS = new Set(['.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp', '.ico'])
|
||||||
@@ -81,8 +83,7 @@ function readAsText(file: File): Promise<string> {
|
|||||||
|
|
||||||
export async function extractPdfText(file: File): Promise<string> {
|
export async function extractPdfText(file: File): Promise<string> {
|
||||||
const pdfjsLib: any = await import('pdfjs-dist')
|
const pdfjsLib: any = await import('pdfjs-dist')
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfWorkerUrl
|
||||||
`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.mjs`
|
|
||||||
|
|
||||||
const buffer = await readAsArrayBuffer(file)
|
const buffer = await readAsArrayBuffer(file)
|
||||||
const pdf = await pdfjsLib.getDocument({ data: buffer }).promise
|
const pdf = await pdfjsLib.getDocument({ data: buffer }).promise
|
||||||
|
|||||||
Reference in New Issue
Block a user