-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move
ResponseData
out of the core package, rename structs…
… and add better documentation
- Loading branch information
Showing
3 changed files
with
44 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
/* | ||
Package print2pdf provides functions to save a webpage as a PDF file, leveraging Chromium and the DevTools Protocol. | ||
Requires two environment variables to be set: | ||
- `CHROMIUM_PATH` with the full path to the Chromium binary | ||
- `BUCKET` with the name of the AWS S3 bucket | ||
This packages uses `init()` functions to initialize the AWS SDK and start an headless instance of Chromium, to reduce | ||
startup time when used as a web service. | ||
*/ | ||
package print2pdf | ||
|
||
// Page margins of the generated PDF, in inches. | ||
type PrintMargins struct { | ||
Top float64 `json:"top,omitempty"` | ||
Bottom float64 `json:"bottom,omitempty"` | ||
Left float64 `json:"left,omitempty"` | ||
Right float64 `json:"right,omitempty"` | ||
} | ||
|
||
type RequestData struct { | ||
Url string `json:"url"` | ||
FileName string `json:"file_name"` | ||
Media string `json:"media,omitempty"` | ||
Format string `json:"format,omitempty"` | ||
Background *bool `json:"background,omitempty"` // pointer to handle missing value from request (nil, false, true) | ||
Layout string `json:"layout,omitempty"` | ||
Margins *PrintMargins `json:"margin,omitempty"` // pointer to handle missing value from request (nil, PrintMargins) | ||
Scale float64 `json:"scale,omitempty"` | ||
} | ||
|
||
type ResponseData struct { | ||
// Parameters for generating a PDF. | ||
type GetPDFParams struct { | ||
// URL of the webpage to save. Required. | ||
Url string `json:"url"` | ||
// Filename of the generated PDF. A `.pdf` suffix will be appended if not present. Required. | ||
FileName string `json:"file_name"` | ||
// Media type to emulate. Accepted values are `"print"` and `"screen"`. Default is `"print"`. | ||
Media string `json:"media,omitempty"` | ||
// Page format. See [FormatsMap] for accepted values. Default is `"A4"`. | ||
Format string `json:"format,omitempty"` | ||
// Print background graphics. Default is `true`. | ||
Background *bool `json:"background,omitempty"` | ||
// Page orientation. Accepted values are `"landscape"` and `"portrait"`. Default is `"portrait"`. | ||
Layout string `json:"layout,omitempty"` | ||
// Page margins in inches. Default is all `0`. | ||
Margins *PrintMargins `json:"margin,omitempty"` | ||
// Scale of the webpage rendering. Default is `1` | ||
Scale float64 `json:"scale,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters