Browse Source

fix:pdf和jpg生成的宽度都做调整,保持左右空白宽度一致

Roc 7 months ago
parent
commit
e63422955e
1 changed files with 8 additions and 8 deletions
  1. 8 8
      services/smart_report.go

+ 8 - 8
services/smart_report.go

@@ -136,7 +136,7 @@ func SmartReportElasticUpsert(smartReportId int, state int) (err error) {
 	return
 }
 
-func ReportToPdf(reportUrl, filePath string) (err error) {
+func ReportToPdf(width int, reportUrl, filePath string) (err error) {
 	pyCode := `
 import asyncio
 from pyppeteer import launch
@@ -151,7 +151,7 @@ async def main():
     })
     page = await browser.newPage()
     await page.setViewport({
-        'width': 1920,
+        'width': %d,
         'height': 1080,
     })
     await page.goto('%s', {
@@ -186,7 +186,7 @@ finally:
     loop.close()
 `
 
-	pyCode = fmt.Sprintf(pyCode, utils.ChromePath, reportUrl, filePath)
+	pyCode = fmt.Sprintf(pyCode, utils.ChromePath, width, reportUrl, filePath)
 	utils.FileLog.Info("pdf pyCode: \n" + pyCode)
 	cmd := exec.Command("python3", "-c", pyCode)
 	output, e := cmd.CombinedOutput()
@@ -329,7 +329,11 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
 	pdfPath := `./static/` + reportCode + ".pdf"
 	jpegPath := `./static/` + reportCode + ".jpg"
 
-	err = ReportToPdf(reportUrl, pdfPath)
+	width := 1560
+	if reportType == 3 {
+		width = 800
+	}
+	err = ReportToPdf(width, reportUrl, pdfPath)
 	if err != nil {
 		utils.FileLog.Info("ReportToPdf failed: , error: \n" + err.Error())
 		go alarm_msg.SendAlarmMsg("ReportToPdf failed:"+err.Error(), 3)
@@ -389,10 +393,6 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
 
 	time.Sleep(1 * time.Minute)
 
-	width := 1200
-	if reportType == 3 {
-		width = 800
-	}
 	err = ReportToJpeg(width, reportUrl, jpegPath)
 	if err != nil {
 		utils.FileLog.Info("ReportToJpeg failed: , error: \n" + err.Error())