Compare commits

...

10 Commits
4.0.0 ... 4.2.1

Author SHA1 Message Date
Alexander Joseph Trelore
ab78559710 remove unused imports (#55)
Thanks!
2019-03-13 10:53:20 +01:00
Julien Neuhart
0d75bb1d3e improving documentation on merge 2019-03-05 11:27:25 +01:00
Julien Neuhart
6441062e7f adding Google analytics 2019-02-19 15:27:20 +01:00
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
21 changed files with 143 additions and 68 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, > If you want to install fonts directly in the Gotenberg Docker image,
> see to the [fonts section](#fonts). > 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 ### 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 = new URLRequest('https://google.com');
$request->setMargins(Request::NO_MARGINS); $request->setMargins(Request::NO_MARGINS);
$dest = "result.pdf"; $dest = "result.pdf";
$filename = $client->store($request, $dest); $client->store($request, $dest);
``` ```

View File

@@ -66,5 +66,5 @@ $markdowns = [
]; ];
$request = new MarkdownRequest($index, $markdowns); $request = new MarkdownRequest($index, $markdowns);
$dest = "result.pdf"; $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` * `.txt`
* `.rtf` * `.rtf`
* `.fodt`
* `.doc` * `.doc`
* `.docx` * `.docx`
* `.odt` * `.odt`
@@ -66,7 +67,7 @@ $files = [
]; ];
$request = new OfficeRequest($files); $request = new OfficeRequest($files);
$dest = "result.pdf"; $dest = "result.pdf";
$filename = $client->store($request, $dest); $client->store($request, $dest);
``` ```
## Orientation ## Orientation
@@ -114,5 +115,5 @@ $files = [
$request = new OfficeRequest($files); $request = new OfficeRequest($files);
$request->setLandscape(true); $request->setLandscape(true);
$dest = "result.pdf"; $dest = "result.pdf";
$filename = $client->store($request, $dest); $client->store($request, $dest);
``` ```

View File

@@ -8,9 +8,11 @@ It accepts `POST` requests with a `multipart/form-data` Content-Type.
## Basic ## Basic
Nothing special here: you may send one or more PDF files and the API Nothing fancy here: you may send one or more PDF files and the API
will merge them and return the resulting PDF file. will merge them and return the resulting PDF file.
> **Attention:** Gotenberg merges the PDF files alphabetically.
### cURL ### cURL
```bash ```bash
@@ -49,5 +51,5 @@ $files = [
]; ];
$request = new MergeRequest($files); $request = new MergeRequest($files);
$dest = "result.pdf"; $dest = "result.pdf";
$filename = $client->store($request, $dest); $client->store($request, $dest);
``` ```

View File

@@ -1,4 +1,13 @@
<!DOCTYPE html><html><head> <!DOCTYPE html><html><head>
<script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-10196481-9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-10196481-9');
</script>
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta http-equiv="x-ua-compatible" content="ie=edge"/> <meta http-equiv="x-ua-compatible" content="ie=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="viewport" content="width=device-width, initial-scale=1"/>
@@ -363,6 +372,9 @@ are on the same level as the <code>index.html</code> file.</p>
<blockquote> <blockquote>
<p>If you want to install fonts directly in the Gotenberg Docker image, <p>If you want to install fonts directly in the Gotenberg Docker image,
see to the <a href="#fonts">fonts section</a>.</p> 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> </blockquote>
<h3 class="Heading"><a class="Anchor" aria-hidden="true" id="html.assets.c_url" href="#html.assets.c_url"> <h3 class="Heading"><a class="Anchor" aria-hidden="true" id="html.assets.c_url" href="#html.assets.c_url">
@@ -545,7 +557,7 @@ $client = new Client(&#39;http://localhost:3000&#39;, new \Http\Adapter\Guzzle6\
$request = new URLRequest(&#39;https://google.com&#39;); $request = new URLRequest(&#39;https://google.com&#39;);
$request-&gt;setMargins(Request::NO_MARGINS); $request-&gt;setMargins(Request::NO_MARGINS);
$dest = &#34;result.pdf&#34;; $dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest); $client-&gt;store($request, $dest);
</pre> </pre>
</div> </div>
@@ -622,7 +634,7 @@ $markdowns = [
]; ];
$request = new MarkdownRequest($index, $markdowns); $request = new MarkdownRequest($index, $markdowns);
$dest = &#34;result.pdf&#34;; $dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest); $client-&gt;store($request, $dest);
</pre> </pre>
</div> </div>
@@ -644,6 +656,7 @@ $filename = $client-&gt;store($request, $dest);
<ul> <ul>
<li><code>.txt</code></li> <li><code>.txt</code></li>
<li><code>.rtf</code></li> <li><code>.rtf</code></li>
<li><code>.fodt</code></li>
<li><code>.doc</code></li> <li><code>.doc</code></li>
<li><code>.docx</code></li> <li><code>.docx</code></li>
<li><code>.odt</code></li> <li><code>.odt</code></li>
@@ -704,7 +717,7 @@ $files = [
]; ];
$request = new OfficeRequest($files); $request = new OfficeRequest($files);
$dest = &#34;result.pdf&#34;; $dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest); $client-&gt;store($request, $dest);
</pre> </pre>
<h2 class="Heading"><a class="Anchor" aria-hidden="true" id="office.orientation" href="#office.orientation"> <h2 class="Heading"><a class="Anchor" aria-hidden="true" id="office.orientation" href="#office.orientation">
@@ -757,7 +770,7 @@ $files = [
$request = new OfficeRequest($files); $request = new OfficeRequest($files);
$request-&gt;setLandscape(true); $request-&gt;setLandscape(true);
$dest = &#34;result.pdf&#34;; $dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest); $client-&gt;store($request, $dest);
</pre> </pre>
</div> </div>
@@ -774,9 +787,13 @@ $filename = $client-&gt;store($request, $dest);
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
</a>Basic</h2> </a>Basic</h2>
<p>Nothing special here: you may send one or more PDF files and the API <p>Nothing fancy here: you may send one or more PDF files and the API
will merge them and return the resulting PDF file.</p> will merge them and return the resulting PDF file.</p>
<blockquote>
<p><strong>Attention:</strong> Gotenberg merges the PDF files alphabetically.</p>
</blockquote>
<h3 class="Heading"><a class="Anchor" aria-hidden="true" id="merge.basic.c_url" href="#merge.basic.c_url"> <h3 class="Heading"><a class="Anchor" aria-hidden="true" id="merge.basic.c_url" href="#merge.basic.c_url">
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
</a>cURL</h3> </a>cURL</h3>
@@ -818,7 +835,7 @@ $files = [
]; ];
$request = new MergeRequest($files); $request = new MergeRequest($files);
$dest = &#34;result.pdf&#34;; $dest = &#34;result.pdf&#34;;
$filename = $client-&gt;store($request, $dest); $client-&gt;store($request, $dest);
</pre> </pre>
</div> </div>

View File

@@ -1,6 +1,15 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-10196481-9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-10196481-9');
</script>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge"> <meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">

4
go.mod
View File

@@ -1,7 +1,6 @@
module github.com/thecodingmachine/gotenberg module github.com/thecodingmachine/gotenberg
require ( require (
github.com/derekparker/delve v1.1.0
github.com/google/go-cmp v0.2.0 // indirect github.com/google/go-cmp v0.2.0 // indirect
github.com/gorilla/websocket v1.4.0 // indirect github.com/gorilla/websocket v1.4.0 // indirect
github.com/hhrutter/pdfcpu v0.1.19 github.com/hhrutter/pdfcpu v0.1.19
@@ -12,10 +11,9 @@ require (
github.com/pkg/errors v0.8.0 // indirect github.com/pkg/errors v0.8.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 github.com/russross/blackfriday/v2 v2.0.1
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95 // indirect github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.2.2 github.com/stretchr/testify v1.2.2
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 // indirect golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 // indirect
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc golang.org/x/net v0.0.0-20181201002055-351d144fa1fc // indirect
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35 // indirect golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35 // indirect
) )

10
go.sum
View File

@@ -1,23 +1,15 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/derekparker/delve v1.1.0 h1:icd65nMp7s2HiLz6y/6RCVXBdoED3xxYLwX09EMaRCc=
github.com/derekparker/delve v1.1.0/go.mod h1:pMSZMfp0Nhbm8qdZJkuE/yPGOkLpGXLS1I4poXQpuJU=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/hhrutter/pdfcpu v0.1.18 h1:GX3d6tZxmQlmB5X9VUyOtx7+HZZpR+8ISLqBineP6dc=
github.com/hhrutter/pdfcpu v0.1.18/go.mod h1:iaCmXGnOXPIvoGLELZZc4m/GpIopVsvLQ00thrbu8LU=
github.com/hhrutter/pdfcpu v0.1.19 h1:J6GjNFDPjurQWallPW9gmz3CcNqBfvgB7Dad9T3e8Hc= github.com/hhrutter/pdfcpu v0.1.19 h1:J6GjNFDPjurQWallPW9gmz3CcNqBfvgB7Dad9T3e8Hc=
github.com/hhrutter/pdfcpu v0.1.19/go.mod h1:iaCmXGnOXPIvoGLELZZc4m/GpIopVsvLQ00thrbu8LU= github.com/hhrutter/pdfcpu v0.1.19/go.mod h1:iaCmXGnOXPIvoGLELZZc4m/GpIopVsvLQ00thrbu8LU=
github.com/labstack/echo v0.0.0-20181123063703-c7eb8da9ec73 h1:oQvA3Xy8274W5Ldgo6Nogy4lX8XO5AaIBsjF5Ggk0IU=
github.com/labstack/echo v0.0.0-20181123063703-c7eb8da9ec73/go.mod h1:rS0D1UPvC8/3sXjhSwEq+K1olh7ipbDhjDWATN2KSgA=
github.com/labstack/echo v0.0.0-20190126223945-739700bf4ef7 h1:kFheQLunLP9dCBrmg3D7y9FD44tlk/nvZQ7JCNvvWEA= github.com/labstack/echo v0.0.0-20190126223945-739700bf4ef7 h1:kFheQLunLP9dCBrmg3D7y9FD44tlk/nvZQ7JCNvvWEA=
github.com/labstack/echo v0.0.0-20190126223945-739700bf4ef7/go.mod h1:rS0D1UPvC8/3sXjhSwEq+K1olh7ipbDhjDWATN2KSgA= github.com/labstack/echo v0.0.0-20190126223945-739700bf4ef7/go.mod h1:rS0D1UPvC8/3sXjhSwEq+K1olh7ipbDhjDWATN2KSgA=
github.com/labstack/echo v3.3.5+incompatible h1:9PfxPUmasKzeJor9uQTaXLT6WUG/r+vSTmvXxvv3JO4=
github.com/labstack/echo v3.3.5+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/gommon v0.2.7/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4= github.com/labstack/gommon v0.2.7/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
github.com/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0= github.com/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0=
github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4= github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
@@ -37,8 +29,6 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95 h1:/vdW8Cb7EXrkqWGufVMES1OH2sU9gKVb2n9/1y5NMBY= github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95 h1:/vdW8Cb7EXrkqWGufVMES1OH2sU9gKVb2n9/1y5NMBY=
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=

View File

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

View File

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

View File

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

View File

@@ -13,15 +13,16 @@ import (
) )
const ( const (
remoteURL string = "remoteURL" remoteURL string = "remoteURL"
webhookURL string = "webhookURL" webhookURL string = "webhookURL"
paperWidth string = "paperWidth" paperWidth string = "paperWidth"
paperHeight string = "paperHeight" paperHeight string = "paperHeight"
marginTop string = "marginTop" marginTop string = "marginTop"
marginBottom string = "marginBottom" marginBottom string = "marginBottom"
marginLeft string = "marginLeft" marginLeft string = "marginLeft"
marginRight string = "marginRight" marginRight string = "marginRight"
landscape string = "landscape" landscape string = "landscape"
webFontsTimeout string = "webFontsTimeout"
) )
// resource facilitates storing and accessing // resource facilitates storing and accessing
@@ -42,6 +43,7 @@ func newResource(c echo.Context) (*resource, error) {
v[marginLeft] = c.FormValue(marginLeft) v[marginLeft] = c.FormValue(marginLeft)
v[marginRight] = c.FormValue(marginRight) v[marginRight] = c.FormValue(marginRight)
v[landscape] = c.FormValue(landscape) v[landscape] = c.FormValue(landscape)
v[webFontsTimeout] = c.FormValue(webFontsTimeout)
dirPath, err := rand.Get() dirPath, err := rand.Get()
if err != nil { if err != nil {
return nil, err return nil, err
@@ -190,5 +192,17 @@ func (r *resource) remoteURL() (string, error) {
return r.values[remoteURL], nil 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) webhookURL() string { return r.values[webhookURL] }
func (r *resource) removeAll() error { return os.RemoveAll(r.dirPath) } 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) return hijackErr(err, r)
} }
p.Landscape = landscape p.Landscape = landscape
chromeWebFontsTimeout, err := r.webFontsTimeout()
if err != nil {
return hijackErr(err, r)
}
p.WebFontsTimeout = chromeWebFontsTimeout
return print(c, p, r) return print(c, p, r)
} }

View File

@@ -18,17 +18,18 @@ import (
// HTML facilitates HTML to PDF conversion. // HTML facilitates HTML to PDF conversion.
type HTML struct { type HTML struct {
Context context.Context Context context.Context
URL string URL string
HeaderHTML string HeaderHTML string
FooterHTML string FooterHTML string
PaperWidth float64 PaperWidth float64
PaperHeight float64 PaperHeight float64
MarginTop float64 MarginTop float64
MarginBottom float64 MarginBottom float64
MarginLeft float64 MarginLeft float64
MarginRight float64 MarginRight float64
Landscape bool Landscape bool
WebFontsTimeout int64
} }
const defaultHeaderFooterHTML string = "<html><head></head><body></body></html>" 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) return fmt.Errorf("waiting for page loading: %v", err)
} }
// inject a script to make sure web fonts are loaded. // 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 () { document.fonts.ready.then(function () {
resolve('fonts loaded'); resolve('fonts loaded');
}); });
setTimeout(resolve.bind(resolve, 'timeout'), %.0f); setTimeout(resolve.bind(resolve, 'timeout'), %d);
});` });`, html.WebFontsTimeout)
scriptArg := runtime.NewEvaluateArgs(script).SetAwaitPromise(true) scriptArg := runtime.NewEvaluateArgs(script).SetAwaitPromise(true)
returnObj, _ := c.Runtime.Evaluate(html.Context, scriptArg) 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) loadFontsResult := string(returnObj.Result.Value)
if strings.Contains(loadFontsResult, "timeout") { if strings.Contains(loadFontsResult, "timeout") {
return errors.New("timed out loading fonts") return errors.New("timed out loading fonts")

View File

@@ -15,17 +15,18 @@ import (
// Markdown facilitates Markdown to PDF conversion. // Markdown facilitates Markdown to PDF conversion.
type Markdown struct { type Markdown struct {
Context context.Context Context context.Context
TemplatePath string TemplatePath string
HeaderHTML string HeaderHTML string
FooterHTML string FooterHTML string
PaperWidth float64 PaperWidth float64
PaperHeight float64 PaperHeight float64
MarginTop float64 MarginTop float64
MarginBottom float64 MarginBottom float64
MarginLeft float64 MarginLeft float64
MarginRight float64 MarginRight float64
Landscape bool Landscape bool
WebFontsTimeout int64
html *HTML html *HTML
} }
@@ -52,6 +53,7 @@ func (md *Markdown) Print(destination string) error {
md.html.MarginLeft = md.MarginLeft md.html.MarginLeft = md.MarginLeft
md.html.MarginRight = md.MarginRight md.html.MarginRight = md.MarginRight
md.html.Landscape = md.Landscape md.html.Landscape = md.Landscape
md.html.WebFontsTimeout = md.WebFontsTimeout
tmpl, err := template. tmpl, err := template.
New(filepath.Base(md.TemplatePath)). New(filepath.Base(md.TemplatePath)).
Funcs(template.FuncMap{"toHTML": toHTML}). Funcs(template.FuncMap{"toHTML": toHTML}).

View File

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

View File

@@ -78,6 +78,11 @@ func (html *HTMLRequest) SetLandscape(isLandscape bool) {
html.values[landscape] = strconv.FormatBool(isLandscape) 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 { func (html *HTMLRequest) getPostURL() string {
return "/convert/html" return "/convert/html"
} }

View File

@@ -88,6 +88,11 @@ func (markdown *MarkdownRequest) SetLandscape(isLandscape bool) {
markdown.values[landscape] = strconv.FormatBool(isLandscape) 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 { func (markdown *MarkdownRequest) getPostURL() string {
return "/convert/markdown" return "/convert/markdown"
} }

View File

@@ -63,6 +63,11 @@ func (url *URLRequest) SetLandscape(isLandscape bool) {
url.values[landscape] = strconv.FormatBool(isLandscape) 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 { func (url *URLRequest) getPostURL() string {
return "/convert/url" return "/convert/url"
} }

View File

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