reamkit 0.1.0-alpha.0 → 1.0.0
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/README.md +106 -30
- package/dist/esm/{bidi → core/bidi}/algorithm.js +1 -1
- package/dist/esm/{bidi → core/bidi}/char-types.js +1 -1
- package/dist/esm/{bidi → core/bidi}/index.js +1 -1
- package/dist/esm/core/bytes.d.ts +1 -0
- package/dist/esm/core/bytes.js +11 -0
- package/dist/esm/core/converter/facade.d.ts +45 -0
- package/dist/esm/core/converter/facade.js +89 -0
- package/dist/esm/core/converter/index.d.ts +4 -0
- package/dist/esm/core/converter/project.d.ts +4 -0
- package/dist/esm/core/converter/project.js +16 -0
- package/dist/esm/core/converter/ream.d.ts +35 -0
- package/dist/esm/core/converter/ream.js +100 -0
- package/dist/esm/{crypto → core/crypto}/asn1.js +1 -1
- package/dist/esm/{crypto → core/crypto}/cms.js +1 -1
- package/dist/esm/core/document-model/index.d.ts +1 -0
- package/dist/esm/{document-model → core/document-model}/types.d.ts +57 -41
- package/dist/esm/{ooxml → core}/drawingml/chart-parser.d.ts +1 -1
- package/dist/esm/{ooxml → core}/drawingml/chart-parser.js +6 -29
- package/dist/esm/{ooxml → core}/drawingml/colors.d.ts +3 -0
- package/dist/esm/{ooxml → core}/drawingml/colors.js +32 -2
- package/dist/esm/{ooxml → core}/drawingml/theme-parser.js +2 -2
- package/dist/esm/{font → core/font}/arabic-joining.js +1 -1
- package/dist/esm/{font → core/font}/binary-reader.js +1 -1
- package/dist/esm/{font → core/font}/font-registry.d.ts +1 -0
- package/dist/esm/{font → core/font}/font-registry.js +17 -16
- package/dist/esm/{font → core/font}/index.d.ts +1 -0
- package/dist/esm/{font → core/font}/opentype-layout.js +1 -1
- package/dist/esm/{font → core/font}/ttf-parser.js +1 -1
- package/dist/esm/{font → core/font}/ttf-subset.js +1 -1
- package/dist/esm/core/fonts/provider.d.ts +60 -0
- package/dist/esm/core/fonts/provider.js +163 -0
- package/dist/esm/{fonts → core/fonts}/remote-fonts.js +1 -1
- package/dist/esm/{hyphenation → core/hyphenation}/index.js +1 -1
- package/dist/esm/{hyphenation → core/hyphenation}/liang.js +1 -1
- package/dist/esm/{hyphenation → core/hyphenation}/patterns-en-us.js +1 -1
- package/dist/esm/{hyphenation → core/hyphenation}/patterns-ru.js +1 -1
- package/dist/esm/core/ir/adapters.d.ts +37 -0
- package/dist/esm/core/ir/features.d.ts +25 -0
- package/dist/esm/core/ir/features.js +24 -0
- package/dist/esm/core/ir/flow.d.ts +24 -0
- package/dist/esm/core/ir/index.d.ts +11 -0
- package/dist/esm/core/ir/loss.d.ts +22 -0
- package/dist/esm/core/ir/loss.js +15 -0
- package/dist/esm/core/ir/resources.d.ts +16 -0
- package/dist/esm/core/ir/resources.js +50 -0
- package/dist/esm/core/ir/units.d.ts +16 -0
- package/dist/esm/core/ir/units.js +41 -0
- package/dist/esm/core/line-breaker/index.d.ts +2 -0
- package/dist/esm/{line-breaker → core/line-breaker}/knuth-plass.js +1 -1
- package/dist/esm/{numbering → core/numbering}/state.js +1 -1
- package/dist/esm/{opc → core/opc}/core-properties.js +1 -1
- package/dist/esm/{opc → core/opc}/package.js +1 -1
- package/dist/esm/{opc → core/opc}/relationship-types.js +1 -1
- package/dist/esm/{opc → core/opc}/relationships.js +1 -1
- package/dist/esm/{ooxml/wordproc → core}/po-helpers.js +1 -1
- package/dist/esm/{style-cascade → core/style-cascade}/index.d.ts +2 -2
- package/dist/esm/core/style-cascade/index.js +2 -0
- package/dist/esm/{style-cascade → core/style-cascade}/resolver.d.ts +1 -0
- package/dist/esm/{style-cascade → core/style-cascade}/resolver.js +14 -9
- package/dist/esm/{style-cascade → core/style-cascade}/types.d.ts +8 -7
- package/dist/esm/{style-cascade → core/style-cascade}/types.js +9 -8
- package/dist/esm/{ooxml/spreadsheet → excel}/cell-reference.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/defined-name-ref.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/index.d.ts +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/number-format.js +1 -1
- package/dist/esm/excel/print-model.d.ts +18 -0
- package/dist/esm/{converter/xlsx-to-pdf.js → excel/print-model.js} +39 -148
- package/dist/esm/{ooxml/spreadsheet → excel}/shared-strings-parser.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/styles-parser.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/workbook-parser.js +1 -1
- package/dist/esm/{ooxml/spreadsheet → excel}/worksheet-parser.js +1 -1
- package/dist/esm/excel/xlsx-reader.d.ts +4 -0
- package/dist/esm/excel/xlsx-reader.js +91 -0
- package/dist/esm/{converter → excel}/xlsx-to-pdf.d.ts +13 -2
- package/dist/esm/excel/xlsx-to-pdf.js +69 -0
- package/dist/esm/index.d.ts +23 -8
- package/dist/esm/index.js +18 -11
- package/dist/esm/pdf/chart-geometry.d.ts +1 -1
- package/dist/esm/pdf/cid-font.d.ts +7 -1
- package/dist/esm/pdf/cid-font.js +33 -22
- package/dist/esm/pdf/image-xobject.d.ts +13 -0
- package/dist/esm/pdf/image-xobject.js +55 -54
- package/dist/esm/pdf/index.d.ts +2 -2
- package/dist/esm/pdf/math-layout.d.ts +1 -1
- package/dist/esm/pdf/preset-geometry.d.ts +1 -1
- package/dist/esm/pdf/signature.js +4 -4
- package/dist/esm/pdf/styled-page-emitter.d.ts +5 -0
- package/dist/esm/pdf/styled-page-emitter.js +542 -0
- package/dist/esm/pdf/styled-page-renderer.d.ts +189 -14
- package/dist/esm/pdf/styled-page-renderer.js +168 -654
- package/dist/esm/pdf/text-page-renderer.d.ts +1 -1
- package/dist/esm/svg/svg-writer.d.ts +8 -0
- package/dist/esm/svg/svg-writer.js +138 -0
- package/dist/esm/word/document-parser.d.ts +16 -0
- package/dist/esm/{ooxml/wordproc → word}/document-parser.js +55 -47
- package/dist/esm/word/docx-reader.d.ts +4 -0
- package/dist/esm/word/docx-reader.js +190 -0
- package/dist/esm/word/docx-to-pdf.d.ts +34 -0
- package/dist/esm/word/docx-to-pdf.js +112 -0
- package/dist/esm/{ooxml/wordproc → word}/drawing-parser.d.ts +10 -9
- package/dist/esm/{ooxml/wordproc → word}/drawing-parser.js +15 -42
- package/dist/esm/{ooxml/wordproc → word}/font-table.d.ts +2 -2
- package/dist/esm/{ooxml/wordproc → word}/font-table.js +2 -2
- package/dist/esm/{ooxml/wordproc → word}/index.d.ts +3 -2
- package/dist/esm/{ooxml/wordproc → word}/numbering-parser.d.ts +1 -1
- package/dist/esm/{ooxml/wordproc → word}/numbering-parser.js +1 -1
- package/dist/esm/{ooxml/math → word}/omml-parser.d.ts +2 -2
- package/dist/esm/{ooxml/math → word}/omml-parser.js +2 -2
- package/dist/esm/{ooxml/wordproc → word}/paragraph-properties.d.ts +1 -1
- package/dist/esm/{ooxml/wordproc → word}/paragraph-properties.js +9 -8
- package/dist/esm/{ooxml/wordproc → word}/po-to-flat.d.ts +1 -1
- package/dist/esm/{ooxml/wordproc → word}/po-to-flat.js +2 -2
- package/dist/esm/{ooxml/wordproc → word}/run-properties.d.ts +1 -1
- package/dist/esm/{ooxml/wordproc → word}/run-properties.js +3 -2
- package/dist/esm/{ooxml/wordproc → word}/settings-parser.js +2 -2
- package/dist/esm/word/styles-parser.d.ts +2 -0
- package/dist/esm/{ooxml/wordproc → word}/styles-parser.js +4 -7
- package/dist/esm/word/table-parser.d.ts +4 -0
- package/dist/esm/{ooxml/wordproc → word}/table-parser.js +80 -26
- package/dist/esm/{ooxml/wordproc → word}/xml-helpers.js +1 -1
- package/package.json +5 -6
- package/dist/esm/converter/docx-to-pdf.d.ts +0 -15
- package/dist/esm/converter/docx-to-pdf.js +0 -227
- package/dist/esm/converter/index.d.ts +0 -4
- package/dist/esm/converter/index.js +0 -2
- package/dist/esm/document-model/index.d.ts +0 -1
- package/dist/esm/line-breaker/index.d.ts +0 -2
- package/dist/esm/ooxml/index.d.ts +0 -1
- package/dist/esm/ooxml/wordproc/document-parser.d.ts +0 -9
- package/dist/esm/ooxml/wordproc/styles-parser.d.ts +0 -3
- package/dist/esm/ooxml/wordproc/table-parser.d.ts +0 -3
- /package/dist/esm/{bidi → core/bidi}/algorithm.d.ts +0 -0
- /package/dist/esm/{bidi → core/bidi}/char-types.d.ts +0 -0
- /package/dist/esm/{bidi → core/bidi}/index.d.ts +0 -0
- /package/dist/esm/{crypto → core/crypto}/asn1.d.ts +0 -0
- /package/dist/esm/{crypto → core/crypto}/cms.d.ts +0 -0
- /package/dist/esm/{crypto → core/crypto}/index.d.ts +0 -0
- /package/dist/esm/{crypto → core/crypto}/index.js +0 -0
- /package/dist/esm/{document-model → core/document-model}/index.js +0 -0
- /package/dist/esm/{ooxml → core}/drawingml/theme-parser.d.ts +0 -0
- /package/dist/esm/{font → core/font}/arabic-joining.d.ts +0 -0
- /package/dist/esm/{font → core/font}/binary-reader.d.ts +0 -0
- /package/dist/esm/{font → core/font}/opentype-layout.d.ts +0 -0
- /package/dist/esm/{font → core/font}/ttf-parser.d.ts +0 -0
- /package/dist/esm/{font → core/font}/ttf-subset.d.ts +0 -0
- /package/dist/esm/{fonts → core/fonts}/index.d.ts +0 -0
- /package/dist/esm/{fonts → core/fonts}/remote-fonts.d.ts +0 -0
- /package/dist/esm/{hyphenation → core/hyphenation}/index.d.ts +0 -0
- /package/dist/esm/{hyphenation → core/hyphenation}/liang.d.ts +0 -0
- /package/dist/esm/{hyphenation → core/hyphenation}/patterns-en-us.d.ts +0 -0
- /package/dist/esm/{hyphenation → core/hyphenation}/patterns-ru.d.ts +0 -0
- /package/dist/esm/{line-breaker → core/line-breaker}/knuth-plass.d.ts +0 -0
- /package/dist/esm/{numbering → core/numbering}/index.d.ts +0 -0
- /package/dist/esm/{numbering → core/numbering}/state.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/core-properties.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/index.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/index.js +0 -0
- /package/dist/esm/{opc → core/opc}/package.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/relationship-types.d.ts +0 -0
- /package/dist/esm/{opc → core/opc}/relationships.d.ts +0 -0
- /package/dist/esm/{ooxml/wordproc → core}/po-helpers.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/cell-reference.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/defined-name-ref.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/index.js +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/number-format.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/shared-strings-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/styles-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/workbook-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/spreadsheet → excel}/worksheet-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/index.js +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/settings-parser.d.ts +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/text-extractor.d.ts +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/text-extractor.js +0 -0
- /package/dist/esm/{ooxml/wordproc → word}/xml-helpers.d.ts +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { fetchFontSet } from "../core/fonts/remote-fonts.js";
|
|
2
|
+
import { FontRegistry } from "../core/font/font-registry.js";
|
|
3
|
+
import { signPdf } from "../pdf/signature.js";
|
|
4
|
+
import { renderStyledPdf } from "../pdf/styled-page-renderer.js";
|
|
5
|
+
import "../pdf/index.js";
|
|
6
|
+
import { readXlsx } from "./xlsx-reader.js";
|
|
7
|
+
import { flowRenderOptions } from "../core/converter/project.js";
|
|
8
|
+
//#region src/excel/xlsx-to-pdf.ts
|
|
9
|
+
/**
|
|
10
|
+
* Convert a .xlsx to PDF in one shot.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated Use `Ream.parse(bytes).convert('pdf', options)` — one parse,
|
|
13
|
+
* any number of targets. This function remains for 0.1.x compatibility.
|
|
14
|
+
*/
|
|
15
|
+
async function convertXlsxToPdf(xlsx, options = {}) {
|
|
16
|
+
const { signature } = options;
|
|
17
|
+
const renderOptions = signature ? {
|
|
18
|
+
...options,
|
|
19
|
+
signaturePlaceholder: signature
|
|
20
|
+
} : options;
|
|
21
|
+
let pdf;
|
|
22
|
+
if (renderOptions.fonts ?? renderOptions.fontBytes) pdf = convertXlsxToPdfSync(xlsx, renderOptions);
|
|
23
|
+
else {
|
|
24
|
+
const fonts = await fetchFontSet({
|
|
25
|
+
...options.fontFamily ? { family: options.fontFamily } : {},
|
|
26
|
+
...options.fontFetch ? { fetch: options.fontFetch } : {}
|
|
27
|
+
});
|
|
28
|
+
pdf = convertXlsxToPdfSync(xlsx, {
|
|
29
|
+
...renderOptions,
|
|
30
|
+
fonts
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return signature ? signPdf(pdf, signature) : pdf;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Synchronous one-shot conversion (requires `fonts`/`fontBytes`).
|
|
37
|
+
*
|
|
38
|
+
* Internal since 1.0 — see the async variant above.
|
|
39
|
+
*/
|
|
40
|
+
function convertXlsxToPdfSync(xlsx, options) {
|
|
41
|
+
const fonts = options.fonts ?? (options.fontBytes ? { regular: options.fontBytes } : void 0);
|
|
42
|
+
if (!fonts) throw new Error("convertXlsxToPdfSync requires options.fonts or options.fontBytes");
|
|
43
|
+
const registry = FontRegistry.fromBytes(fonts);
|
|
44
|
+
const { doc: flow } = readXlsx(xlsx);
|
|
45
|
+
const { fontBytes: _ignoreA, fonts: _ignoreB, section: sectionOverride, info: callerInfo, embedSource, attachments: callerAttachments, signature: _ignoreSig, ...renderOptions } = options;
|
|
46
|
+
const section = sectionOverride ?? flow.section;
|
|
47
|
+
const info = flow.info || callerInfo ? {
|
|
48
|
+
...flow.info,
|
|
49
|
+
...callerInfo
|
|
50
|
+
} : void 0;
|
|
51
|
+
const attachments = [...callerAttachments ?? []];
|
|
52
|
+
if (embedSource && options.pdfA?.startsWith("PDF/A-3")) attachments.push({
|
|
53
|
+
name: "source.xlsx",
|
|
54
|
+
bytes: xlsx,
|
|
55
|
+
mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
56
|
+
relationship: "Source",
|
|
57
|
+
description: "Source Excel workbook"
|
|
58
|
+
});
|
|
59
|
+
return renderStyledPdf(flow.body, {
|
|
60
|
+
registry,
|
|
61
|
+
...flowRenderOptions(flow),
|
|
62
|
+
...section ? { section } : {},
|
|
63
|
+
...info ? { info } : {},
|
|
64
|
+
...attachments.length > 0 ? { attachments } : {},
|
|
65
|
+
...renderOptions
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { convertXlsxToPdf };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
3
|
-
export { fetchFontSet, resolveFamilyKey } from './fonts/index.js';
|
|
4
|
-
export type { FamilyKey, FetchFontSetOptions, FetchLike } from './fonts/index.js';
|
|
1
|
+
export { fetchFontSet, resolveFamilyKey } from './core/fonts/index.js';
|
|
2
|
+
export type { FamilyKey, FetchFontSetOptions, FetchLike } from './core/fonts/index.js';
|
|
5
3
|
export { renderStyledPdf } from './pdf/index.js';
|
|
6
4
|
export type { StyledRenderOptions, DocumentInfo } from './pdf/index.js';
|
|
7
5
|
export { signPdf } from './pdf/index.js';
|
|
8
6
|
export type { SignaturePlaceholder, SignerCredentials, SignatureOptions } from './pdf/index.js';
|
|
9
|
-
export { FontRegistry, parseTtf, subsetTtf } from './font/index.js';
|
|
10
|
-
export type { FontBytesByVariant, FontVariant, ParsedTtf } from './font/index.js';
|
|
11
|
-
export { getHyphenator, createLanguageHyphenator, createHyphenator, splitPatternBundle, } from './hyphenation/index.js';
|
|
12
|
-
export type { Hyphenator, HyphenatorOptions, SupportedLanguage } from './hyphenation/index.js';
|
|
7
|
+
export { FontRegistry, parseTtf, subsetTtf } from './core/font/index.js';
|
|
8
|
+
export type { FontBytesByVariant, FontVariant, ParsedTtf } from './core/font/index.js';
|
|
9
|
+
export { getHyphenator, createLanguageHyphenator, createHyphenator, splitPatternBundle, } from './core/hyphenation/index.js';
|
|
10
|
+
export type { Hyphenator, HyphenatorOptions, SupportedLanguage } from './core/hyphenation/index.js';
|
|
11
|
+
export type { Pt, ResourceId, Feature, KnownFeature, Loss, LossReport, LossSeverity, NativeBag, } from './core/ir/index.js';
|
|
12
|
+
export { FEATURES, ResourceStore, ConversionLossError, formatLoss, pt, twipsToPt, halfPtToPt, eighthPtToPt, emuToPt, pxToPt, inchToPt, mmToPt, } from './core/ir/index.js';
|
|
13
|
+
export type { FlowDoc } from './core/ir/flow.js';
|
|
14
|
+
export type { DocumentReader, DocumentWriter, ReadOptions, ReadResult, WriteOptions, WriteResult, } from './core/ir/adapters.js';
|
|
15
|
+
export { docxReader, readDocx } from './word/docx-reader.js';
|
|
16
|
+
export { xlsxReader, readXlsx } from './excel/xlsx-reader.js';
|
|
17
|
+
export { Ream } from './core/converter/ream.js';
|
|
18
|
+
export type { ReamConvertOptions, ReamParseOptions, ReamTarget } from './core/converter/ream.js';
|
|
19
|
+
export { createConverter } from './core/converter/facade.js';
|
|
20
|
+
export type { Converter, ConvertOptions, ConvertResult, CreateConverterOptions, } from './core/converter/facade.js';
|
|
21
|
+
export type { PageItem, PageItemBase, TextLineItem, BorderItem, FillItem, ImageItem, ShapeItem, LaidOutPage, } from './pdf/styled-page-renderer.js';
|
|
22
|
+
export { chainProviders, callerFontProvider, embeddedDocFontProvider, remoteFontProvider, localFontProvider, readOs2FsType, isEmbeddingRestricted, NO_FONT, } from './core/fonts/provider.js';
|
|
23
|
+
export type { FontProvider, FontRequest, FontAnswer } from './core/fonts/provider.js';
|
|
24
|
+
export { svgWriter, writeSvg } from './svg/svg-writer.js';
|
|
25
|
+
export type { SvgWriteOptions } from './svg/svg-writer.js';
|
|
26
|
+
export { layoutStyledDocument } from './pdf/styled-page-renderer.js';
|
|
27
|
+
export type { LaidOutDocument } from './pdf/styled-page-renderer.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { fetchFontSet, resolveFamilyKey } from "./core/fonts/remote-fonts.js";
|
|
2
|
+
import { parseTtf } from "./core/font/ttf-parser.js";
|
|
3
|
+
import { subsetTtf } from "./core/font/ttf-subset.js";
|
|
4
|
+
import { FontRegistry } from "./core/font/font-registry.js";
|
|
5
|
+
import { eighthPtToPt, emuToPt, halfPtToPt, inchToPt, mmToPt, pt, pxToPt, twipsToPt } from "./core/ir/units.js";
|
|
6
|
+
import { ResourceStore } from "./core/ir/resources.js";
|
|
7
|
+
import { FEATURES } from "./core/ir/features.js";
|
|
8
|
+
import { ConversionLossError, formatLoss } from "./core/ir/loss.js";
|
|
5
9
|
import { signPdf } from "./pdf/signature.js";
|
|
6
|
-
import { renderStyledPdf } from "./pdf/styled-page-renderer.js";
|
|
10
|
+
import { layoutStyledDocument, renderStyledPdf } from "./pdf/styled-page-renderer.js";
|
|
7
11
|
import "./pdf/index.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import "./
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import { createHyphenator, splitPatternBundle } from "./core/hyphenation/liang.js";
|
|
13
|
+
import { createLanguageHyphenator, getHyphenator } from "./core/hyphenation/index.js";
|
|
14
|
+
import { docxReader, readDocx } from "./word/docx-reader.js";
|
|
15
|
+
import { readXlsx, xlsxReader } from "./excel/xlsx-reader.js";
|
|
16
|
+
import { NO_FONT, callerFontProvider, chainProviders, embeddedDocFontProvider, isEmbeddingRestricted, localFontProvider, readOs2FsType, remoteFontProvider } from "./core/fonts/provider.js";
|
|
17
|
+
import { svgWriter, writeSvg } from "./svg/svg-writer.js";
|
|
18
|
+
import { createConverter } from "./core/converter/facade.js";
|
|
19
|
+
import { Ream } from "./core/converter/ream.js";
|
|
20
|
+
export { ConversionLossError, FEATURES, FontRegistry, NO_FONT, Ream, ResourceStore, callerFontProvider, chainProviders, createConverter, createHyphenator, createLanguageHyphenator, docxReader, eighthPtToPt, embeddedDocFontProvider, emuToPt, fetchFontSet, formatLoss, getHyphenator, halfPtToPt, inchToPt, isEmbeddingRestricted, layoutStyledDocument, localFontProvider, mmToPt, parseTtf, pt, pxToPt, readDocx, readOs2FsType, readXlsx, remoteFontProvider, renderStyledPdf, resolveFamilyKey, signPdf, splitPatternBundle, subsetTtf, svgWriter, twipsToPt, writeSvg, xlsxReader };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParsedTtf } from '../font/index.js';
|
|
1
|
+
import { ParsedTtf } from '../core/font/index.js';
|
|
2
2
|
import { PdfRef } from './objects.js';
|
|
3
3
|
import { PdfDocument } from './writer.js';
|
|
4
4
|
export interface EmbedTtfOptions {
|
|
@@ -12,4 +12,10 @@ export interface EmbeddedFont {
|
|
|
12
12
|
readonly textWidthPt: (text: string, fontSize: number) => number;
|
|
13
13
|
readonly encodeTextAsCidHex: (text: string) => string;
|
|
14
14
|
}
|
|
15
|
+
export interface FontMeasure {
|
|
16
|
+
readonly pdfWidthForGid: (gid: number) => number;
|
|
17
|
+
readonly textWidthPt: (text: string, fontSize: number) => number;
|
|
18
|
+
readonly encodeTextAsCidHex: (text: string) => string;
|
|
19
|
+
}
|
|
20
|
+
export declare function createFontMeasure(parsed: ParsedTtf): FontMeasure;
|
|
15
21
|
export declare function embedTtfFont(doc: PdfDocument, parsed: ParsedTtf, options?: EmbedTtfOptions): EmbeddedFont;
|
package/dist/esm/pdf/cid-font.js
CHANGED
|
@@ -1,8 +1,34 @@
|
|
|
1
|
-
import { shapeText } from "../font/opentype-layout.js";
|
|
2
|
-
import { glyphClosure, subsetTtf } from "../font/ttf-subset.js";
|
|
1
|
+
import { shapeText } from "../core/font/opentype-layout.js";
|
|
2
|
+
import { glyphClosure, subsetTtf } from "../core/font/ttf-subset.js";
|
|
3
3
|
import { dict, name, ref, stream } from "./objects.js";
|
|
4
4
|
//#region src/pdf/cid-font.ts
|
|
5
5
|
var encoder = new TextEncoder();
|
|
6
|
+
function createFontMeasure(parsed) {
|
|
7
|
+
const scale = 1e3 / parsed.unitsPerEm;
|
|
8
|
+
const widths = new Array(parsed.numGlyphs);
|
|
9
|
+
for (let i = 0; i < parsed.numGlyphs; i++) widths[i] = Math.round((parsed.advanceWidths[i] ?? 0) * scale);
|
|
10
|
+
const pdfWidthForGid = (gid) => {
|
|
11
|
+
if (gid < 0 || gid >= parsed.numGlyphs) return 1e3;
|
|
12
|
+
return widths[gid];
|
|
13
|
+
};
|
|
14
|
+
const textWidthPt = (text, fontSize) => {
|
|
15
|
+
const shaped = shapeText(text, parsed.glyphForCodepoint, parsed.advanceWidths, parsed.ligatures, parsed.kerning, parsed.joiningForms);
|
|
16
|
+
let totalEm = 0;
|
|
17
|
+
for (const a of shaped.advances) totalEm += a;
|
|
18
|
+
return totalEm * fontSize / parsed.unitsPerEm;
|
|
19
|
+
};
|
|
20
|
+
const encodeTextAsCidHex = (text) => {
|
|
21
|
+
const shaped = shapeText(text, parsed.glyphForCodepoint, parsed.advanceWidths, parsed.ligatures, parsed.kerning, parsed.joiningForms);
|
|
22
|
+
let out = "";
|
|
23
|
+
for (const gid of shaped.gids) out += gid.toString(16).padStart(4, "0").toUpperCase();
|
|
24
|
+
return out;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
pdfWidthForGid,
|
|
28
|
+
textWidthPt,
|
|
29
|
+
encodeTextAsCidHex
|
|
30
|
+
};
|
|
31
|
+
}
|
|
6
32
|
function embedTtfFont(doc, parsed, options = {}) {
|
|
7
33
|
const scale = 1e3 / parsed.unitsPerEm;
|
|
8
34
|
const toPdfUnits = (v) => Math.round(v * scale);
|
|
@@ -55,28 +81,13 @@ function embedTtfFont(doc, parsed, options = {}) {
|
|
|
55
81
|
DescendantFonts: [ref(cidFontRef.id)],
|
|
56
82
|
ToUnicode: ref(toUnicodeRef.id)
|
|
57
83
|
}));
|
|
58
|
-
const
|
|
59
|
-
if (gid < 0 || gid >= parsed.numGlyphs) return 1e3;
|
|
60
|
-
return widths[gid];
|
|
61
|
-
};
|
|
62
|
-
const textWidthPt = (text, fontSize) => {
|
|
63
|
-
const shaped = shapeText(text, parsed.glyphForCodepoint, parsed.advanceWidths, parsed.ligatures, parsed.kerning, parsed.joiningForms);
|
|
64
|
-
let totalEm = 0;
|
|
65
|
-
for (const a of shaped.advances) totalEm += a;
|
|
66
|
-
return totalEm * fontSize / parsed.unitsPerEm;
|
|
67
|
-
};
|
|
68
|
-
const encodeTextAsCidHexFn = (text) => {
|
|
69
|
-
const shaped = shapeText(text, parsed.glyphForCodepoint, parsed.advanceWidths, parsed.ligatures, parsed.kerning, parsed.joiningForms);
|
|
70
|
-
let out = "";
|
|
71
|
-
for (const gid of shaped.gids) out += gid.toString(16).padStart(4, "0").toUpperCase();
|
|
72
|
-
return out;
|
|
73
|
-
};
|
|
84
|
+
const measure = createFontMeasure(parsed);
|
|
74
85
|
return {
|
|
75
86
|
fontRef: type0Ref,
|
|
76
87
|
parsed,
|
|
77
|
-
pdfWidthForGid,
|
|
78
|
-
textWidthPt,
|
|
79
|
-
encodeTextAsCidHex:
|
|
88
|
+
pdfWidthForGid: measure.pdfWidthForGid,
|
|
89
|
+
textWidthPt: measure.textWidthPt,
|
|
90
|
+
encodeTextAsCidHex: measure.encodeTextAsCidHex
|
|
80
91
|
};
|
|
81
92
|
}
|
|
82
93
|
function buildCidSet(cids) {
|
|
@@ -171,4 +182,4 @@ function buildToUnicodeCMap(parsed) {
|
|
|
171
182
|
return encoder.encode(lines.join("\n"));
|
|
172
183
|
}
|
|
173
184
|
//#endregion
|
|
174
|
-
export { embedTtfFont };
|
|
185
|
+
export { createFontMeasure, embedTtfFont };
|
|
@@ -10,4 +10,17 @@ export declare function detectImageFormat(bytes: Uint8Array): ImageFormat | null
|
|
|
10
10
|
export interface EmbedImageOptions {
|
|
11
11
|
readonly flattenAlpha?: boolean;
|
|
12
12
|
}
|
|
13
|
+
export interface PreparedImage {
|
|
14
|
+
readonly format: ImageFormat;
|
|
15
|
+
readonly mimeType: 'image/jp2' | 'image/jpeg' | 'image/png';
|
|
16
|
+
readonly widthPx: number;
|
|
17
|
+
readonly heightPx: number;
|
|
18
|
+
readonly colorSpace?: 'DeviceGray' | 'DeviceRGB';
|
|
19
|
+
readonly bitsPerComponent?: number;
|
|
20
|
+
readonly filter: 'DCTDecode' | 'FlateDecode' | 'JPXDecode';
|
|
21
|
+
readonly data: Uint8Array;
|
|
22
|
+
readonly smaskData?: Uint8Array;
|
|
23
|
+
}
|
|
24
|
+
export declare function prepareImage(bytes: Uint8Array, options?: EmbedImageOptions): PreparedImage;
|
|
25
|
+
export declare function addImage(doc: PdfDocument, prepared: PreparedImage): EmbeddedImage;
|
|
13
26
|
export declare function embedImage(doc: PdfDocument, bytes: Uint8Array, options?: EmbedImageOptions): EmbeddedImage;
|
|
@@ -8,25 +8,49 @@ function detectImageFormat(bytes) {
|
|
|
8
8
|
if (bytes.length >= 4 && bytes[0] === 255 && bytes[1] === 79 && bytes[2] === 255 && bytes[3] === 81) return "jpeg2000";
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function prepareImage(bytes, options = {}) {
|
|
12
12
|
const format = detectImageFormat(bytes);
|
|
13
|
-
if (format === "jpeg") return
|
|
14
|
-
if (format === "png") return
|
|
15
|
-
if (format === "jpeg2000") return
|
|
13
|
+
if (format === "jpeg") return prepareJpeg(bytes);
|
|
14
|
+
if (format === "png") return preparePng(bytes, options);
|
|
15
|
+
if (format === "jpeg2000") return prepareJpeg2000(bytes);
|
|
16
16
|
throw new Error("Unsupported image format");
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function addImage(doc, prepared) {
|
|
19
|
+
let smaskRef;
|
|
20
|
+
if (prepared.smaskData) smaskRef = doc.add(stream({
|
|
21
|
+
Type: name("XObject"),
|
|
22
|
+
Subtype: name("Image"),
|
|
23
|
+
Width: prepared.widthPx,
|
|
24
|
+
Height: prepared.heightPx,
|
|
25
|
+
ColorSpace: name("DeviceGray"),
|
|
26
|
+
BitsPerComponent: 8,
|
|
27
|
+
Filter: name("FlateDecode")
|
|
28
|
+
}, prepared.smaskData));
|
|
29
|
+
const entries = {
|
|
30
|
+
Type: name("XObject"),
|
|
31
|
+
Subtype: name("Image"),
|
|
32
|
+
Width: prepared.widthPx,
|
|
33
|
+
Height: prepared.heightPx,
|
|
34
|
+
...prepared.colorSpace ? { ColorSpace: name(prepared.colorSpace) } : {},
|
|
35
|
+
...prepared.bitsPerComponent !== void 0 ? { BitsPerComponent: prepared.bitsPerComponent } : {},
|
|
36
|
+
Filter: name(prepared.filter)
|
|
37
|
+
};
|
|
38
|
+
if (smaskRef) entries["SMask"] = smaskRef;
|
|
39
|
+
return {
|
|
40
|
+
ref: doc.add(stream(entries, prepared.data)),
|
|
41
|
+
widthPx: prepared.widthPx,
|
|
42
|
+
heightPx: prepared.heightPx
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function prepareJpeg2000(bytes) {
|
|
19
46
|
const { width, height } = readJpeg2000Info(bytes);
|
|
20
47
|
return {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Subtype: name("Image"),
|
|
24
|
-
Width: width,
|
|
25
|
-
Height: height,
|
|
26
|
-
Filter: name("JPXDecode")
|
|
27
|
-
}, bytes)),
|
|
48
|
+
format: "jpeg2000",
|
|
49
|
+
mimeType: "image/jp2",
|
|
28
50
|
widthPx: width,
|
|
29
|
-
heightPx: height
|
|
51
|
+
heightPx: height,
|
|
52
|
+
filter: "JPXDecode",
|
|
53
|
+
data: bytes
|
|
30
54
|
};
|
|
31
55
|
}
|
|
32
56
|
function readU32(b, o) {
|
|
@@ -76,21 +100,17 @@ function readSiz(bytes, sizOffset) {
|
|
|
76
100
|
height
|
|
77
101
|
};
|
|
78
102
|
}
|
|
79
|
-
function
|
|
103
|
+
function prepareJpeg(bytes) {
|
|
80
104
|
const info = readJpegInfo(bytes);
|
|
81
|
-
const colorSpace = info.numComponents === 1 ? "DeviceGray" : "DeviceRGB";
|
|
82
105
|
return {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
Subtype: name("Image"),
|
|
86
|
-
Width: info.width,
|
|
87
|
-
Height: info.height,
|
|
88
|
-
ColorSpace: name(colorSpace),
|
|
89
|
-
BitsPerComponent: info.precision,
|
|
90
|
-
Filter: name("DCTDecode")
|
|
91
|
-
}, bytes)),
|
|
106
|
+
format: "jpeg",
|
|
107
|
+
mimeType: "image/jpeg",
|
|
92
108
|
widthPx: info.width,
|
|
93
|
-
heightPx: info.height
|
|
109
|
+
heightPx: info.height,
|
|
110
|
+
colorSpace: info.numComponents === 1 ? "DeviceGray" : "DeviceRGB",
|
|
111
|
+
bitsPerComponent: info.precision,
|
|
112
|
+
filter: "DCTDecode",
|
|
113
|
+
data: bytes
|
|
94
114
|
};
|
|
95
115
|
}
|
|
96
116
|
function readJpegInfo(bytes) {
|
|
@@ -121,38 +141,19 @@ function readJpegInfo(bytes) {
|
|
|
121
141
|
}
|
|
122
142
|
throw new Error("JPEG SOFn marker not found");
|
|
123
143
|
}
|
|
124
|
-
function
|
|
144
|
+
function preparePng(bytes, options = {}) {
|
|
125
145
|
let decoded = decodePng(bytes);
|
|
126
146
|
if (options.flattenAlpha && decoded.smaskRaw) decoded = flattenAlphaOnWhite(decoded);
|
|
127
|
-
const compressedColor = zlibSync(decoded.raw);
|
|
128
|
-
const baseDict = {
|
|
129
|
-
Type: name("XObject"),
|
|
130
|
-
Subtype: name("Image"),
|
|
131
|
-
Width: decoded.width,
|
|
132
|
-
Height: decoded.height,
|
|
133
|
-
ColorSpace: name(decoded.colorSpace),
|
|
134
|
-
BitsPerComponent: decoded.bitsPerComponent,
|
|
135
|
-
Filter: name("FlateDecode")
|
|
136
|
-
};
|
|
137
|
-
let smaskRef;
|
|
138
|
-
if (decoded.smaskRaw) {
|
|
139
|
-
const compressedAlpha = zlibSync(decoded.smaskRaw);
|
|
140
|
-
smaskRef = doc.add(stream({
|
|
141
|
-
Type: name("XObject"),
|
|
142
|
-
Subtype: name("Image"),
|
|
143
|
-
Width: decoded.width,
|
|
144
|
-
Height: decoded.height,
|
|
145
|
-
ColorSpace: name("DeviceGray"),
|
|
146
|
-
BitsPerComponent: 8,
|
|
147
|
-
Filter: name("FlateDecode")
|
|
148
|
-
}, compressedAlpha));
|
|
149
|
-
}
|
|
150
|
-
const entries = { ...baseDict };
|
|
151
|
-
if (smaskRef) entries["SMask"] = smaskRef;
|
|
152
147
|
return {
|
|
153
|
-
|
|
148
|
+
format: "png",
|
|
149
|
+
mimeType: "image/png",
|
|
154
150
|
widthPx: decoded.width,
|
|
155
|
-
heightPx: decoded.height
|
|
151
|
+
heightPx: decoded.height,
|
|
152
|
+
colorSpace: decoded.colorSpace,
|
|
153
|
+
bitsPerComponent: decoded.bitsPerComponent,
|
|
154
|
+
filter: "FlateDecode",
|
|
155
|
+
data: zlibSync(decoded.raw),
|
|
156
|
+
...decoded.smaskRaw ? { smaskData: zlibSync(decoded.smaskRaw) } : {}
|
|
156
157
|
};
|
|
157
158
|
}
|
|
158
159
|
function decodePng(bytes) {
|
|
@@ -332,4 +333,4 @@ function concatBytes(parts) {
|
|
|
332
333
|
return out;
|
|
333
334
|
}
|
|
334
335
|
//#endregion
|
|
335
|
-
export { detectImageFormat,
|
|
336
|
+
export { addImage, detectImageFormat, prepareImage };
|
package/dist/esm/pdf/index.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export type { SignaturePlaceholder, SignerCredentials, SignatureOptions } from '
|
|
|
7
7
|
export type { AttachedFile, AFRelationship } from './embedded-file.js';
|
|
8
8
|
export { embedTtfFont } from './cid-font.js';
|
|
9
9
|
export type { EmbeddedFont } from './cid-font.js';
|
|
10
|
-
export {
|
|
11
|
-
export type { EmbeddedImage, ImageFormat } from './image-xobject.js';
|
|
10
|
+
export { addImage, detectImageFormat, embedImage, prepareImage } from './image-xobject.js';
|
|
11
|
+
export type { EmbeddedImage, ImageFormat, PreparedImage } from './image-xobject.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MathNode } from '../document-model/index.js';
|
|
1
|
+
import { MathNode } from '../core/document-model/index.js';
|
|
2
2
|
import { PathSegment } from './vector-graphics.js';
|
|
3
3
|
export type MathVariant = 'regular' | 'italic' | 'bold' | 'boldItalic';
|
|
4
4
|
export interface MathGlyphItem {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomGeometry } from '../document-model/index.js';
|
|
1
|
+
import { CustomGeometry } from '../core/document-model/index.js';
|
|
2
2
|
import { PathSegment, VectorPath } from './vector-graphics.js';
|
|
3
3
|
export declare function rectSegments(w: number, h: number): ReadonlyArray<PathSegment>;
|
|
4
4
|
export declare function rectPath(w: number, h: number): VectorPath;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PdfHexString, PdfRawToken, dict, name, ref } from "./objects.js";
|
|
2
|
-
import { integer, seq } from "../crypto/asn1.js";
|
|
3
|
-
import { buildPkcs7Detached } from "../crypto/cms.js";
|
|
4
|
-
import "../crypto/index.js";
|
|
2
|
+
import { integer, seq } from "../core/crypto/asn1.js";
|
|
3
|
+
import { buildPkcs7Detached } from "../core/crypto/cms.js";
|
|
4
|
+
import "../core/crypto/index.js";
|
|
5
5
|
//#region src/pdf/signature.ts
|
|
6
6
|
var BYTE_RANGE_PLACEHOLDER = "[0 0000000000 0000000000 0000000000]";
|
|
7
7
|
var DEFAULT_RESERVE_BYTES = 8192;
|
|
@@ -80,7 +80,7 @@ function toHex(bytes) {
|
|
|
80
80
|
}
|
|
81
81
|
async function signPdf(pdf, cred) {
|
|
82
82
|
const out = pdf.slice();
|
|
83
|
-
const brKey = indexOfAscii(out,
|
|
83
|
+
const brKey = indexOfAscii(out, `/ByteRange ${BYTE_RANGE_PLACEHOLDER}`);
|
|
84
84
|
if (brKey < 0) throw new Error("signPdf: no /ByteRange placeholder found");
|
|
85
85
|
const brOpen = indexOfAscii(out, "[", brKey);
|
|
86
86
|
const brClose = indexOfAscii(out, "]", brOpen);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { LaidOutDocument, StyledRenderOptions } from './styled-page-renderer.js';
|
|
2
|
+
import { PdfDocument } from './writer.js';
|
|
3
|
+
type EmitOptions = Pick<StyledRenderOptions, 'attachments' | 'info' | 'language' | 'signaturePlaceholder'>;
|
|
4
|
+
export declare function emitStyledPdf(laid: LaidOutDocument, options: EmitOptions, doc: PdfDocument): Uint8Array;
|
|
5
|
+
export {};
|