Просмотр исходного кода

调整PDF页面输出系数,与造价的一致

TonyKang 6 лет назад
Родитель
Сommit
12a2373e25
1 измененных файлов с 23 добавлено и 15 удалено
  1. 23 15
      modules/reports/util/rpt_pdf_util.js

+ 23 - 15
modules/reports/util/rpt_pdf_util.js

@@ -5,11 +5,12 @@
  * Created by zhang on 2017/8/14.
  */
 
-let pdf = require('pdfkit');
-let fs = require('fs');
-let jpcCmnHelper = require('../rpt_component/helper/jpc_helper_common');
-let DPI = jpcCmnHelper.getScreenDPI()[0];
-let JV = require('../rpt_component/jpc_value_define');
+const pdf = require('pdfkit');
+const PDF_SCALE = 0.75;
+const fs = require('fs');
+const jpcCmnHelper = require('../rpt_component/helper/jpc_helper_common');
+const DPI = jpcCmnHelper.getScreenDPI()[0] * PDF_SCALE;
+const JV = require('../rpt_component/jpc_value_define');
 const uuidV1 = require('uuid/v1');
 
 let fontUtil = require('./rpt_font_util');
@@ -106,10 +107,12 @@ function export_pdf_file (pageData, paperSize, fName, callback) {
                 destStyle = styles[mergedBand[JV.PROP_STYLE][JV.PROP_ID]];
             }
         }
-        doc.moveTo(cell[JV.PROP_AREA][startP[0]] + offsetX, cell[JV.PROP_AREA][startP[1]] + offsetY);
+        // doc.moveTo(cell[JV.PROP_AREA][startP[0]] + offsetX, cell[JV.PROP_AREA][startP[1]] + offsetY);
+        doc.moveTo( (cell[JV.PROP_AREA][startP[0]] + offsetX) * PDF_SCALE, (cell[JV.PROP_AREA][startP[1]] + offsetY) * PDF_SCALE);
         if (destStyle[styleBorderDest] && parseFloat(destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]) !== 0) {
             doc.lineWidth(1.0 * destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]);
-            doc.lineTo(cell[JV.PROP_AREA][destP[0]] + offsetX, cell[JV.PROP_AREA][destP[1]] + offsetY);
+            // doc.lineTo(cell[JV.PROP_AREA][destP[0]] + offsetX, cell[JV.PROP_AREA][destP[1]] + offsetY);
+            doc.lineTo((cell[JV.PROP_AREA][destP[0]] + offsetX) * PDF_SCALE, (cell[JV.PROP_AREA][destP[1]] + offsetY) * PDF_SCALE);
             doc.strokeColor(destStyle[styleBorderDest][JV.PROP_COLOR]);
         }
         doc.stroke();
@@ -217,10 +220,12 @@ function export_pdf_file (pageData, paperSize, fName, callback) {
                 ctx.translate(0,0.5);
             }
             // ctx.beginPath();
-            ctx.moveTo(startX, startY);
+            // ctx.moveTo(startX, startY);
+            ctx.moveTo(startX * PDF_SCALE, startY * PDF_SCALE);
             ctx.lineWidth(1);
             ctx.strokeStyle = "BLACK";
-            ctx.lineTo(endX, endY);
+            // ctx.lineTo(endX, endY);
+            ctx.lineTo(endX * PDF_SCALE, endY * PDF_SCALE);
             ctx.stroke();
             // ctx.restore();
         }
@@ -238,9 +243,10 @@ function export_pdf_file (pageData, paperSize, fName, callback) {
             doc.rotate(font.FontAngle,rotateOptions);
         }
         if (w >= doc.widthOfString(val) || (control && control.Shrink !== 'T')) {
-            options.width = w;
-            options.height = dftFontHeight;
-            doc.text(val,output[0], output[1], options);
+            options.width = w * PDF_SCALE;
+            options.height = dftFontHeight * PDF_SCALE;
+            doc.fontSize(dftFontHeight * PDF_SCALE);
+            doc.text(val,output[0] * PDF_SCALE, output[1] * PDF_SCALE, options);
             doc.font(__dirname + '/pdf_base_files/simhei_bold_italic.ttf');
         } else {
             while (true) {
@@ -268,13 +274,15 @@ function export_pdf_file (pageData, paperSize, fName, callback) {
                     for (let ai = 0; ai < area.length; ai++) {
                         newArea[ai] = area[ai];
                     }
-                    options.width = w;
-                    options.height = dftFontHeight;
+                    options.width = w * PDF_SCALE;
+                    options.height = dftFontHeight * PDF_SCALE;
                     for (let lIdx = 0; lIdx < actLines.length; lIdx++) {
                         newArea[JV.IDX_TOP] = Math.round(aH * lIdx + baseTop);
                         newArea[JV.IDX_BOTTOM] = Math.round(aH * (lIdx + 1) + baseTop);
                         inner_setupControl(newArea, dftFontHeight, output);
-                        doc.text(actLines[lIdx], output[0], output[1], options);
+                        doc.fontSize(dftFontHeight * PDF_SCALE);
+                        // doc.text(actLines[lIdx], output[0], output[1], options);
+                        doc.text(actLines[lIdx], output[0] * PDF_SCALE, output[1] * PDF_SCALE, options);
                     }
                     break;
                 }