@@ -5,36 +5,57 @@ A simple Go client for interacting with a Gotenberg API.
55## Install
66
77``` bash
8- $ go get -u github.com/thecodingmachine/gotenberg-go-client/v6
8+ $ go get -u github.com/thecodingmachine/gotenberg-go-client/v7
99```
1010
1111## Usage
1212
1313``` golang
14- import " github.com/thecodingmachine/gotenberg-go-client/v6"
15-
16- func main () {
17- // HTML conversion example.
18- c := &gotenberg.Client {Hostname: " http://localhost:3000" }
19- req , _ := gotenberg.NewHTMLRequest (" index.html" )
20- req.Header (" header.html" )
21- req.Footer (" footer.html" )
22- req.Assets (
23- " font.woff" ,
24- " img.gif" ,
25- " style.css" ,
26- )
27- req.PaperSize (gotenberg.A4 )
28- req.Margins (gotenberg.NormalMargins )
29- req.Landscape (false )
30- dest := " foo.pdf"
31- c.Store (req, dest)
14+ import (
15+ " time"
16+ " net/http"
17+
18+ " github.com/thecodingmachine/gotenberg-go-client/v7"
19+ )
20+
21+ // create the client.
22+ client := &gotenberg.Client {Hostname: " http://localhost:3000" }
23+ // ... or use your own *http.Client.
24+ httpClient := &http.Client {
25+ Timeout : time.Duration (5 ) * time.Second ,
3226}
27+ client := &gotenberg.Client {Hostname: " http://localhost:3000" , HTTPClient : httpClient}
28+
29+ // prepare the files required for your conversion.
30+
31+ // from a path.
32+ index , _ := gotenberg.NewDocumentFromPath (" index.html" , " /path/to/file" )
33+ // ... or from a string.
34+ index , _ := gotenberg.NewDocumentFromString (" index.html" , " <html>Foo</html>" )
35+ // ... or from bytes.
36+ index , _ := gotenberg.NewDocumentFromBytes (" index.html" , []byte (" <html>Foo</html>" ))
37+
38+ header , _ := gotenberg.NewDocumentFromPath (" header.html" , " /path/to/file" )
39+ footer , _ := gotenberg.NewDocumentFromPath (" footer.html" , " /path/to/file" )
40+ style , _ := gotenberg.NewDocumentFromPath (" style.css" , " /path/to/file" )
41+ img , _ := gotenberg.NewDocumentFromPath (" img.png" , " /path/to/file" )
42+
43+ req := gotenberg.NewHTMLRequest (index)
44+ req.Header (header)
45+ req.Footer (footer)
46+ req.Assets (style, img)
47+ req.PaperSize (gotenberg.A4 )
48+ req.Margins (gotenberg.NoMargins )
49+
50+ // store method allows you to... store the resulting PDF in a particular destination.
51+ client.Store (req, " path/you/want/the/pdf/to/be/stored.pdf" )
52+
53+ // if you wish to redirect the response directly to the browser, you may also use:
54+ resp , _ := client.Post (req)
3355```
3456
3557For more complete usages, head to the [ documentation] ( https://thecodingmachine.github.io/gotenberg ) .
3658
37-
3859## Badges
3960
4061[ ![ Travis CI] ( https://travis-ci.org/thecodingmachine/gotenberg-go-client.svg?branch=master )] ( https://travis-ci.org/thecodingmachine/gotenberg-go-client )
0 commit comments