Skip to content

Commit 298b946

Browse files
committed
Bumped v0.16.0
Signed-off-by: Vishal Rana <[email protected]>
1 parent a41026f commit 298b946

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

pdf.go

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,63 @@
11
package labstack
22

3+
import "strconv"
4+
35
type (
46
PDFImageRequest struct {
5-
File string
7+
File string
8+
Extract bool
69
}
710

811
PDFImageResponse struct {
912
*Download
1013
}
14+
15+
PDFSplitRequest struct {
16+
File string
17+
Pages string
18+
}
19+
20+
PDFSplitResponse struct {
21+
*Download
22+
}
23+
24+
PDFCompressRequest struct {
25+
File string
26+
Quality int
27+
DPI int
28+
}
29+
30+
PDFCompressResponse struct {
31+
*Download
32+
Size int64 `json:"size"`
33+
}
1134
)
1235

36+
func (c *Client) PDFCompress(req *PDFCompressRequest) (res *PDFCompressResponse, err *APIError) {
37+
res = new(PDFCompressResponse)
38+
_, e := c.resty.R().
39+
SetFile("file", req.File).
40+
SetFormData(map[string]string{
41+
"quality": strconv.Itoa(req.Quality),
42+
"dpi": strconv.Itoa(req.DPI),
43+
}).
44+
SetResult(res).
45+
SetError(err).
46+
Post("/pdf/compress")
47+
if e != nil {
48+
err = new(APIError)
49+
err.Message = e.Error()
50+
}
51+
return
52+
}
53+
1354
func (c *Client) PDFImage(req *PDFImageRequest) (res *PDFImageResponse, err *APIError) {
1455
res = new(PDFImageResponse)
1556
_, e := c.resty.R().
1657
SetFile("file", req.File).
58+
SetFormData(map[string]string{
59+
"extract": strconv.FormatBool(req.Extract),
60+
}).
1761
SetResult(res).
1862
SetError(err).
1963
Post("/pdf/image")
@@ -23,3 +67,20 @@ func (c *Client) PDFImage(req *PDFImageRequest) (res *PDFImageResponse, err *API
2367
}
2468
return
2569
}
70+
71+
func (c *Client) PDFSplit(req *PDFSplitRequest) (res *PDFSplitResponse, err *APIError) {
72+
res = new(PDFSplitResponse)
73+
_, e := c.resty.R().
74+
SetFile("file", req.File).
75+
SetFormData(map[string]string{
76+
"pages": req.Pages,
77+
}).
78+
SetResult(res).
79+
SetError(err).
80+
Post("/pdf/split")
81+
if e != nil {
82+
err = new(APIError)
83+
err.Message = e.Error()
84+
}
85+
return
86+
}

0 commit comments

Comments
 (0)