function createPdfPage(canvas) {
  var contentWidth = canvas.width;
  var contentHeight = canvas.height;
  var pageHeight = (contentWidth / 592.28) * 841.89;
  var leftHeight = contentHeight;
  var position = 0;
  var imgWidth = 595.28;
  var imgHeight = (592.28 / contentWidth) * contentHeight;
  var pageData = canvas.toDataURL("image/jpeg", 1.0);
  var pdf = new window.jspdf.jsPDF("", "pt", "a4");
  if (leftHeight < pageHeight) {
    pdf.addImage(pageData, "JPEG", 0, 0, imgWidth, imgHeight);
  } else {
    while (leftHeight > 0) {
      pdf.addImage(pageData, "JPEG", 0, position, imgWidth, imgHeight);
      leftHeight -= pageHeight;
      position -= 841.89;
      if (leftHeight > 0) {
        pdf.addPage();
      }
    }
  }
  pdf.save(`项目验收报告.pdf`);
}
/**
 * 想保存为pdf的话，直接调这个getPdf方法就行
 */
function getPdf() {
  var canvas = document.createElement("canvas");
  var context = canvas.getContext("2d");
  var _articleHtml = document.getElementById("accept-report");
  var _w = _articleHtml.clientWidth;
  var _h = _articleHtml.clientHeight;
  var scale = 3;
  if (_w > _h) {
    _h = _w;
  }
  canvas.width = _w * scale;
  canvas.height = _h * scale;
  context.scale(scale, scale);
  var opts = {
    scale: 1,
    width: _w,
    height: _h,
    canvas: canvas,
    useCORS: true,
  };
  html2canvas(_articleHtml, opts).then((canvas) => {
    createPdfPage(canvas);
  });
}
