fix
This commit is contained in:
@@ -2,25 +2,27 @@ package pdf
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"github.com/SebastiaanKlippert/go-wkhtmltopdf"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
html转 Pdf
|
||||
dataType = 1 为网页url dataType = 2为网页内容
|
||||
outFile为空则不保存(使用该方法需要安装工具 sudo apt-get install wkhtmltopdf)
|
||||
*/
|
||||
func HtmlToPdfBase64(content string, dataType int, outFile ...string) (string, error) {
|
||||
func HtmlToPdfBase64(content string, dataType string, outFile ...string) (string, error) {
|
||||
pdfg, err := wkhtmltopdf.NewPDFGenerator()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
switch dataType {
|
||||
case 1: //网页地址
|
||||
case "url": //网页地址
|
||||
pdfg.AddPage(wkhtmltopdf.NewPage(content))
|
||||
case 2: //网页内容
|
||||
case "html": //网页内容
|
||||
pdfg.AddPage(wkhtmltopdf.NewPageReader(strings.NewReader(content)))
|
||||
default:
|
||||
return "", errors.New("invalid type")
|
||||
}
|
||||
//模式
|
||||
pdfg.Orientation.Set(wkhtmltopdf.OrientationPortrait)
|
||||
|
||||
Reference in New Issue
Block a user