From 3ed99133d4f123e697ce3f8175b3fc71c465d722 Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Fri, 25 Jan 2019 15:48:40 +0100 Subject: [PATCH] removing paper size for Office conversion --- build/base/Dockerfile | 2 +- build/docs/content/04-office.md | 11 ++--------- docs/index.html | 21 ++++++--------------- internal/app/api/office.go | 6 ------ internal/pkg/printer/office.go | 27 +++------------------------ pkg/client.go | 1 - pkg/office.go | 6 ------ pkg/office_test.go | 1 - 8 files changed, 12 insertions(+), 63 deletions(-) diff --git a/build/base/Dockerfile b/build/base/Dockerfile index 8f00244c..4d11b724 100644 --- a/build/base/Dockerfile +++ b/build/base/Dockerfile @@ -31,7 +31,7 @@ RUN curl -sL https://deb.nodesource.com/setup_9.x | bash - &&\ COPY --from=hack /usr/bin/pm2 /usr/bin/pm2 COPY --from=hack /usr/share/pm2 /usr/share/pm2 -COPY --from=hack /etc/default/pm2 /usr/default/pm2 +COPY --from=hack /etc/default/pm2 /etc/default/pm2 COPY --from=hack /etc/systemd/system/pm2.service /etc/systemd/system/pm2.service # |-------------------------------------------------------------------------- diff --git a/build/docs/content/04-office.md b/build/docs/content/04-office.md index 55b26857..8adcab3b 100644 --- a/build/docs/content/04-office.md +++ b/build/docs/content/04-office.md @@ -69,14 +69,11 @@ $dirPath = "/foo"; $filename = $client->store($request, $dirPath); ``` -## Paper size and orientation +## Orientation You may also customize the resulting PDF format. -By default, it will be rendered with `A4` size and `portrait` orientation. - -> Paper size has to be provided in `inches`. -> Also, you have to set both `paperWidth` and `paperHeight`. +By default, it will be rendered `portrait` orientation. ### cURL @@ -85,8 +82,6 @@ $ curl --request POST \ --url http://localhost:3000/convert/office \ --header 'Content-Type: multipart/form-data' \ --form files=@document.docx \ - --form paperWidth=8.27 \ - --form paperHeight=11.27 \ --form landscape=true \ -o result.pdf ``` @@ -99,7 +94,6 @@ import "github.com/thecodingmachine/gotenberg/pkg" func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} req, _ := gotenberg.NewOfficeRequest([]string{"document.docx"}) - req.SetPaperSize(gotenberg.A4) req.SetLandscape(true) dest := "result.pdf" c.Store(req, dest) @@ -118,7 +112,6 @@ $files = [ DocumentFactory::makeFromPath('document.docx', 'document.docx'), ]; $request = new OfficeRequest($files); -$request->setPaperSize(Request::A4); $request->setLandscape(true); $dirPath = "/foo"; $filename = $client->store($request, $dirPath); diff --git a/docs/index.html b/docs/index.html index 1023b08b..87abfb1c 100755 --- a/docs/index.html +++ b/docs/index.html @@ -637,20 +637,15 @@ $dirPath = "/foo"; $filename = $client->store($request, $dirPath); -

Paper size and orientation

+Orientation

You may also customize the resulting PDF format.

-

By default, it will be rendered with A4 size and portrait orientation.

+

By default, it will be rendered portrait orientation.

-
-

Paper size has to be provided in inches. -Also, you have to set both paperWidth and paperHeight.

-
- -

cURL

@@ -658,13 +653,11 @@ Also, you have to set both paperWidth and paperHeight. --url http://localhost:3000/convert/office \ --header 'Content-Type: multipart/form-data' \ --form files=@document.docx \ - --form paperWidth=8.27 \ - --form paperHeight=11.27 \ --form landscape=true \ -o result.pdf -

Go

@@ -673,14 +666,13 @@ Also, you have to set both paperWidth and paperHeight. func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} req, _ := gotenberg.NewOfficeRequest([]string{"document.docx"}) - req.SetPaperSize(gotenberg.A4) req.SetLandscape(true) dest := "result.pdf" c.Store(req, dest) } -

PHP

