Sign inSign up

craysiii/arthur

By craysiii

•Updated about 2 years ago

Make PDF files from URLs and base64-encoded HTML.

Image
0

298

craysiii/arthur repository overview

⁠Arthur

Make PDF files from URLs and base64-encoded HTML.

⁠Endpoints

There are two separate endpoints in order to generate a PDF depending on whether you want to pass a URL or a base64-encoded HTML string.

Each endpoint accepts a POST request with a JSON body.

/from-url requires a url field in the JSON body. It must include the scheme (i.e. protocol) in order to be considered valid (e.g. https://google.com instead of google.com)

/from-base64 requires a encodedTemplate field in the JSON body. It must be a base64-encoded string.

⁠Request Options

The following options are common among both endpoints and can be defined as fields in the JSON body. You can read more about the underlying options here⁠

⁠Width / Height / Margin Measurements

All measurement fields must be an int or float optionally followed by a unit of measurement.

Valid units are px|in|cm|mm. If no unit is provided, then defaults to px. Examples include 1024(pixels), 12.5in, 10cm, and 400mm.

  • displayHeaderFooter: Expects boolean. Display header and footer. Defaults to false.
  • headerTemplate: Expects string. HTML template for the print header. Must be base64-encoded. Check underlying Playwright documentation⁠ for more.
  • footerTemplate: Expects string. HTML template for the print footer. Must be base64-encoded. Check underlying Playwright documentation⁠ for more.
⁠Margin Options

All margin options default to 0px.

  • margin: Expects string. Margin to use for all sides of each page. This field has lower precedence than other margin fields.
  • marginTop: Expects string. Margin to use for the top of each page.
  • marginLeft: Expects string. Margin to use for the left side of each page.
  • marginRight: Expects string. Margin to use for the right side of each page.
  • marginBottom: Expects string. Margin to use for the bottom of each page.
⁠Page Size / Layout Options
  • landscape: Expects boolean. Paper orientation. Defaults to false.
  • format: Expects string. Takes priority over width or height. Options are Letter, Legal, Tabloid, Ledger, and A0 through A6. Defaults to Letter.
  • width: Expects string. Width of the printed page.
  • height: Expects string. Height of the printed page.
  • singlePage: Expects boolean. Prints to a single page. Takes precedence over height field.
  • scale: Expects float. Scale of the page rendering. Must be between 0.1 and 2.0.
  • preferCssPageSize: Expects boolean. Give any CSS @page size declared in the page priority over what is declared in width and height or format options. Defaults to false.
⁠Miscellaneous Options
  • outline: Expects boolean. Embed the document outline into the PDF. Defaults to false.
  • pageRanges: Expects string. Paper ranges to print, e.g., 1-5, 8, 11-13. Defaults to all pages.
  • printBackground: Expects boolean. Print background graphics. Defaults to false.
  • tagged: Expects boolean. Generate tagged (accessible) PDF. Defaults to false.
  • pageRenderDelay: Expects int. Wait for a period of time in milliseconds before saving the PDF. Defaults to 0.
⁠Response Options
  • responseFormat: Expects string. Determines which format to return the PDF in. Valid options are PDF and BASE64. Defaults to PDF.
  • fileName: Expects string. When using the PDF responseFormat type, determines the name of the returned file.

⁠Deploying

I suggest that you use docker compose to deploy this.

services:
  arthur:
    image: 'craysiii/arthur:latest'
    restart: unless-stopped
    ports:
      - 9650:8080
    # environment:
    #   API_KEY: some-complex-string

⁠Authentication

An extremely simple form of API authentication can be achieved by setting an API_KEY environment variable within your environment, and then passing the same value in the API_KEY header in your requests.

⁠Security Considerations

Currently, the docker container is configured to run as root. This is bad. It is due to Playwright's requirement to run apt-get within the container so that it can install the appropriate version of Chromium during start-up. I would highly recommend using the API_KEY option.

⁠License

MIT.

Tag summary

Content type

Image

Digest

sha256:8c1445628…

Size

125.1 MB

Last updated

about 2 years ago

docker pull craysiii/arthur