Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
@@ -13,9 +13,6 @@ var (
|
||||
CodeServiceErr = &StatusResponse{510, "server logic error"} // server logic 错误
|
||||
CodeUnAuth = &StatusResponse{401, "unauthorized"} // 未授权
|
||||
|
||||
CodeUpdateErr = &StatusResponse{5000, "update database error"} // update database logic 错误
|
||||
CodeRequestParamsErr = &StatusResponse{5002, "invalid request param"} // api参数校验 错误
|
||||
|
||||
CodeEmailNotFoundErr = &StatusResponse{5050, "the email was not found"} // email 不存在
|
||||
CodeUserIdNotFoundErr = &StatusResponse{5051, "the user was not found"} // email 不存在
|
||||
CodePasswordErr = &StatusResponse{5052, "invalid password"} // 密码错误
|
||||
@@ -23,6 +20,10 @@ var (
|
||||
CodeGuestDupErr = &StatusResponse{5010, "the user is already a guest user and does not need to apply again"} // 用户已经是guest用户不需要重复申请 错误
|
||||
CodeGuestGenErr = &StatusResponse{5011, "serialization failed for guest_id of the visitor"} // 游客guest_id序列化失败
|
||||
|
||||
CodeUpdateErr = &StatusResponse{5000, "update database error"} // update database logic 错误
|
||||
CodeDupGuestErr = &StatusResponse{5001, "the user is already a guest user and does not need to apply again"} // 用户已经是guest用户不需要重复申请 错误
|
||||
CodeRequestParamsErr = &StatusResponse{5002, "invalid request param"} // api参数校验 错误
|
||||
CodeDbRecordNotFoundErr = &StatusResponse{5003, "db record not found"}
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
|
||||
36
utils/pdf/html_to_pdf.go
Normal file
36
utils/pdf/html_to_pdf.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package pdf
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/SebastiaanKlippert/go-wkhtmltopdf"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// html转 Pdf dataType = 1 为网页url dataType = 2为网页内容 outFile为空则不保存
|
||||
func HtmlToPdfBase64(content string, dataType int, outFile ...string) (string, error) {
|
||||
pdfg, err := wkhtmltopdf.NewPDFGenerator()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
switch dataType {
|
||||
case 1: //网页地址
|
||||
pdfg.AddPage(wkhtmltopdf.NewPage(content))
|
||||
case 2: //网页内容
|
||||
pdfg.AddPage(wkhtmltopdf.NewPageReader(strings.NewReader(content)))
|
||||
}
|
||||
//模式
|
||||
pdfg.Orientation.Set(wkhtmltopdf.OrientationPortrait)
|
||||
//pdf尺寸默认A4纸
|
||||
pdfg.PageSize.Set(wkhtmltopdf.PageSizeA4)
|
||||
// Create PDF document in memory
|
||||
if err = pdfg.Create(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
// Write PDF to file
|
||||
if len(outFile) != 0 {
|
||||
if err = pdfg.WriteFile(outFile[0]); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString(pdfg.Bytes()), nil
|
||||
}
|
||||
Reference in New Issue
Block a user