This commit is contained in:
laodaming 2023-06-15 14:34:40 +08:00
parent 6a06a21c2a
commit 200e821c85

View File

@ -6,7 +6,7 @@ import (
)
// html转 Pdf dataType = 1 为网页url dataType = 2为网页内容 outFile为空则不保存
func HtmlToPdf(content string, dataType int, outFile string) ([]byte, error) {
func HtmlToPdf(content string, dataType int, outFile ...string) ([]byte, error) {
pdfg, err := wkhtmltopdf.NewPDFGenerator()
if err != nil {
return nil, err
@ -26,8 +26,8 @@ func HtmlToPdf(content string, dataType int, outFile string) ([]byte, error) {
return nil, err
}
// Write PDF to file
if outFile != "" {
if err = pdfg.WriteFile(outFile); err != nil {
if len(outFile) != 0 {
if err = pdfg.WriteFile(outFile[0]); err != nil {
return nil, err
}
}