使用docx.js生成word;使用pdf.js base64Pdf转base64Img

139 阅读11分钟

背景

需求:根据数据和pdf图生成word并导出。

前端js库docx.js、pdf.js 安装"docx": "^8.5.0"、"pdfjs-dist": "2.6.347"版本

记录一下:使用docx.js生成word,写入文字、表格、图片生成docx文件并导出, 其中 pdf.js 主要实现了pdf转图片功能【当然,该库功能强大,其他功能有待使用等】

docx.js官网地址Getting Started (docx.js.org)

pdf.js官网地址PDF.js - Home (mozilla.github.io)

base64pdf转base64img

let PDFJS = require('pdfjs-dist');
PDFJS.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/build/pdf.worker.entry.js");

// 核心【base64pdf转base64img】【pdf文件转图片】
export function pdf2imgCode(base64Pdf) {
  // 假设你已经有了一个Base64编码的PDF
  const base64PDF = base64Pdf;

  // 将Base64编码的PDF数据转换为Uint8Array
  const pdfData = atob(base64PDF.split(',')[1]);
  const pdfArray = new Uint8Array(pdfData.length);
  for (let i = 0; i < pdfData.length; i++) {
    pdfArray[i] = pdfData.charCodeAt(i);
  }

  // 使用PDF.js加载PDF
  const loadingTask = PDFJS.getDocument({ data: pdfArray, binary: true });
  return loadingTask.promise.then(function (pdf) {
    // 获取第一页
    return pdf.getPage(1).then(function (page) {
      // 计算所需的视口大小
      const viewport = page.getViewport({ scale: 1.5 });

      // 创建一个Canvas元素
      const canvas = document.createElement('canvas');
      canvas.width = viewport.width;
      canvas.height = viewport.height;
      const context = canvas.getContext('2d');

      // 渲染页面
      return page.render({ canvasContext: context, viewport: viewport }).promise.then(function () {
        // 将Canvas转换为Base64编码的图片
        let base64ImageCode = canvas.toDataURL('image/png');
        return base64ImageCode
        // console.log('这里就是转换后的Base64编码的图片', base64Image); // 这里就是转换后的Base64编码的图片
      });
    });
  });
}

生成docx文件

import { HeadingLevel, AlignmentType, WidthType, Table, TableRow, TableCell, Paragraph, Document, TextRun, ImageRun, Packer } from "docx";

