@effortlessmotion/pdf-to-md 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/pdf-open.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';
|
|
2
2
|
/** Data-based open (collect.ts's seam): no cMaps/fonts — text-layer extraction
|
|
3
|
-
* only,
|
|
3
|
+
* only. wasmUrl is set as in openPdfForRender: OCR opens a PDF here first, and without it a CCITTFax page then decodes blank on Windows. Verified to decode CJK correctly. Wraps missing/unreadable and non-PDF files as PdfToMdError/PDF_OPEN. */
|
|
4
4
|
export declare function openDocument(src: string): Promise<PDFDocumentProxy>;
|
|
5
5
|
/**
|
|
6
6
|
* Open a PDF for rendering (raster.ts/tesseract.ts's seam): cMaps + standard
|
package/dist/cjs/pdf-open.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';
|
|
2
2
|
/** Data-based open (collect.ts's seam): no cMaps/fonts — text-layer extraction
|
|
3
|
-
* only,
|
|
3
|
+
* only. wasmUrl is set as in openPdfForRender: OCR opens a PDF here first, and without it a CCITTFax page then decodes blank on Windows. Verified to decode CJK correctly. Wraps missing/unreadable and non-PDF files as PdfToMdError/PDF_OPEN. */
|
|
4
4
|
export declare function openDocument(src: string): Promise<PDFDocumentProxy>;
|
|
5
5
|
/**
|
|
6
6
|
* Open a PDF for rendering (raster.ts/tesseract.ts's seam): cMaps + standard
|
package/dist/cjs/pdf-open.js
CHANGED
package/dist/cjs/pdf-open.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/formats/pdf-to-md/src/pdf-open.ts"],"sourcesContent":["// pdf-open.ts — the one seam that opens a PDF via pdfjs-dist, in the two\n// shapes callers need: openDocument (data-based, already-open doc) and openPdfForRender (url-based, task you must await + destroy()).\n// Both wrap a failure the same way: PdfToMdError/PDF_OPEN, original message preserved.\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport { getDocument, VerbosityLevel } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport { PdfToMdError } from './errors.ts';\nimport { resolvePackagePath } from './resolve.ts';\n\n// `verbosity: VerbosityLevel.ERRORS` silences pdfjs's own console.warn calls\n// — the library's documented promise is it never writes to stdout/stderr on its own.\n\n/** Data-based open (collect.ts's seam): no cMaps/fonts — text-layer extraction\n * only,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/formats/pdf-to-md/src/pdf-open.ts"],"sourcesContent":["// pdf-open.ts — the one seam that opens a PDF via pdfjs-dist, in the two\n// shapes callers need: openDocument (data-based, already-open doc) and openPdfForRender (url-based, task you must await + destroy()).\n// Both wrap a failure the same way: PdfToMdError/PDF_OPEN, original message preserved.\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport { getDocument, VerbosityLevel } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport { PdfToMdError } from './errors.ts';\nimport { resolvePackagePath } from './resolve.ts';\n\n// `verbosity: VerbosityLevel.ERRORS` silences pdfjs's own console.warn calls\n// — the library's documented promise is it never writes to stdout/stderr on its own.\n\n/** Data-based open (collect.ts's seam): no cMaps/fonts — text-layer extraction\n * only. wasmUrl is set as in openPdfForRender: OCR opens a PDF here first, and without it a CCITTFax page then decodes blank on Windows. Verified to decode CJK correctly. Wraps missing/unreadable and non-PDF files as PdfToMdError/PDF_OPEN. */\nexport async function openDocument(src: string): Promise<PDFDocumentProxy> {\n let data: Uint8Array;\n try {\n data = new Uint8Array(readFileSync(src));\n } catch (err) {\n throw new PdfToMdError('PDF_OPEN', `cannot read ${src}: ${(err as Error).message}`);\n }\n try {\n return await getDocument({\n data,\n useSystemFonts: true,\n wasmUrl: WASM_URL,\n verbosity: VerbosityLevel.ERRORS,\n }).promise;\n } catch (err) {\n throw new PdfToMdError('PDF_OPEN', `cannot open ${src} as a PDF: ${(err as Error).message}`);\n }\n}\n\n// Wires up pdfjs's bundled cmaps/standard_fonts so CJK and non-embedded\n// standard fonts resolve instead of falling back to substitute glyphs.\n//\n// GOTCHA: despite the `...Url` name, pdfjs's Node loader does `fs.readFile`\n// on the string directly — a `file://` URL silently fails every lookup (only a stderr warning); plain filesystem paths are required.\n// The trailing \"/\" must be literal (pdfjs rejects a trailing \"\\\"); Windows' fs accepts \"/\" after a \"\\\" path.\nconst PDFJS_DIST_ROOT = path.dirname(resolvePackagePath('pdfjs-dist/package.json'));\nconst CMAP_URL = `${path.join(PDFJS_DIST_ROOT, 'cmaps')}/`;\nconst STANDARD_FONT_DATA_URL = `${path.join(PDFJS_DIST_ROOT, 'standard_fonts')}/`;\n// JBIG2/JPEG2000 decoding lives in pdfjs's WASM modules: without this, bitonal\n// scans (the usual encoding for B&W page images) decode to a BLANK page and OCR sees nothing.\nconst WASM_URL = `${path.join(PDFJS_DIST_ROOT, 'wasm')}/`;\n\n/**\n * Open a PDF for rendering (raster.ts/tesseract.ts's seam): cMaps + standard\n * fonts wired up, url-based. Callers must `await` the returned task's `.promise` (via `awaitPdfOpen`) and call `.destroy()` when done.\n */\nexport function openPdfForRender(pdfPath: string): PDFDocumentLoadingTask {\n // No `worker` option: this pdfjs-dist Node build needs no real Worker thread wired up to run.\n return getDocument({\n url: pdfPath,\n cMapUrl: CMAP_URL,\n cMapPacked: true,\n standardFontDataUrl: STANDARD_FONT_DATA_URL,\n wasmUrl: WASM_URL,\n verbosity: VerbosityLevel.ERRORS,\n });\n}\n\n/** Shared error wrapping for `openPdfForRender`'s task: a raw pdfjs open\n * failure becomes PdfToMdError/PDF_OPEN, original message preserved. */\nexport async function awaitPdfOpen(loadingTask: PDFDocumentLoadingTask, pdfPath: string): Promise<PDFDocumentProxy> {\n try {\n return await loadingTask.promise;\n } catch (err) {\n throw new PdfToMdError('PDF_OPEN', `could not open PDF: ${pdfPath} (${(err as Error).message})`);\n }\n}\n"],"names":["awaitPdfOpen","openDocument","openPdfForRender","src","data","err","Uint8Array","readFileSync","PdfToMdError","message","getDocument","useSystemFonts","wasmUrl","WASM_URL","verbosity","VerbosityLevel","ERRORS","promise","PDFJS_DIST_ROOT","path","dirname","resolvePackagePath","CMAP_URL","join","STANDARD_FONT_DATA_URL","pdfPath","url","cMapUrl","cMapPacked","standardFontDataUrl","loadingTask"],"mappings":"AAAA,yEAAyE;AACzE,sIAAsI;AACtI,uFAAuF;;;;;;;;;;;;QA+DjEA;eAAAA;;QAlDAC;eAAAA;;QAoCNC;eAAAA;;;sBAhDa;+DACZ;mBAE2B;wBACf;yBACM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAO5B,SAAeD,aAAaE,GAAW;;YACxCC,MAaKC;;;;oBAZT,IAAI;wBACFD,OAAO,IAAIE,WAAWC,IAAAA,oBAAY,EAACJ;oBACrC,EAAE,OAAOE,KAAK;wBACZ,MAAM,IAAIG,sBAAY,CAAC,YAAY,AAAC,eAAsB,OAARL,KAAI,MAA2B,OAAvB,AAACE,IAAcI,OAAO;oBAClF;;;;;;;;;oBAES;;wBAAMC,IAAAA,gBAAW,EAAC;4BACvBN,MAAAA;4BACAO,gBAAgB;4BAChBC,SAASC;4BACTC,WAAWC,mBAAc,CAACC,MAAM;wBAClC,GAAGC,OAAO;;;oBALV;;wBAAO;;;oBAMAZ;oBACP,MAAM,IAAIG,sBAAY,CAAC,YAAY,AAAC,eAA+B,OAAjBL,KAAI,eAAoC,OAAvB,AAACE,IAAcI,OAAO;;;;;;;IAE7F;;AAEA,wEAAwE;AACxE,uEAAuE;AACvE,EAAE;AACF,4EAA4E;AAC5E,qIAAqI;AACrI,6GAA6G;AAC7G,IAAMS,kBAAkBC,iBAAI,CAACC,OAAO,CAACC,IAAAA,6BAAkB,EAAC;AACxD,IAAMC,WAAW,AAAC,GAAsC,OAApCH,iBAAI,CAACI,IAAI,CAACL,iBAAiB,UAAS;AACxD,IAAMM,yBAAyB,AAAC,GAA+C,OAA7CL,iBAAI,CAACI,IAAI,CAACL,iBAAiB,mBAAkB;AAC/E,+EAA+E;AAC/E,8FAA8F;AAC9F,IAAML,WAAW,AAAC,GAAqC,OAAnCM,iBAAI,CAACI,IAAI,CAACL,iBAAiB,SAAQ;AAMhD,SAAShB,iBAAiBuB,OAAe;IAC9C,8FAA8F;IAC9F,OAAOf,IAAAA,gBAAW,EAAC;QACjBgB,KAAKD;QACLE,SAASL;QACTM,YAAY;QACZC,qBAAqBL;QACrBZ,SAASC;QACTC,WAAWC,mBAAc,CAACC,MAAM;IAClC;AACF;AAIO,SAAehB,aAAa8B,WAAmC,EAAEL,OAAe;;YAG5EpB;;;;;;;;;;oBADA;;wBAAMyB,YAAYb,OAAO;;;oBAAhC;;wBAAO;;;oBACAZ;oBACP,MAAM,IAAIG,sBAAY,CAAC,YAAY,AAAC,uBAAkC,OAAZiB,SAAQ,MAA2B,OAAvB,AAACpB,IAAcI,OAAO,EAAC;;;;;;;IAEjG"}
|
package/dist/esm/pdf-open.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';
|
|
2
2
|
/** Data-based open (collect.ts's seam): no cMaps/fonts — text-layer extraction
|
|
3
|
-
* only,
|
|
3
|
+
* only. wasmUrl is set as in openPdfForRender: OCR opens a PDF here first, and without it a CCITTFax page then decodes blank on Windows. Verified to decode CJK correctly. Wraps missing/unreadable and non-PDF files as PdfToMdError/PDF_OPEN. */
|
|
4
4
|
export declare function openDocument(src: string): Promise<PDFDocumentProxy>;
|
|
5
5
|
/**
|
|
6
6
|
* Open a PDF for rendering (raster.ts/tesseract.ts's seam): cMaps + standard
|
package/dist/esm/pdf-open.js
CHANGED
|
@@ -9,7 +9,7 @@ import { resolvePackagePath } from './resolve.js';
|
|
|
9
9
|
// `verbosity: VerbosityLevel.ERRORS` silences pdfjs's own console.warn calls
|
|
10
10
|
// — the library's documented promise is it never writes to stdout/stderr on its own.
|
|
11
11
|
/** Data-based open (collect.ts's seam): no cMaps/fonts — text-layer extraction
|
|
12
|
-
* only,
|
|
12
|
+
* only. wasmUrl is set as in openPdfForRender: OCR opens a PDF here first, and without it a CCITTFax page then decodes blank on Windows. Verified to decode CJK correctly. Wraps missing/unreadable and non-PDF files as PdfToMdError/PDF_OPEN. */ export async function openDocument(src) {
|
|
13
13
|
let data;
|
|
14
14
|
try {
|
|
15
15
|
data = new Uint8Array(readFileSync(src));
|
|
@@ -20,6 +20,7 @@ import { resolvePackagePath } from './resolve.js';
|
|
|
20
20
|
return await getDocument({
|
|
21
21
|
data,
|
|
22
22
|
useSystemFonts: true,
|
|
23
|
+
wasmUrl: WASM_URL,
|
|
23
24
|
verbosity: VerbosityLevel.ERRORS
|
|
24
25
|
}).promise;
|
|
25
26
|
} catch (err) {
|
package/dist/esm/pdf-open.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/formats/pdf-to-md/src/pdf-open.ts"],"sourcesContent":["// pdf-open.ts — the one seam that opens a PDF via pdfjs-dist, in the two\n// shapes callers need: openDocument (data-based, already-open doc) and openPdfForRender (url-based, task you must await + destroy()).\n// Both wrap a failure the same way: PdfToMdError/PDF_OPEN, original message preserved.\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport { getDocument, VerbosityLevel } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport { PdfToMdError } from './errors.ts';\nimport { resolvePackagePath } from './resolve.ts';\n\n// `verbosity: VerbosityLevel.ERRORS` silences pdfjs's own console.warn calls\n// — the library's documented promise is it never writes to stdout/stderr on its own.\n\n/** Data-based open (collect.ts's seam): no cMaps/fonts — text-layer extraction\n * only,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/formats/pdf-to-md/src/pdf-open.ts"],"sourcesContent":["// pdf-open.ts — the one seam that opens a PDF via pdfjs-dist, in the two\n// shapes callers need: openDocument (data-based, already-open doc) and openPdfForRender (url-based, task you must await + destroy()).\n// Both wrap a failure the same way: PdfToMdError/PDF_OPEN, original message preserved.\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport { getDocument, VerbosityLevel } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport { PdfToMdError } from './errors.ts';\nimport { resolvePackagePath } from './resolve.ts';\n\n// `verbosity: VerbosityLevel.ERRORS` silences pdfjs's own console.warn calls\n// — the library's documented promise is it never writes to stdout/stderr on its own.\n\n/** Data-based open (collect.ts's seam): no cMaps/fonts — text-layer extraction\n * only. wasmUrl is set as in openPdfForRender: OCR opens a PDF here first, and without it a CCITTFax page then decodes blank on Windows. Verified to decode CJK correctly. Wraps missing/unreadable and non-PDF files as PdfToMdError/PDF_OPEN. */\nexport async function openDocument(src: string): Promise<PDFDocumentProxy> {\n let data: Uint8Array;\n try {\n data = new Uint8Array(readFileSync(src));\n } catch (err) {\n throw new PdfToMdError('PDF_OPEN', `cannot read ${src}: ${(err as Error).message}`);\n }\n try {\n return await getDocument({\n data,\n useSystemFonts: true,\n wasmUrl: WASM_URL,\n verbosity: VerbosityLevel.ERRORS,\n }).promise;\n } catch (err) {\n throw new PdfToMdError('PDF_OPEN', `cannot open ${src} as a PDF: ${(err as Error).message}`);\n }\n}\n\n// Wires up pdfjs's bundled cmaps/standard_fonts so CJK and non-embedded\n// standard fonts resolve instead of falling back to substitute glyphs.\n//\n// GOTCHA: despite the `...Url` name, pdfjs's Node loader does `fs.readFile`\n// on the string directly — a `file://` URL silently fails every lookup (only a stderr warning); plain filesystem paths are required.\n// The trailing \"/\" must be literal (pdfjs rejects a trailing \"\\\"); Windows' fs accepts \"/\" after a \"\\\" path.\nconst PDFJS_DIST_ROOT = path.dirname(resolvePackagePath('pdfjs-dist/package.json'));\nconst CMAP_URL = `${path.join(PDFJS_DIST_ROOT, 'cmaps')}/`;\nconst STANDARD_FONT_DATA_URL = `${path.join(PDFJS_DIST_ROOT, 'standard_fonts')}/`;\n// JBIG2/JPEG2000 decoding lives in pdfjs's WASM modules: without this, bitonal\n// scans (the usual encoding for B&W page images) decode to a BLANK page and OCR sees nothing.\nconst WASM_URL = `${path.join(PDFJS_DIST_ROOT, 'wasm')}/`;\n\n/**\n * Open a PDF for rendering (raster.ts/tesseract.ts's seam): cMaps + standard\n * fonts wired up, url-based. Callers must `await` the returned task's `.promise` (via `awaitPdfOpen`) and call `.destroy()` when done.\n */\nexport function openPdfForRender(pdfPath: string): PDFDocumentLoadingTask {\n // No `worker` option: this pdfjs-dist Node build needs no real Worker thread wired up to run.\n return getDocument({\n url: pdfPath,\n cMapUrl: CMAP_URL,\n cMapPacked: true,\n standardFontDataUrl: STANDARD_FONT_DATA_URL,\n wasmUrl: WASM_URL,\n verbosity: VerbosityLevel.ERRORS,\n });\n}\n\n/** Shared error wrapping for `openPdfForRender`'s task: a raw pdfjs open\n * failure becomes PdfToMdError/PDF_OPEN, original message preserved. */\nexport async function awaitPdfOpen(loadingTask: PDFDocumentLoadingTask, pdfPath: string): Promise<PDFDocumentProxy> {\n try {\n return await loadingTask.promise;\n } catch (err) {\n throw new PdfToMdError('PDF_OPEN', `could not open PDF: ${pdfPath} (${(err as Error).message})`);\n }\n}\n"],"names":["readFileSync","path","getDocument","VerbosityLevel","PdfToMdError","resolvePackagePath","openDocument","src","data","Uint8Array","err","message","useSystemFonts","wasmUrl","WASM_URL","verbosity","ERRORS","promise","PDFJS_DIST_ROOT","dirname","CMAP_URL","join","STANDARD_FONT_DATA_URL","openPdfForRender","pdfPath","url","cMapUrl","cMapPacked","standardFontDataUrl","awaitPdfOpen","loadingTask"],"mappings":"AAAA,yEAAyE;AACzE,sIAAsI;AACtI,uFAAuF;AACvF,SAASA,YAAY,QAAQ,UAAU;AACvC,OAAOC,UAAU,YAAY;AAE7B,SAASC,WAAW,EAAEC,cAAc,QAAQ,kCAAkC;AAC9E,SAASC,YAAY,QAAQ,cAAc;AAC3C,SAASC,kBAAkB,QAAQ,eAAe;AAElD,6EAA6E;AAC7E,qFAAqF;AAErF;iPACiP,GACjP,OAAO,eAAeC,aAAaC,GAAW;IAC5C,IAAIC;IACJ,IAAI;QACFA,OAAO,IAAIC,WAAWT,aAAaO;IACrC,EAAE,OAAOG,KAAK;QACZ,MAAM,IAAIN,aAAa,YAAY,CAAC,YAAY,EAAEG,IAAI,EAAE,EAAE,AAACG,IAAcC,OAAO,EAAE;IACpF;IACA,IAAI;QACF,OAAO,MAAMT,YAAY;YACvBM;YACAI,gBAAgB;YAChBC,SAASC;YACTC,WAAWZ,eAAea,MAAM;QAClC,GAAGC,OAAO;IACZ,EAAE,OAAOP,KAAK;QACZ,MAAM,IAAIN,aAAa,YAAY,CAAC,YAAY,EAAEG,IAAI,WAAW,EAAE,AAACG,IAAcC,OAAO,EAAE;IAC7F;AACF;AAEA,wEAAwE;AACxE,uEAAuE;AACvE,EAAE;AACF,4EAA4E;AAC5E,qIAAqI;AACrI,6GAA6G;AAC7G,MAAMO,kBAAkBjB,KAAKkB,OAAO,CAACd,mBAAmB;AACxD,MAAMe,WAAW,GAAGnB,KAAKoB,IAAI,CAACH,iBAAiB,SAAS,CAAC,CAAC;AAC1D,MAAMI,yBAAyB,GAAGrB,KAAKoB,IAAI,CAACH,iBAAiB,kBAAkB,CAAC,CAAC;AACjF,+EAA+E;AAC/E,8FAA8F;AAC9F,MAAMJ,WAAW,GAAGb,KAAKoB,IAAI,CAACH,iBAAiB,QAAQ,CAAC,CAAC;AAEzD;;;CAGC,GACD,OAAO,SAASK,iBAAiBC,OAAe;IAC9C,8FAA8F;IAC9F,OAAOtB,YAAY;QACjBuB,KAAKD;QACLE,SAASN;QACTO,YAAY;QACZC,qBAAqBN;QACrBT,SAASC;QACTC,WAAWZ,eAAea,MAAM;IAClC;AACF;AAEA;sEACsE,GACtE,OAAO,eAAea,aAAaC,WAAmC,EAAEN,OAAe;IACrF,IAAI;QACF,OAAO,MAAMM,YAAYb,OAAO;IAClC,EAAE,OAAOP,KAAK;QACZ,MAAM,IAAIN,aAAa,YAAY,CAAC,oBAAoB,EAAEoB,QAAQ,EAAE,EAAE,AAACd,IAAcC,OAAO,CAAC,CAAC,CAAC;IACjG;AACF"}
|
package/package.json
CHANGED