fix
This commit is contained in:
parent
2068825ae1
commit
8593eb2dd3
@ -32,6 +32,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/api/collection/test_ai",
|
Path: "/api/collection/test_ai",
|
||||||
Handler: TestAiHandler(serverCtx),
|
Handler: TestAiHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/collection/test_pdf",
|
||||||
|
Handler: TestPdfHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,11 @@ type TestAiReq struct {
|
|||||||
Num int `form:"num"`
|
Num int `form:"num"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TestPdfReq struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,12 @@ service collection {
|
|||||||
//获取收藏列表
|
//获取收藏列表
|
||||||
@handler GetCollectProductListHandler
|
@handler GetCollectProductListHandler
|
||||||
get /api/collection/get_collect_product_list(GetCollectProductListReq) returns (response);
|
get /api/collection/get_collect_product_list(GetCollectProductListReq) returns (response);
|
||||||
//测试
|
//测试算法合图并发
|
||||||
@handler TestAiHandler
|
@handler TestAiHandler
|
||||||
get /api/collection/test_ai(TestAiReq) returns (response);
|
get /api/collection/test_ai(TestAiReq) returns (response);
|
||||||
|
//测试pdf
|
||||||
|
@handler TestPdfHandler
|
||||||
|
post /api/collection/test_pdf(TestPdfReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
//收藏产品
|
//收藏产品
|
||||||
@ -56,7 +59,12 @@ type GetCollectProductListRspItem {
|
|||||||
IsShelf int64 `json:"is_shelf"`
|
IsShelf int64 `json:"is_shelf"`
|
||||||
IsDeleted int64 `json:"is_deleted"`
|
IsDeleted int64 `json:"is_deleted"`
|
||||||
}
|
}
|
||||||
//测试
|
//测试算法
|
||||||
type TestAiReq {
|
type TestAiReq {
|
||||||
Num int `form:"num"`
|
Num int `form:"num"`
|
||||||
}
|
}
|
||||||
|
//测试pdf
|
||||||
|
type TestPdfReq {
|
||||||
|
Content string `form:"content"`
|
||||||
|
Type string `form:"type"`
|
||||||
|
}
|
@ -2,25 +2,27 @@ package pdf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
"github.com/SebastiaanKlippert/go-wkhtmltopdf"
|
"github.com/SebastiaanKlippert/go-wkhtmltopdf"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
html转 Pdf
|
html转 Pdf
|
||||||
dataType = 1 为网页url dataType = 2为网页内容
|
|
||||||
outFile为空则不保存(使用该方法需要安装工具 sudo apt-get install wkhtmltopdf)
|
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()
|
pdfg, err := wkhtmltopdf.NewPDFGenerator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
switch dataType {
|
switch dataType {
|
||||||
case 1: //网页地址
|
case "url": //网页地址
|
||||||
pdfg.AddPage(wkhtmltopdf.NewPage(content))
|
pdfg.AddPage(wkhtmltopdf.NewPage(content))
|
||||||
case 2: //网页内容
|
case "html": //网页内容
|
||||||
pdfg.AddPage(wkhtmltopdf.NewPageReader(strings.NewReader(content)))
|
pdfg.AddPage(wkhtmltopdf.NewPageReader(strings.NewReader(content)))
|
||||||
|
default:
|
||||||
|
return "", errors.New("invalid type")
|
||||||
}
|
}
|
||||||
//模式
|
//模式
|
||||||
pdfg.Orientation.Set(wkhtmltopdf.OrientationPortrait)
|
pdfg.Orientation.Set(wkhtmltopdf.OrientationPortrait)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user