@@ -693,7 +685,6 @@ $files = [ DocumentFactory::makeFromPath('document.docx', 'document.docx'), ]; $request = new OfficeRequest($files); -$request->setPaperSize(Request::A4); $request->setLandscape(true); $dirPath = "/foo"; $filename = $client->store($request, $dirPath); diff --git a/internal/app/api/office.go b/internal/app/api/office.go index ee6df2f0..aece6c7b 100644 --- a/internal/app/api/office.go +++ b/internal/app/api/office.go @@ -38,12 +38,6 @@ func convertOffice(c echo.Context) error { return hijackErr(errors.New("no suitable office documents to convert"), r) } p := &printer.Office{Context: ctx, FilePaths: fpaths} - paperSize, err := r.paperSize() - if err != nil { - return hijackErr(err, r) - } - p.PaperWidth = paperSize[0] - p.PaperHeight = paperSize[1] landscape, err := r.landscape() if err != nil { return hijackErr(err, r) diff --git a/internal/pkg/printer/office.go b/internal/pkg/printer/office.go index b6f1f441..5a090378 100644 --- a/internal/pkg/printer/office.go +++ b/internal/pkg/printer/office.go @@ -7,7 +7,6 @@ import ( "os" "os/exec" "path/filepath" - "strconv" "sync" "github.com/thecodingmachine/gotenberg/internal/pkg/rand" @@ -17,11 +16,9 @@ var mu sync.Mutex // Office facilitates Office documents to PDF conversion. type Office struct { - Context context.Context - FilePaths []string - PaperWidth float64 - PaperHeight float64 - Landscape bool + Context context.Context + FilePaths []string + Landscape bool } // Print converts Office documents to PDF. @@ -36,15 +33,9 @@ func (o *Office) Print(destination string) error { return err } tmpDest := fmt.Sprintf("%s/%s.pdf", dirPath, baseFilename) - paperSize, err := unoconvPaperSize(o.PaperWidth, o.PaperHeight) - if err != nil { - return err - } cmdArgs := []string{ "--format", "pdf", - "--printer", - paperSize, } if o.Landscape { cmdArgs = append(cmdArgs, "--printer", "PaperOrientation=landscape") @@ -70,18 +61,6 @@ func (o *Office) Print(destination string) error { return Merge(fpaths, destination) } -func unoconvPaperSize(paperWidth, paperHeight float64) (string, error) { - width, err := strconv.Atoi(fmt.Sprintf("%.0f", paperWidth*25.4)) - if err != nil { - return "", fmt.Errorf("%0.f: converting width to millimiter: %v", paperWidth, err) - } - height, err := strconv.Atoi(fmt.Sprintf("%.0f", paperHeight*25.4)) - if err != nil { - return "", fmt.Errorf("%0.f: converting height to millimiter: %v", paperHeight, err) - } - return fmt.Sprintf("PaperSize=%dx%d", width, height), nil -} - // Compile-time checks to ensure type implements desired interfaces. var ( _ = Printer(new(Office)) diff --git a/pkg/client.go b/pkg/client.go index c43f58ee..354c2dec 100644 --- a/pkg/client.go +++ b/pkg/client.go @@ -81,7 +81,6 @@ type ChromeRequest interface { // conversion requests which will be // handle by unoconv. type UnoconvRequest interface { - SetPaperSize(size [2]float64) SetLandscape(landscape bool) } diff --git a/pkg/office.go b/pkg/office.go index 06a19079..9fc677a7 100644 --- a/pkg/office.go +++ b/pkg/office.go @@ -28,12 +28,6 @@ func (office *OfficeRequest) SetWebhookURL(webhookURL string) { office.values[webhookURL] = webhookURL } -// SetPaperSize sets paperWidth and paperHeight form fields. -func (office *OfficeRequest) SetPaperSize(size [2]float64) { - office.values[paperWidth] = fmt.Sprintf("%f", size[0]) - office.values[paperHeight] = fmt.Sprintf("%f", size[1]) -} - // SetLandscape sets landscape form field. func (office *OfficeRequest) SetLandscape(isLandscape bool) { office.values[landscape] = strconv.FormatBool(isLandscape) diff --git a/pkg/office_test.go b/pkg/office_test.go index 4f1bf682..ecfcff6f 100644 --- a/pkg/office_test.go +++ b/pkg/office_test.go @@ -17,7 +17,6 @@ func TestOffice(t *testing.T) { test.OfficeTestFilePath(t, "document.docx"), }) require.Nil(t, err) - req.SetPaperSize(A4) req.SetLandscape(false) dirPath, err := rand.Get() require.Nil(t, err)