deno.land / x / docx@8.5.0 / demo / 5-images.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Example of how to add images to the document - You can use Buffers, UInt8Arrays or Base64 strings
import * as fs from "fs";import { convertMillimetersToTwip, Document, HorizontalPositionAlign, HorizontalPositionRelativeFrom, ImageRun, Packer, Paragraph, VerticalPositionAlign, VerticalPositionRelativeFrom,} from "docx";
const doc = new Document({ sections: [ { children: [ new Paragraph("Hello World"), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/image1.jpeg"), transformation: { width: 100, height: 100, }, altText: { title: "This is an ultimate title", description: "This is an ultimate image", name: "My Ultimate Image", }, }), ], }), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/dog.png").toString("base64"), transformation: { width: 100, height: 100, }, outline: { type: "solidFill", solidFillType: "rgb", value: "FF0000", }, }), ], }), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/cat.jpg"), transformation: { width: 100, height: 100, flip: { vertical: true, }, }, outline: { type: "solidFill", solidFillType: "rgb", value: "0000FF", width: convertMillimetersToTwip(600), }, }), ], }), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/parrots.bmp"), transformation: { width: 150, height: 150, flip: { horizontal: true, }, rotation: 225, }, }), ], }), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/pizza.gif"), transformation: { width: 200, height: 200, flip: { horizontal: true, vertical: true, }, }, }), ], }), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/pizza.gif"), transformation: { width: 200, height: 200, rotation: 45, }, floating: { zIndex: 10, horizontalPosition: { offset: 1014400, }, verticalPosition: { offset: 1014400, }, }, }), ], }), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/cat.jpg"), transformation: { width: 200, height: 200, }, floating: { zIndex: 5, horizontalPosition: { relative: HorizontalPositionRelativeFrom.PAGE, align: HorizontalPositionAlign.RIGHT, }, verticalPosition: { relative: VerticalPositionRelativeFrom.PAGE, align: VerticalPositionAlign.BOTTOM, }, }, }), ], }), ], }, ],});
Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer);});
docx

Version Info

Tagged at
4 months ago