Compare commits

...

7 Commits
4.0.0 ... 4.2.0

Author SHA1 Message Date
Julien Neuhart
4827a45f22 adding flat open document support (fixes #47) 2019-02-18 13:46:58 +01:00
Julien Neuhart
40eef457ab adding latest tag (fixes #48) 2019-02-18 13:44:30 +01:00
Julien Neuhart
c22a4d109b minor fix in doc for web fonts 2019-02-01 11:22:06 +01:00
Julien Neuhart
571c3e04c4 adding form field web fonts timeout 2019-02-01 09:40:16 +01:00
Sergei Opletaev
f9fb97a572 Fix for #44 promise wait for fonts (#45)
`runtime.ExceptionDetails: Uncaught exception at 4:47: SyntaxError: Unexpected token %`
2019-02-01 09:21:02 +01:00
Julien Neuhart
e6484bb2d5 Trigger GitHub documentation 2019-01-28 15:56:13 +01:00
Julien Neuhart
19f51fdc1f fixing PHP documentation 2019-01-28 15:36:59 +01:00
18 changed files with 116 additions and 53 deletions

View File

@@ -186,6 +186,9 @@ You may also use *remote* paths for Google fonts, images and so on.
> If you want to install fonts directly in the Gotenberg Docker image,
> see to the [fonts section](#fonts).
>
> For web fonts (Google fonts), there is a timeout of 500ms by default. You may update
> this value thanks to the form field `webFontsTimeout`.
### cURL

View File

@@ -52,5 +52,5 @@ $client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()
$request = new URLRequest('https://google.com');
$request->setMargins(Request::NO_MARGINS);
$dest = "result.pdf";
$filename = $client->store($request, $dest);
$client->store($request, $dest);
```

View File

@@ -66,5 +66,5 @@ $markdowns = [
];
$request = new MarkdownRequest($index, $markdowns);
$dest = "result.pdf";
$filename = $client->store($request, $dest);
$client->store($request, $dest);
```

View File

@@ -12,6 +12,7 @@ You may send one or more Office documents. Following file extensions are accepte
* `.txt`
* `.rtf`
* `.fodt`
* `.doc`
* `.docx`
* `.odt`
@@ -66,7 +67,7 @@ $files = [
];
$request = new OfficeRequest($files);
$dest = "result.pdf";
$filename = $client->store($request, $dest);
$client->store($request, $dest);
```
## Orientation
@@ -114,5 +115,5 @@ $files = [
$request = new OfficeRequest($files);
$request->setLandscape(true);
$dest = "result.pdf";
$filename = $client->store($request, $dest);
$client->store($request, $dest);
```

View File

@@ -49,5 +49,5 @@ $files = [
];
$request = new MergeRequest($files);
$dest = "result.pdf";
$filename = $client->store($request, $dest);
$client->store($request, $dest);
```

View File

@@ -363,6 +363,9 @@ are on the same level as the <code>index.html</code> file.</p>
<blockquote>
<p>If you want to install fonts directly in the Gotenberg Docker image,
see to the <a href="#fonts">fonts section</a>.</p>
<p>For web fonts (Google fonts), there is a timeout of 500ms by default. You may update
this value thanks to the form field <code>webFontsTimeout</code>.</p>
</blockquote>
<h3 class="Heading"><a class="Anchor" aria-hidden="true" id="html.assets.c_url" href="#html.assets.c_url">
@@ -545,7 +548,7 @@ $client = new Client(&#39;http://localhost:3000&#39;, new \Http\Adapter\Guzzle6\
$request = new URLRequest(&#39;https://google.com&#39;);
$request-&gt;setMargins(Request::NO_MARGINS);
$dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest);
$client-&gt;store($request, $dest);
</pre>
</div>
@@ -622,7 +625,7 @@ $markdowns = [
];
$request = new MarkdownRequest($index, $markdowns);
$dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest);
$client-&gt;store($request, $dest);
</pre>
</div>
@@ -644,6 +647,7 @@ $filename = $client-&gt;store($request, $dest);
<ul>
<li><code>.txt</code></li>
<li><code>.rtf</code></li>
<li><code>.fodt</code></li>
<li><code>.doc</code></li>
<li><code>.docx</code></li>
<li><code>.odt</code></li>
@@ -704,7 +708,7 @@ $files = [
];
$request = new OfficeRequest($files);
$dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest);
$client-&gt;store($request, $dest);
</pre>
<h2 class="Heading"><a class="Anchor" aria-hidden="true" id="office.orientation" href="#office.orientation">
@@ -757,7 +761,7 @@ $files = [
$request = new OfficeRequest($files);
$request-&gt;setLandscape(true);
$dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest);
$client-&gt;store($request, $dest);
</pre>
</div>
@@ -818,7 +822,7 @@ $files = [
];
$request = new MergeRequest($files);
$dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest);
$client-&gt;store($request, $dest);
</pre>
</div>

View File

@@ -47,5 +47,10 @@ func convertHTML(c echo.Context) error {
return hijackErr(err, r)
}
p.Landscape = landscape
chromeWebFontsTimeout, err := r.webFontsTimeout()
if err != nil {
return hijackErr(err, r)
}
p.WebFontsTimeout = chromeWebFontsTimeout
return print(c, p, r)
}

View File

@@ -46,5 +46,10 @@ func convertMarkdown(c echo.Context) error {
return hijackErr(err, r)
}
p.Landscape = landscape
chromeWebFontsTimeout, err := r.webFontsTimeout()
if err != nil {
return hijackErr(err, r)
}
p.WebFontsTimeout = chromeWebFontsTimeout
return print(c, p, r)
}

View File

@@ -10,6 +10,7 @@ import (
var officeExts = []string{
".txt",
".rtf",
".fodt",
".doc",
".docx",
".odt",

View File

@@ -22,6 +22,7 @@ const (
marginLeft string = "marginLeft"
marginRight string = "marginRight"
landscape string = "landscape"
webFontsTimeout string = "webFontsTimeout"
)
// resource facilitates storing and accessing
@@ -42,6 +43,7 @@ func newResource(c echo.Context) (*resource, error) {
v[marginLeft] = c.FormValue(marginLeft)
v[marginRight] = c.FormValue(marginRight)
v[landscape] = c.FormValue(landscape)
v[webFontsTimeout] = c.FormValue(webFontsTimeout)
dirPath, err := rand.Get()
if err != nil {
return nil, err
@@ -190,5 +192,17 @@ func (r *resource) remoteURL() (string, error) {
return r.values[remoteURL], nil
}
func (r *resource) webFontsTimeout() (int64, error) {
webFontsTimeoutStr := r.values[webFontsTimeout]
if webFontsTimeoutStr == "" {
return 500, nil
}
timeout, err := strconv.ParseInt(webFontsTimeoutStr, 10, 64)
if err != nil {
return 500, fmt.Errorf("web fonts timeout: %v", err)
}
return timeout, nil
}
func (r *resource) webhookURL() string { return r.values[webhookURL] }
func (r *resource) removeAll() error { return os.RemoveAll(r.dirPath) }

View File

@@ -47,5 +47,10 @@ func convertURL(c echo.Context) error {
return hijackErr(err, r)
}
p.Landscape = landscape
chromeWebFontsTimeout, err := r.webFontsTimeout()
if err != nil {
return hijackErr(err, r)
}
p.WebFontsTimeout = chromeWebFontsTimeout
return print(c, p, r)
}

View File

@@ -29,6 +29,7 @@ type HTML struct {
MarginLeft float64
MarginRight float64
Landscape bool
WebFontsTimeout int64
}
const defaultHeaderFooterHTML string = "<html><head></head><body></body></html>"
@@ -103,14 +104,17 @@ func (html *HTML) Print(destination string) error {
return fmt.Errorf("waiting for page loading: %v", err)
}
// inject a script to make sure web fonts are loaded.
script := `new Promise((resolve, reject) => {
script := fmt.Sprintf(`new Promise((resolve, reject) => {
document.fonts.ready.then(function () {
resolve('fonts loaded');
});
setTimeout(resolve.bind(resolve, 'timeout'), %.0f);
});`
setTimeout(resolve.bind(resolve, 'timeout'), %d);
});`, html.WebFontsTimeout)
scriptArg := runtime.NewEvaluateArgs(script).SetAwaitPromise(true)
returnObj, _ := c.Runtime.Evaluate(html.Context, scriptArg)
if returnObj.ExceptionDetails != nil {
return fmt.Errorf("script evaluated with exception: %+v", returnObj.ExceptionDetails)
}
loadFontsResult := string(returnObj.Result.Value)
if strings.Contains(loadFontsResult, "timeout") {
return errors.New("timed out loading fonts")

View File

@@ -26,6 +26,7 @@ type Markdown struct {
MarginLeft float64
MarginRight float64
Landscape bool
WebFontsTimeout int64
html *HTML
}
@@ -52,6 +53,7 @@ func (md *Markdown) Print(destination string) error {
md.html.MarginLeft = md.MarginLeft
md.html.MarginRight = md.MarginRight
md.html.Landscape = md.Landscape
md.html.WebFontsTimeout = md.WebFontsTimeout
tmpl, err := template.
New(filepath.Base(md.TemplatePath)).
Funcs(template.FuncMap{"toHTML": toHTML}).

View File

@@ -22,6 +22,7 @@ const (
marginLeft string = "marginLeft"
marginRight string = "marginRight"
landscape string = "landscape"
webFontsTimeout string = "webFontsTimeout"
)
var (
@@ -75,6 +76,7 @@ type ChromeRequest interface {
SetPaperSize(size [2]float64)
SetMargins(margins [4]float64)
SetLandscape(isLandscape bool)
SetWebFontsTimeout(timeout int64)
}
// UnoconvRequest is a type for sending

View File

@@ -78,6 +78,11 @@ func (html *HTMLRequest) SetLandscape(isLandscape bool) {
html.values[landscape] = strconv.FormatBool(isLandscape)
}
// SetWebFontsTimeout sets webFontsTimeout form field.
func (html *HTMLRequest) SetWebFontsTimeout(timeout int64) {
html.values[webFontsTimeout] = strconv.FormatInt(timeout, 10)
}
func (html *HTMLRequest) getPostURL() string {
return "/convert/html"
}

View File

@@ -88,6 +88,11 @@ func (markdown *MarkdownRequest) SetLandscape(isLandscape bool) {
markdown.values[landscape] = strconv.FormatBool(isLandscape)
}
// SetWebFontsTimeout sets webFontsTimeout form field.
func (markdown *MarkdownRequest) SetWebFontsTimeout(timeout int64) {
markdown.values[webFontsTimeout] = strconv.FormatInt(timeout, 10)
}
func (markdown *MarkdownRequest) getPostURL() string {
return "/convert/markdown"
}

View File

@@ -63,6 +63,11 @@ func (url *URLRequest) SetLandscape(isLandscape bool) {
url.values[landscape] = strconv.FormatBool(isLandscape)
}
// SetWebFontsTimeout sets webFontsTimeout form field.
func (url *URLRequest) SetWebFontsTimeout(timeout int64) {
url.values[webFontsTimeout] = strconv.FormatInt(timeout, 10)
}
func (url *URLRequest) getPostURL() string {
return "/convert/url"
}

View File

@@ -21,11 +21,13 @@ docker build -t thecodingmachine/gotenberg:base -f build/base/Dockerfile .
docker build \
--build-arg GOLANG_VERSION=${GOLANG_VERSION} \
--build-arg VERSION=${VERSION} \
-t thecodingmachine/gotenberg:latest \
-t thecodingmachine/gotenberg:${SEMVER[0]} \
-t thecodingmachine/gotenberg:${SEMVER[0]}.${SEMVER[1]} \
-t thecodingmachine/gotenberg:${SEMVER[0]}.${SEMVER[1]}.${SEMVER[2]} \
-f build/package/Dockerfile .
docker push "thecodingmachine/gotenberg:latest"
docker push "thecodingmachine/gotenberg:${SEMVER[0]}"
docker push "thecodingmachine/gotenberg:${SEMVER[0]}.${SEMVER[1]}"
docker push "thecodingmachine/gotenberg:${SEMVER[0]}.${SEMVER[1]}.${SEMVER[2]}"