From ae967af7da8c7417d49d916814dfe8e2e3d64db7 Mon Sep 17 00:00:00 2001 From: Juha Heikkinen <82436478+juha-heikkinen@users.noreply.github.com> Date: Mon, 28 Jun 2021 15:14:40 +0300 Subject: [PATCH] Setting a custom PaperFormat with Width/Height options (#67) * Setting a custom PaperFormat with Width/Height options * Updated puppeteer and chromium * Added width and height to pdf options Co-authored-by: Savpek --- ApiDescription.md | 5 ++++- Dockerfile | 2 +- Pdf.Storage.csproj | 2 +- Pdf/PdfQueue.cs | 7 ++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ApiDescription.md b/ApiDescription.md index 84d8435..137ea6a 100644 --- a/ApiDescription.md +++ b/ApiDescription.md @@ -99,9 +99,12 @@ Pdf can contain following options "marginTop": "120px", "marginBottom": "120px", "marginLeft": "20px", - "marginRight": "20px" + "marginRight": "20px", + "width": null, + "height": null } ``` +Values in width AND height (in inches) creates a custom sized paper. If omitted the default A4 paper size will be used. For further information, see [https://www.puppeteersharp.com/api/PuppeteerSharp.PdfOptions.html](https://www.puppeteersharp.com/api/PuppeteerSharp.PdfOptions.html). diff --git a/Dockerfile b/Dockerfile index aa72e4b..61663ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # ! IMPORTANT: Keep chromium version synced with version from package 'PuppeteerSharp' # and match it with from https://pkgs.alpinelinux.org/packages -ARG chromium_version=89.0.4389.128-r2 +ARG chromium_version=91.0.4472.101-r0 FROM mcr.microsoft.com/dotnet/core/sdk:3.1.100-alpine3.10 as dotnetBuild ARG chromium_version diff --git a/Pdf.Storage.csproj b/Pdf.Storage.csproj index 88da175..69a211d 100644 --- a/Pdf.Storage.csproj +++ b/Pdf.Storage.csproj @@ -55,7 +55,7 @@ - + diff --git a/Pdf/PdfQueue.cs b/Pdf/PdfQueue.cs index 8902620..eb82611 100644 --- a/Pdf/PdfQueue.cs +++ b/Pdf/PdfQueue.cs @@ -80,7 +80,12 @@ await page.SetContentAsync(html, var defaultPdfOptions = new PdfOptions { - Format = PaperFormat.A4 + Format = options.ContainsKey("Width") && options.ContainsKey("Height") ? + new PaperFormat( + options["Width"].Value(), + options["Height"].Value() + ) : + PaperFormat.A4 }; return await page.PdfDataAsync(new PdfOptions