export function generate(station, shieldAngleStat, shieldAngleBase64Code, equalHeightByK123Base64Code, equalHeightByH123Base64Code) {
  let systemDate = getSystemDate() // 获取时间方法
  const doc = new Document({
    styles: {
      paragraphStyles: [ // 段落样式
        {
          id: "Heading1",
          name: "Heading 1",
          basedOn: "Normal",
          next: "Normal",
          quickFormat: true,
          run: {
            size: 44,
            bold: true,
            italics: false, // 斜体字
            color: "#000000",
            margin: {
              top: 500,
              bottom: 300
            }
          },
          paragraph: { // 段落
            spacing: { // 字间距
              after: 300,
            },
          }
        },
        {
          id: "Heading2",
          name: "Heading 2",
          basedOn: "Normal",
          next: "Normal",
          quickFormat: true, // 快速格式化
          run: {
            size: 32, // 字号
            bold: true, // 加粗
            color: '#000000',
            // underline: { // 设置下划线  DOUBLE是双下划线
            //     type: UnderlineType.DOUBLE,
            //     color: "FF0000"
            // }
          },
          paragraph: {
            spacing: {
              before: 240,
              after: 120
            }
          },
        },
        {
          id: "aside",
          name: "Aside",
          basedOn: "Normal",
          next: "Normal",
          run: {
            color: "999999",
            italics: true
          },
          paragraph: {
            indent: {
              left: 720
            },
            spacing: {
              line: 276
            }
          },
        },
        {
          id: "CoverTitle",
          name: "CoverTitle",
          basedOn: "Normal",
          quickFormat: true,
          run: {
            size: 52, // 字号
            bold: true, // 加粗
            color: '#000000'
          },
          paragraph: { // 段落
            spacing: { // 字间距
              after: 100,
              before: 100
            },
          }
        },
        {
          id: "CoverInfo",
          name: "CoverInfo",
          basedOn: "Normal",
          quickFormat: true,
          run: {
            size: 30, // 字号
            bold: true, // 加粗
            color: '#000000'
          },
          paragraph: { // 段落
            spacing: { // 字间距
              after: 100,
              before: 100
            },
          }
        },
        {
          id: "TableTxt",
          name: "TableTxt",
          basedOn: "Normal",
          quickFormat: true,
          run: {
            size: 30, // 字号
            bold: false, // 加粗
            color: '#000000',
          }
        },
        {
          id: "TableTxtSmall",
          name: "TableTxtSmall",
          basedOn: "Normal",
          quickFormat: true,
          run: {
            size: 21, // 字号
            bold: false, // 加粗
            color: '#000000',
          }
        }
      ],
    },
    sections: [
      {
        properties: {},
        children: [
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            alignment: AlignmentType.CENTER,
            children: [
              new TextRun({
                text: station.name + "选址分析报告",
              })
            ]
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverTitle',
            text: ''
          }),
          new Paragraph({
            heading: 'CoverInfo',
            alignment: AlignmentType.CENTER,
            children: [
              new TextRun({
                text: "生成时间:" + systemDate,
              })
            ]
          }),
          new Paragraph({
            heading: 'CoverInfo',
            alignment: AlignmentType.CENTER,
            children: [
              new TextRun({
                text: "分析平台:雷圣国一",
              })
            ]
          }),
        ]
      },
      {
        properties: {},
        children: [
          new Paragraph({
            heading: HeadingLevel.HEADING_1,
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "一.台站信息"
              })
            ]
          }),
          new Table({
            rows: [
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "站名",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.name,
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "经度",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.longitude + "°",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "纬度",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.latitude + "°",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "海拔高度",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.altitude + "(m)",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "天线架高",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.height + "(m)",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "最大测距",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.maxRange + "(km)",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "波段",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.radarTypeAbbr,
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "雷达型号",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.radarType,
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "省份",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.province,
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "主要天气来向",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxt',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: station.weatherSource,
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 100,
                      bottom: 100,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 6000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
            ]
          }),
        ]
      },
      {
        properties: {},
        children: [
          new Paragraph({
            heading: HeadingLevel.HEADING_1,
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "二.选址分析",
              })
            ]
          }),
          new Paragraph({
            heading: HeadingLevel.HEADING_2,
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "1.遮蔽角分析",
              })
            ]
          }),
          new Paragraph({
            children: [
              new ImageRun({
                data: shieldAngleBase64Code,
                transformation: { width: 600, height: 424 }
              })
            ]
          }),
          new Paragraph({
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "遮挡分析:",
              })
            ]
          }),
          new Table({
            rows: [
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "遮挡角",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "遮挡方位角",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 5000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "遮挡方位角累计",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "0.5°",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.shieldRange05 + '',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 5000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.azimuthTotal05 + '°',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "1°",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.shieldRange10 + '',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 5000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.azimuthTotal10 + '°',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "1.5°",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.shieldRange15 + '',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 5000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.azimuthTotal15 + '°',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "2.4°",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.shieldRange24 + '',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 5000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.azimuthTotal24 + '°',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2000,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
            ]
          }),
          new Paragraph(''),
          new Table({
            rows: [
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "最大遮挡仰角:" + shieldAngleStat.shieldMax + '°',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 4500,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "最大遮挡方位角:" + shieldAngleStat.azimuthMax + '°',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 4500,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "主要天气来向最大遮挡仰角:" + shieldAngleStat.weatherShieldMax + '°',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 4500,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "主要天气来向最大遮挡方位角:" + shieldAngleStat.weatherShieldMax + '°',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 4500,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
            ]
          }),
        ]
      },
      {
        properties: {},
        children: [
          new Paragraph({
            heading: HeadingLevel.HEADING_2,
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "2.等射束高度图分析"
              })
            ]
          }),
          new Paragraph({
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "馈源高度分析"
              })
            ]
          }),
          new Paragraph({
            children: [
              new ImageRun({
                data: equalHeightByK123Base64Code,
                transformation: { width: 580, height: 409 }
              })
            ]
          }),
          new Paragraph({
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "海拔高度分析"
              })
            ]
          }),
          new Paragraph({
            children: [
              new ImageRun({
                data: equalHeightByH123Base64Code,
                transformation: { width: 580, height: 409 }
              })
            ]
          }),
        ]
      },
      {
        properties: {},
        children: [
          new Paragraph({
            heading: HeadingLevel.HEADING_1,
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "三.电磁环境审核",
              })
            ]
          }),
          new Paragraph({
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "目标站点的电磁环境已达标",
              })
            ]
          }),
          new Paragraph(''),
          new Paragraph(''),
          new Paragraph({
            heading: HeadingLevel.HEADING_1,
            alignment: AlignmentType.LEFT,
            children: [
              new TextRun({
                text: "四.雷达选址打分",
              })
            ]
          }),
          new Table({
            rows: [
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "编号",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 1000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "评估指标",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "满分",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "站点得分",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "1",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 1000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "雷达0.5°仰角遮挡情况",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "60",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.mark05 + '',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "2",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 1000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "雷达1.5°仰角遮挡情况",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "20",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.mark15 + '',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "3",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 1000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "雷达2.4°仰角遮挡情况",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "10",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.mark24 + '',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "4",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 1000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "雷达站主要天气来向遮挡情况",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 3000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "10",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.weatherMark + '',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
              new TableRow({
                children: [
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.CENTER,
                        children: [
                          new TextRun({
                            text: "总分",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    columnSpan: 2,
                    width: {
                      size: 1000,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: "100",
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  }),
                  new TableCell({
                    children: [
                      new Paragraph({
                        heading: 'TableTxtSmall',
                        alignment: AlignmentType.LEFT,
                        children: [
                          new TextRun({
                            text: shieldAngleStat.mark + '',
                          })
                        ]
                      })
                    ],
                    margins: {
                      marginUnitType: WidthType.DXA,
                      top: 50,
                      bottom: 50,
                      left: 100,
                      right: 100,
                    },
                    width: {
                      size: 2500,
                      type: WidthType.DXA
                    }
                  })
                ]
              }),
            ]
          }),
        ]
      },
    ]
  });

  Packer.toBlob(doc).then((blob) => {
    console.log(blob);
    saveAs(blob, station.name + "选址分析报告.docx");
    console.log("Document created successfully");
  });
}