+ const doc = new PDFDocument({size: 'A4'});
+ doc.pipe(fs.createWriteStream('output.pdf'));
+ this.grid(doc);
+
+ let styleCache : any = {};
+ let fontPairCache : fontPathPSNamePair = {path : "", psName : ""};
+ await this.putText(doc, boxesFixed, <TextStyle>styleCache, fontPairCache);
+ // putChar
+ doc.end();
+
+
+ }
+
+ async putText(doc : PDFKit.PDFDocument, box : Box, styleCache : TextStyle,
+ fontPairCache : fontPathPSNamePair):
+ Promise<[PDFKit.PDFDocument, TextStyle, fontPathPSNamePair]>{
+ var fontPair;
+
+
+ if (box.textStyle !== null){
+
+ if(box.textStyle == styleCache){
+ fontPair = fontPairCache;
+ }else{
+ fontPair = fontStyleTofont(box.textStyle);
+ styleCache = box.textStyle;
+ fontPairCache = fontPair;
+
+ if (fontPair.path.match(/\.ttc$/g)){
+ doc
+ .font(fontPair.path, fontPair.psName)
+ .fontSize(box.textStyle.size * 0.75);}
+ else{
+ doc
+ .font(fontPair.path)
+ .fontSize(box.textStyle.size * 0.75); // 0.75 must added!
+ }
+ }
+
+ if (box.textStyle.color !== undefined){
+ doc.fill(box.textStyle.color);
+ }
+
+ if (Array.isArray(box.content)){
+ for (var k=0; k<box.content.length; k++){
+
+ let tmp = await this.putText(doc, box.content[k], styleCache, fontPairCache);
+ doc = tmp[0];
+ styleCache = tmp[1];
+ fontPairCache = tmp[2];
+ }
+ }else if (box.content !== null){
+ await doc.text(box.content,
+ (box.x!==null? box.x: undefined),
+ (box.y!==null? box.y: undefined));
+ }
+
+ }
+
+
+ return [doc, styleCache, fontPairCache];
+ };