abstract-document 16.0.0 → 16.0.2
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/CHANGELOG.md +4 -0
- package/lib/abstract-document/abstract-doc.d.ts.map +1 -1
- package/lib/abstract-document/abstract-doc.js +14 -5
- package/lib/abstract-document/abstract-doc.js.map +1 -1
- package/lib/abstract-document/resources.d.ts +1 -4
- package/lib/abstract-document/resources.d.ts.map +1 -1
- package/lib/abstract-document/resources.js +21 -12
- package/lib/abstract-document/resources.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.d.ts +2 -1
- package/lib/abstract-document-exporters/docx2/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.js +4 -4
- package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.d.ts +2 -2
- package/lib/abstract-document-exporters/docx2/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.js +26 -26
- package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js +4 -3
- package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.d.ts +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +6 -6
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.d.ts +2 -2
- package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +26 -26
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/package.json +2 -2
- package/src/abstract-document/abstract-doc.ts +20 -7
- package/src/abstract-document/resources.ts +29 -16
- package/src/abstract-document-exporters/docx2/render-image.ts +5 -8
- package/src/abstract-document-exporters/docx2/render.ts +26 -49
- package/src/abstract-document-exporters/pdf/pre-process.ts +4 -3
- package/src/abstract-document-exporters/pdf/render-image.ts +7 -10
- package/src/abstract-document-exporters/pdf/render.ts +26 -66
|
@@ -35,24 +35,17 @@ import { Readable } from "stream";
|
|
|
35
35
|
const abstractDocToDocxFontRatio = 2;
|
|
36
36
|
const abstractDocPixelToDocxDXARatio = 20;
|
|
37
37
|
|
|
38
|
-
export function exportToHTML5Blob(
|
|
39
|
-
doc: AD.AbstractDoc.AbstractDoc,
|
|
40
|
-
imageDataByUrl: Record<string, Uint8Array | string> = {}
|
|
41
|
-
): Promise<Blob> {
|
|
38
|
+
export function exportToHTML5Blob(doc: AD.AbstractDoc.AbstractDoc): Promise<Blob> {
|
|
42
39
|
return new Promise((resolve) => {
|
|
43
|
-
const docx = createDocument(doc
|
|
40
|
+
const docx = createDocument(doc);
|
|
44
41
|
Packer.toBlob(docx).then((blob) => {
|
|
45
42
|
resolve(blob);
|
|
46
43
|
});
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
export function exportToStream(
|
|
51
|
-
|
|
52
|
-
doc: AD.AbstractDoc.AbstractDoc,
|
|
53
|
-
imageDataByUrl: Record<string, Uint8Array | string> = {}
|
|
54
|
-
): void {
|
|
55
|
-
const docx = createDocument(doc, imageDataByUrl);
|
|
47
|
+
export function exportToStream(blobStream: NodeJS.WritableStream, doc: AD.AbstractDoc.AbstractDoc): void {
|
|
48
|
+
const docx = createDocument(doc);
|
|
56
49
|
|
|
57
50
|
Packer.toBuffer(docx).then((buffer) => {
|
|
58
51
|
const readableStream = new Readable();
|
|
@@ -69,21 +62,14 @@ export function exportToStream(
|
|
|
69
62
|
* @param doc
|
|
70
63
|
*/
|
|
71
64
|
|
|
72
|
-
function createDocument(
|
|
73
|
-
doc: AD.AbstractDoc.AbstractDoc,
|
|
74
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
75
|
-
): Document {
|
|
65
|
+
function createDocument(doc: AD.AbstractDoc.AbstractDoc): Document {
|
|
76
66
|
const docx = new Document({
|
|
77
|
-
sections: doc.children.map((s) => renderSection(s, doc
|
|
67
|
+
sections: doc.children.map((s) => renderSection(s, doc)),
|
|
78
68
|
});
|
|
79
69
|
return docx;
|
|
80
70
|
}
|
|
81
71
|
|
|
82
|
-
function renderSection(
|
|
83
|
-
section: AD.Section.Section,
|
|
84
|
-
parentResources: AD.Resources.Resources,
|
|
85
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
86
|
-
): ISectionOptions {
|
|
72
|
+
function renderSection(section: AD.Section.Section, parentResources: AD.Resources.Resources): ISectionOptions {
|
|
87
73
|
const pageWidth = AD.PageStyle.getWidth(section.page.style);
|
|
88
74
|
const pageHeight = AD.PageStyle.getHeight(section.page.style);
|
|
89
75
|
|
|
@@ -93,13 +79,13 @@ function renderSection(
|
|
|
93
79
|
const resources = AD.Resources.mergeResources([parentResources, section]);
|
|
94
80
|
|
|
95
81
|
const headerChildren = section.page.header.reduce((sofar, c) => {
|
|
96
|
-
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth
|
|
82
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
97
83
|
return sofar;
|
|
98
84
|
}, [] as Array<Paragraph | Table>);
|
|
99
85
|
|
|
100
86
|
const footerChildren = [
|
|
101
87
|
...section.page.footer.reduce((sofar, c) => {
|
|
102
|
-
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth
|
|
88
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
103
89
|
return sofar;
|
|
104
90
|
}, [] as Array<Paragraph | Table>),
|
|
105
91
|
];
|
|
@@ -115,7 +101,7 @@ function renderSection(
|
|
|
115
101
|
],
|
|
116
102
|
}),
|
|
117
103
|
...section.children.reduce((sofar, c) => {
|
|
118
|
-
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth
|
|
104
|
+
sofar.push(...renderSectionElement(c, resources, contentAvailableWidth));
|
|
119
105
|
return sofar;
|
|
120
106
|
}, [] as Array<Paragraph | Table>),
|
|
121
107
|
];
|
|
@@ -191,17 +177,16 @@ function renderSectionElement(
|
|
|
191
177
|
element: AD.SectionElement.SectionElement,
|
|
192
178
|
parentResources: AD.Resources.Resources,
|
|
193
179
|
contentAvailableWidth: number,
|
|
194
|
-
keepNext: boolean
|
|
195
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
180
|
+
keepNext: boolean = false
|
|
196
181
|
): ReadonlyArray<Paragraph | Table> /*| DOCXJS.TableOfContents | DOCXJS.HyperlinkRef */ {
|
|
197
182
|
const resources = AD.Resources.mergeResources([parentResources, element]);
|
|
198
183
|
switch (element.type) {
|
|
199
184
|
case "Paragraph":
|
|
200
|
-
return [renderParagraph(element, resources, keepNext
|
|
185
|
+
return [renderParagraph(element, resources, keepNext)];
|
|
201
186
|
case "Group":
|
|
202
|
-
return [...renderGroup(element, parentResources, contentAvailableWidth
|
|
187
|
+
return [...renderGroup(element, parentResources, contentAvailableWidth)];
|
|
203
188
|
case "Table":
|
|
204
|
-
const table = renderTable(element, resources, contentAvailableWidth, keepNext
|
|
189
|
+
const table = renderTable(element, resources, contentAvailableWidth, keepNext);
|
|
205
190
|
return table
|
|
206
191
|
? [table, new Paragraph({ keepNext: keepNext, children: [new TextRun({ text: ".", size: 0.000001 })] })]
|
|
207
192
|
: [];
|
|
@@ -220,8 +205,7 @@ function renderTable(
|
|
|
220
205
|
table: AD.Table.Table,
|
|
221
206
|
resources: AD.Resources.Resources,
|
|
222
207
|
contentAvailableWidth: number,
|
|
223
|
-
keepNext: boolean
|
|
224
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
208
|
+
keepNext: boolean
|
|
225
209
|
): Table | undefined {
|
|
226
210
|
const style = AD.Resources.getStyle(
|
|
227
211
|
undefined,
|
|
@@ -294,7 +278,7 @@ function renderTable(
|
|
|
294
278
|
style: BorderStyle.NONE,
|
|
295
279
|
},
|
|
296
280
|
},
|
|
297
|
-
rows: table.children.map((c) => renderRow(c, resources, style.cellStyle, columnWidths, keepNext
|
|
281
|
+
rows: table.children.map((c) => renderRow(c, resources, style.cellStyle, columnWidths, keepNext)),
|
|
298
282
|
});
|
|
299
283
|
}
|
|
300
284
|
|
|
@@ -303,14 +287,11 @@ function renderRow(
|
|
|
303
287
|
resources: AD.Resources.Resources,
|
|
304
288
|
tableCellStyle: AD.TableCellStyle.TableCellStyle,
|
|
305
289
|
columnWidths: ReadonlyArray<number>,
|
|
306
|
-
keepNext: boolean
|
|
307
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
290
|
+
keepNext: boolean
|
|
308
291
|
): TableRow {
|
|
309
292
|
return new TableRow({
|
|
310
293
|
cantSplit: true,
|
|
311
|
-
children: row.children.map((c, ix) =>
|
|
312
|
-
renderCell(c, resources, tableCellStyle, columnWidths[ix], keepNext, imageDataByUrl)
|
|
313
|
-
),
|
|
294
|
+
children: row.children.map((c, ix) => renderCell(c, resources, tableCellStyle, columnWidths[ix], keepNext)),
|
|
314
295
|
});
|
|
315
296
|
}
|
|
316
297
|
|
|
@@ -319,8 +300,7 @@ function renderCell(
|
|
|
319
300
|
resources: AD.Resources.Resources,
|
|
320
301
|
tableCellStyle: AD.TableCellStyle.TableCellStyle,
|
|
321
302
|
width: number,
|
|
322
|
-
keepNext: boolean
|
|
323
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
303
|
+
keepNext: boolean
|
|
324
304
|
): TableCell {
|
|
325
305
|
const style = AD.Resources.getStyle(
|
|
326
306
|
tableCellStyle,
|
|
@@ -376,7 +356,7 @@ function renderCell(
|
|
|
376
356
|
},
|
|
377
357
|
|
|
378
358
|
children: cell.children.reduce((sofar, c) => {
|
|
379
|
-
sofar.push(...renderSectionElement(c, resources, width, keepNext
|
|
359
|
+
sofar.push(...renderSectionElement(c, resources, width, keepNext));
|
|
380
360
|
return sofar;
|
|
381
361
|
}, [] as Array<Paragraph | Table>),
|
|
382
362
|
});
|
|
@@ -385,8 +365,7 @@ function renderCell(
|
|
|
385
365
|
function renderAtom(
|
|
386
366
|
resources: AD.Resources.Resources,
|
|
387
367
|
textStyle: AD.TextStyle.TextStyle,
|
|
388
|
-
atom: AD.Atom.Atom
|
|
389
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
368
|
+
atom: AD.Atom.Atom
|
|
390
369
|
):
|
|
391
370
|
| TextRun
|
|
392
371
|
| ImageRun
|
|
@@ -406,7 +385,7 @@ function renderAtom(
|
|
|
406
385
|
case "TextRun":
|
|
407
386
|
return renderTextRun(resources, textStyle, atom);
|
|
408
387
|
case "Image":
|
|
409
|
-
return renderImage(atom, textStyle,
|
|
388
|
+
return renderImage(atom, textStyle, resources);
|
|
410
389
|
case "HyperLink":
|
|
411
390
|
return renderHyperLink(atom, textStyle);
|
|
412
391
|
case "TocSeparator":
|
|
@@ -515,8 +494,7 @@ function renderText(style: AD.TextStyle.TextStyle, text: string): TextRun {
|
|
|
515
494
|
function renderGroup(
|
|
516
495
|
group: AD.Group.Group,
|
|
517
496
|
resources: AD.Resources.Resources,
|
|
518
|
-
availabelWidth: number
|
|
519
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
497
|
+
availabelWidth: number
|
|
520
498
|
): Array<Paragraph | Table> {
|
|
521
499
|
let sofar = Array<Paragraph | Table>();
|
|
522
500
|
let keepNext = true;
|
|
@@ -524,7 +502,7 @@ function renderGroup(
|
|
|
524
502
|
if (index == group.children.length - 1) {
|
|
525
503
|
keepNext = false;
|
|
526
504
|
}
|
|
527
|
-
sofar.push(...renderSectionElement(group.children[index], resources, availabelWidth, keepNext
|
|
505
|
+
sofar.push(...renderSectionElement(group.children[index], resources, availabelWidth, keepNext));
|
|
528
506
|
}
|
|
529
507
|
return sofar;
|
|
530
508
|
}
|
|
@@ -532,8 +510,7 @@ function renderGroup(
|
|
|
532
510
|
function renderParagraph(
|
|
533
511
|
paragraph: AD.Paragraph.Paragraph,
|
|
534
512
|
resources: AD.Resources.Resources,
|
|
535
|
-
keepNext: boolean
|
|
536
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
513
|
+
keepNext: boolean
|
|
537
514
|
): Paragraph {
|
|
538
515
|
const style = AD.Resources.getStyle(
|
|
539
516
|
undefined,
|
|
@@ -562,6 +539,6 @@ function renderParagraph(
|
|
|
562
539
|
left: Math.max(style.margins.left, 0) * abstractDocPixelToDocxDXARatio,
|
|
563
540
|
right: Math.max(style.margins.right, 0) * abstractDocPixelToDocxDXARatio,
|
|
564
541
|
},
|
|
565
|
-
children: paragraph.children.map((atom) => renderAtom(resources, style.textStyle, atom
|
|
542
|
+
children: paragraph.children.map((atom) => renderAtom(resources, style.textStyle, atom)),
|
|
566
543
|
});
|
|
567
544
|
}
|
|
@@ -38,10 +38,11 @@ export function preProcess(doc: AD.AbstractDoc.AbstractDoc): AD.AbstractDoc.Abst
|
|
|
38
38
|
return AD.AbstractDoc.create(
|
|
39
39
|
{
|
|
40
40
|
fonts: doc.fonts,
|
|
41
|
-
imageResources: doc.imageResources,
|
|
42
41
|
styles: doc.styles,
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
imageDataByUrl: doc.imageDataByUrl,
|
|
43
|
+
// imageResources: doc.imageResources,
|
|
44
|
+
// numberings: doc.numberings,
|
|
45
|
+
// numberingDefinitions: doc.numberingDefinitions,
|
|
45
46
|
},
|
|
46
47
|
children
|
|
47
48
|
);
|
|
@@ -8,8 +8,7 @@ export function renderImage(
|
|
|
8
8
|
pdf: PDFKit.PDFDocument,
|
|
9
9
|
finalRect: AD.Rect.Rect,
|
|
10
10
|
textStyle: AD.TextStyle.TextStyle,
|
|
11
|
-
image: AD.Image.Image
|
|
12
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
11
|
+
image: AD.Image.Image
|
|
13
12
|
): void {
|
|
14
13
|
const aImage = image.imageResource.abstractImage;
|
|
15
14
|
const position = AD.Point.create(finalRect.x, finalRect.y);
|
|
@@ -17,10 +16,9 @@ export function renderImage(
|
|
|
17
16
|
const scaleY = finalRect.height / aImage.size.height;
|
|
18
17
|
const scale = Math.min(scaleX, scaleY);
|
|
19
18
|
pdf.save();
|
|
19
|
+
|
|
20
20
|
pdf.translate(position.x, position.y).scale(scale);
|
|
21
|
-
aImage.components.forEach((c: AbstractImage.Component) =>
|
|
22
|
-
abstractComponentToPdf(resources, pdf, c, textStyle, imageDataByUrl)
|
|
23
|
-
);
|
|
21
|
+
aImage.components.forEach((c: AbstractImage.Component) => abstractComponentToPdf(resources, pdf, c, textStyle));
|
|
24
22
|
pdf.restore();
|
|
25
23
|
}
|
|
26
24
|
|
|
@@ -28,20 +26,19 @@ function abstractComponentToPdf(
|
|
|
28
26
|
resources: AD.Resources.Resources,
|
|
29
27
|
pdf: PDFKit.PDFDocument,
|
|
30
28
|
component: AbstractImage.Component,
|
|
31
|
-
textStyle: AD.TextStyle.TextStyle
|
|
32
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
29
|
+
textStyle: AD.TextStyle.TextStyle
|
|
33
30
|
): void {
|
|
34
31
|
switch (component.type) {
|
|
35
32
|
case "group":
|
|
36
|
-
component.children.forEach((c) => abstractComponentToPdf(resources, pdf, c, textStyle
|
|
33
|
+
component.children.forEach((c) => abstractComponentToPdf(resources, pdf, c, textStyle));
|
|
37
34
|
break;
|
|
38
35
|
case "binaryimage":
|
|
39
36
|
const format = component.format.toLowerCase();
|
|
40
37
|
const imageWidth = component.bottomRight.x - component.topLeft.x;
|
|
41
38
|
const imageHeight = component.bottomRight.y - component.topLeft.y;
|
|
42
39
|
if (component.data.type === "url") {
|
|
43
|
-
const imageData = imageDataByUrl[component.data.url];
|
|
44
|
-
if (typeof imageData === "string" &&
|
|
40
|
+
const imageData = resources.imageDataByUrl?.[component.data.url];
|
|
41
|
+
if (typeof imageData === "string" && imageData.includes("<svg")) {
|
|
45
42
|
addWithSvgToPdfKit(imageData, component, pdf, resources, textStyle);
|
|
46
43
|
} else {
|
|
47
44
|
pdf.image(
|
|
@@ -13,11 +13,10 @@ export type PdfExportOptions = {
|
|
|
13
13
|
export function exportToHTML5Blob(
|
|
14
14
|
pdfKit: PDFKit.PDFDocument,
|
|
15
15
|
doc: AD.AbstractDoc.AbstractDoc,
|
|
16
|
-
options: PdfExportOptions = { compress: false }
|
|
17
|
-
imageDataByUrl: Record<string, Uint8Array | string> = {}
|
|
16
|
+
options: PdfExportOptions = { compress: false }
|
|
18
17
|
): Promise<Blob> {
|
|
19
18
|
return new Promise((resolve) => {
|
|
20
|
-
let pdf = createDocument(pdfKit, options, doc
|
|
19
|
+
let pdf = createDocument(pdfKit, options, doc);
|
|
21
20
|
const buffers = Array<BlobPart>();
|
|
22
21
|
pdf.on("data", buffers.push.bind(buffers));
|
|
23
22
|
pdf.on("end", () => resolve(new Blob(buffers, { type: "application/pdf" })));
|
|
@@ -36,18 +35,16 @@ export function exportToStream(
|
|
|
36
35
|
pdfKit: PDFKit.PDFDocument,
|
|
37
36
|
blobStream: any,
|
|
38
37
|
doc: AD.AbstractDoc.AbstractDoc,
|
|
39
|
-
options: PdfExportOptions = { compress: false }
|
|
40
|
-
imageDataByUrl: Record<string, Uint8Array | string> = {}
|
|
38
|
+
options: PdfExportOptions = { compress: false }
|
|
41
39
|
): void {
|
|
42
|
-
let pdf = createDocument(pdfKit, options, doc
|
|
40
|
+
let pdf = createDocument(pdfKit, options, doc);
|
|
43
41
|
pdf.pipe(blobStream);
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
function createDocument(
|
|
47
45
|
pdfKit: PDFKit.PDFDocument,
|
|
48
46
|
options: PdfExportOptions,
|
|
49
|
-
ad: AD.AbstractDoc.AbstractDoc
|
|
50
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
47
|
+
ad: AD.AbstractDoc.AbstractDoc
|
|
51
48
|
): PDFKit.PDFDocument {
|
|
52
49
|
const pdf = new pdfKit({ ...options, autoFirstPage: false, bufferPages: true });
|
|
53
50
|
|
|
@@ -59,7 +56,7 @@ function createDocument(
|
|
|
59
56
|
const pageDesiredSizes = measurePages(pdfKit, document, updatedPages);
|
|
60
57
|
|
|
61
58
|
for (let page of updatedPages) {
|
|
62
|
-
renderPage(document, pdf, pageDesiredSizes, page
|
|
59
|
+
renderPage(document, pdf, pageDesiredSizes, page);
|
|
63
60
|
}
|
|
64
61
|
pdf.end();
|
|
65
62
|
return pdf;
|
|
@@ -69,8 +66,7 @@ function renderPage(
|
|
|
69
66
|
parentResources: AD.Resources.Resources,
|
|
70
67
|
pdfKit: PDFKit.PDFDocument,
|
|
71
68
|
desiredSizes: Map<{}, AD.Size.Size>,
|
|
72
|
-
page: Page
|
|
73
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
69
|
+
page: Page
|
|
74
70
|
): void {
|
|
75
71
|
const section = page.section;
|
|
76
72
|
const style = section.page.style;
|
|
@@ -95,8 +91,7 @@ function renderPage(
|
|
|
95
91
|
pdfKit,
|
|
96
92
|
desiredSizes,
|
|
97
93
|
AD.Rect.create(headerX, isAbsolute ? headerStart : headerY, elementSize.width, elementSize.height),
|
|
98
|
-
element
|
|
99
|
-
imageDataByUrl
|
|
94
|
+
element
|
|
100
95
|
);
|
|
101
96
|
if (!isAbsolute) {
|
|
102
97
|
headerY += elementSize.height;
|
|
@@ -119,8 +114,7 @@ function renderPage(
|
|
|
119
114
|
pdfKit,
|
|
120
115
|
desiredSizes,
|
|
121
116
|
AD.Rect.create(footerX, isAbsolute ? footerStart : footerY, elementSize.width, elementSize.height),
|
|
122
|
-
element
|
|
123
|
-
imageDataByUrl
|
|
117
|
+
element
|
|
124
118
|
);
|
|
125
119
|
if (!isAbsolute) {
|
|
126
120
|
footerY += elementSize.height;
|
|
@@ -137,8 +131,7 @@ function renderPage(
|
|
|
137
131
|
pdfKit,
|
|
138
132
|
desiredSizes,
|
|
139
133
|
AD.Rect.create(contentRect.x, isAbsolute ? elementStart : y, elementSize.width, elementSize.height),
|
|
140
|
-
element
|
|
141
|
-
imageDataByUrl
|
|
134
|
+
element
|
|
142
135
|
);
|
|
143
136
|
if (!isAbsolute) {
|
|
144
137
|
y += elementSize.height;
|
|
@@ -167,19 +160,18 @@ function renderSectionElement(
|
|
|
167
160
|
pdf: PDFKit.PDFDocument,
|
|
168
161
|
desiredSizes: Map<{}, AD.Size.Size>,
|
|
169
162
|
finalRect: AD.Rect.Rect,
|
|
170
|
-
element: AD.SectionElement.SectionElement
|
|
171
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
163
|
+
element: AD.SectionElement.SectionElement
|
|
172
164
|
): void {
|
|
173
165
|
const resources = AD.Resources.mergeResources([parentResources, element]);
|
|
174
166
|
switch (element.type) {
|
|
175
167
|
case "Paragraph":
|
|
176
|
-
renderParagraph(resources, pdf, desiredSizes, finalRect, element
|
|
168
|
+
renderParagraph(resources, pdf, desiredSizes, finalRect, element);
|
|
177
169
|
return;
|
|
178
170
|
case "Table":
|
|
179
|
-
renderTable(resources, pdf, desiredSizes, finalRect, element
|
|
171
|
+
renderTable(resources, pdf, desiredSizes, finalRect, element);
|
|
180
172
|
return;
|
|
181
173
|
case "Group":
|
|
182
|
-
renderGroup(resources, pdf, desiredSizes, finalRect, element
|
|
174
|
+
renderGroup(resources, pdf, desiredSizes, finalRect, element);
|
|
183
175
|
return;
|
|
184
176
|
}
|
|
185
177
|
}
|
|
@@ -189,8 +181,7 @@ function renderGroup(
|
|
|
189
181
|
pdfKit: PDFKit.PDFDocument,
|
|
190
182
|
desiredSizes: Map<{}, AD.Size.Size>,
|
|
191
183
|
finalRect: AD.Rect.Rect,
|
|
192
|
-
group: AD.Group.Group
|
|
193
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
184
|
+
group: AD.Group.Group
|
|
194
185
|
): void {
|
|
195
186
|
const finalX = finalRect.x + group.style.margins.left;
|
|
196
187
|
const startY = finalRect.y + group.style.margins.top;
|
|
@@ -203,8 +194,7 @@ function renderGroup(
|
|
|
203
194
|
pdfKit,
|
|
204
195
|
desiredSizes,
|
|
205
196
|
AD.Rect.create(finalX, isAbsolute ? startY : y, elementSize.width, elementSize.height),
|
|
206
|
-
element
|
|
207
|
-
imageDataByUrl
|
|
197
|
+
element
|
|
208
198
|
);
|
|
209
199
|
if (!isAbsolute) {
|
|
210
200
|
y += elementSize.height;
|
|
@@ -217,8 +207,7 @@ function renderParagraph(
|
|
|
217
207
|
pdfKit: PDFKit.PDFDocument,
|
|
218
208
|
desiredSizes: Map<{}, AD.Size.Size>,
|
|
219
209
|
finalRect: AD.Rect.Rect,
|
|
220
|
-
paragraph: AD.Paragraph.Paragraph
|
|
221
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
210
|
+
paragraph: AD.Paragraph.Paragraph
|
|
222
211
|
): void {
|
|
223
212
|
const style = AD.Resources.getStyle(
|
|
224
213
|
undefined,
|
|
@@ -332,8 +321,7 @@ function renderParagraph(
|
|
|
332
321
|
parseAlignment(style.alignment),
|
|
333
322
|
availableWidth,
|
|
334
323
|
i === 0,
|
|
335
|
-
i === lastIndex
|
|
336
|
-
imageDataByUrl
|
|
324
|
+
i === lastIndex
|
|
337
325
|
);
|
|
338
326
|
|
|
339
327
|
x += atomSize.width;
|
|
@@ -368,8 +356,7 @@ function renderAtom(
|
|
|
368
356
|
alignment: AD.TextStyle.TextAlignment,
|
|
369
357
|
availableWidth: number,
|
|
370
358
|
isFirstAtom: boolean,
|
|
371
|
-
isLastAtom: boolean
|
|
372
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
359
|
+
isLastAtom: boolean
|
|
373
360
|
): void {
|
|
374
361
|
switch (atom.type) {
|
|
375
362
|
case "TextField":
|
|
@@ -389,7 +376,7 @@ function renderAtom(
|
|
|
389
376
|
renderTextRun(resources, pdfKit, finalRect, textStyle, atom, alignment, isFirstAtom, isLastAtom, availableWidth);
|
|
390
377
|
return;
|
|
391
378
|
case "Image":
|
|
392
|
-
renderImage(resources, pdfKit, finalRect, textStyle, atom
|
|
379
|
+
renderImage(resources, pdfKit, finalRect, textStyle, atom);
|
|
393
380
|
return;
|
|
394
381
|
case "HyperLink":
|
|
395
382
|
renderHyperLink(
|
|
@@ -682,8 +669,7 @@ function renderTable(
|
|
|
682
669
|
pdf: PDFKit.PDFDocument,
|
|
683
670
|
desiredSizes: Map<{}, AD.Size.Size>,
|
|
684
671
|
finalRect: AD.Rect.Rect,
|
|
685
|
-
table: AD.Table.Table
|
|
686
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
672
|
+
table: AD.Table.Table
|
|
687
673
|
): void {
|
|
688
674
|
const style = AD.Resources.getStyle(
|
|
689
675
|
undefined,
|
|
@@ -703,19 +689,7 @@ function renderTable(
|
|
|
703
689
|
const rowRect = AD.Rect.create(x, y, rowSize.width, rowSize.height);
|
|
704
690
|
const isTop = index === 0;
|
|
705
691
|
const isBottom = index === rows.length - 1;
|
|
706
|
-
renderRow(
|
|
707
|
-
resources,
|
|
708
|
-
pdf,
|
|
709
|
-
desiredSizes,
|
|
710
|
-
rowRect,
|
|
711
|
-
style.cellStyle,
|
|
712
|
-
table,
|
|
713
|
-
row,
|
|
714
|
-
index,
|
|
715
|
-
isTop,
|
|
716
|
-
isBottom,
|
|
717
|
-
imageDataByUrl
|
|
718
|
-
);
|
|
692
|
+
renderRow(resources, pdf, desiredSizes, rowRect, style.cellStyle, table, row, index, isTop, isBottom);
|
|
719
693
|
y += rowSize.height;
|
|
720
694
|
}
|
|
721
695
|
}
|
|
@@ -730,8 +704,7 @@ function renderRow(
|
|
|
730
704
|
row: AD.TableRow.TableRow,
|
|
731
705
|
rowIndex: number,
|
|
732
706
|
isTop: boolean,
|
|
733
|
-
isBottom: boolean
|
|
734
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
707
|
+
isBottom: boolean
|
|
735
708
|
): void {
|
|
736
709
|
let x = finalRect.x;
|
|
737
710
|
const rowSize = getDesiredSize(row, desiredSizes);
|
|
@@ -752,19 +725,7 @@ function renderRow(
|
|
|
752
725
|
const cellRect = AD.Rect.create(x, finalRect.y, cellSize.width, height);
|
|
753
726
|
const isFirst = cellIndex === 0;
|
|
754
727
|
const isLast = cellIndex === row.children.length - 1;
|
|
755
|
-
renderCell(
|
|
756
|
-
resources,
|
|
757
|
-
pdf,
|
|
758
|
-
desiredSizes,
|
|
759
|
-
cellRect,
|
|
760
|
-
tableCellStyle,
|
|
761
|
-
cell,
|
|
762
|
-
isFirst,
|
|
763
|
-
isLast,
|
|
764
|
-
isTop,
|
|
765
|
-
isBottom,
|
|
766
|
-
imageDataByUrl
|
|
767
|
-
);
|
|
728
|
+
renderCell(resources, pdf, desiredSizes, cellRect, tableCellStyle, cell, isFirst, isLast, isTop, isBottom);
|
|
768
729
|
x += cellSize.width;
|
|
769
730
|
}
|
|
770
731
|
}
|
|
@@ -779,8 +740,7 @@ function renderCell(
|
|
|
779
740
|
isFirst: boolean,
|
|
780
741
|
isLast: boolean,
|
|
781
742
|
isTop: boolean,
|
|
782
|
-
isBottom: boolean
|
|
783
|
-
imageDataByUrl: Record<string, Uint8Array | string>
|
|
743
|
+
isBottom: boolean
|
|
784
744
|
): void {
|
|
785
745
|
const style = AD.Resources.getStyle(
|
|
786
746
|
tableCellStyle,
|
|
@@ -809,7 +769,7 @@ function renderCell(
|
|
|
809
769
|
const elementSize = getDesiredSize(element, desiredSizes);
|
|
810
770
|
const isAbsolute = AD.Position.isPositionAbsolute(element);
|
|
811
771
|
const elementRect = AD.Rect.create(x, isAbsolute ? startY : y, elementSize.width, elementSize.height);
|
|
812
|
-
renderSectionElement(resources, pdf, desiredSizes, elementRect, element
|
|
772
|
+
renderSectionElement(resources, pdf, desiredSizes, elementRect, element);
|
|
813
773
|
if (!isAbsolute) {
|
|
814
774
|
y += elementSize.height;
|
|
815
775
|
}
|