|
@@ -136,7 +136,7 @@ func SmartReportElasticUpsert(smartReportId int, state int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func ReportToPdf(width int, reportUrl, filePath string) (err error) {
|
|
|
+func ReportToPdf(width int, reportUrl, filePath string, top, bottom, left, right int) (err error) {
|
|
|
pyCode := `
|
|
|
import asyncio
|
|
|
from pyppeteer import launch
|
|
@@ -168,10 +168,10 @@ async def main():
|
|
|
'path': "%s",
|
|
|
'printBackground': True,
|
|
|
'margin': {
|
|
|
- 'top': '20px',
|
|
|
- 'bottom': '20px',
|
|
|
- 'left': '20px',
|
|
|
- 'right': '20px'
|
|
|
+ 'top': '%dpx',
|
|
|
+ 'bottom': '%dpx',
|
|
|
+ 'left': '%dpx',
|
|
|
+ 'right': '%dpx'
|
|
|
}
|
|
|
})
|
|
|
await browser.close()
|
|
@@ -187,7 +187,7 @@ finally:
|
|
|
loop.close()
|
|
|
`
|
|
|
|
|
|
- pyCode = fmt.Sprintf(pyCode, utils.ChromePath, width, reportUrl, width, filePath)
|
|
|
+ pyCode = fmt.Sprintf(pyCode, utils.ChromePath, width, reportUrl, width, filePath, top, bottom, left, right)
|
|
|
utils.FileLog.Info("pdf pyCode: \n" + pyCode)
|
|
|
cmd := exec.Command(utils.CommandPython, "-c", pyCode)
|
|
|
output, e := cmd.CombinedOutput()
|
|
@@ -335,10 +335,14 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
|
|
|
jpegPath := `./static/` + reportCode + "_1200.jpg"
|
|
|
|
|
|
width := 1200
|
|
|
+ top, bottom, left, right := 20, 20, 20, 20
|
|
|
+ if report.ReportLayout == 3 {
|
|
|
+ top, bottom, left, right = 0, 0, 0, 0
|
|
|
+ }
|
|
|
//if reportType == 3 {
|
|
|
// width = 800
|
|
|
//}
|
|
|
- err = ReportToPdf(width, reportUrl, pdfPath)
|
|
|
+ err = ReportToPdf(width, reportUrl, pdfPath, top, bottom, left, right)
|
|
|
if err != nil {
|
|
|
utils.FileLog.Info("ReportToPdf failed: , error: \n" + err.Error())
|
|
|
go alarm_msg.SendAlarmMsg("ReportToPdf failed:"+err.Error(), 3)
|
|
@@ -457,9 +461,9 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
|
|
|
go func() {
|
|
|
pdfPathMobile := `./static/` + reportCode + "_600.pdf"
|
|
|
jpegPathMobile := `./static/` + reportCode + "_600.jpg"
|
|
|
-
|
|
|
+ top, bottom, left, right := 20, 20, 20, 20
|
|
|
width := 600
|
|
|
- err = ReportToPdf(width, reportUrl, pdfPathMobile)
|
|
|
+ err = ReportToPdf(width, reportUrl, pdfPathMobile, top, bottom, left, right)
|
|
|
if err != nil {
|
|
|
utils.FileLog.Info("ReportToPdf failed: , error: \n" + err.Error())
|
|
|
go alarm_msg.SendAlarmMsg("ReportToPdf failed:"+err.Error(), 3)
|