Skip to main content

Django library for invoking splat

Project description

splat

splat is simple aws lambda function that takes HTML/CSS/JS, invokes PrinceXML to render it and returns the resulting PDF in one of many ways.

It is intended to be a DIY docraptor of sorts.

Installation

Simply build the docker image, deploy it to AWS, then invoke the lambda with an event body JSON that performs the desired operation. For example: {"document_content": "<h1>Hello, World!</h1>"}

This can be done via a function_url, apigateway or lambda invoke.

Invoking splat

Event payload body.

Field Type Description
javascript (princexml) boolean (False) Enables princeXML's javascript execution. This will not render react but can be used for formatting.
check_license boolean (False) Send this field to receive a check on remaining license usage
document_content string Embed the html content in the payload. There will be AWS payload size limitations.
document_url url Fetch the html content from document_url to disk before rendering.
browser_url url Browser the browser_url with playwright before rendering with renderer
browser_headers Mapping[str,str] Add additional headers to playwright before visiting browser_url
browser_pdf_options Mapping[str,str] Add additional options to playwright .pdf() call
renderer princexml or playwright Renderer to render the html with
bucket_name string Output the resulting pdf to s3://{bucket_name}/{uuid}.pdf. The lambda will require permission to upload to the bucket. The response will include bucket, key, presigned_url
presigned_url url Output the resulting pdf to the presigned url. Generate the presigned url with put_object. See Output for more information.

Input

Pass content in event: {"document_content": "<h1>Hello, World!</h1>"}

Pass content via URL: {"document_url": "https://some_page/report.html"}

Pass content via Browser page: {"browser_url": "https://some_react_page/", "renderer": "princexml", "browser_headers": {"Authorization": "Bearer SOME_BEARER_TOKEN"}}

Output

Returns PDF base64 encoded by default.

To save to an s3 bucket (lambda requires permission): {"bucket_name": "<BUCKET>"}

To save to a presigned url: {"presigned_url": "<URL>"}

PrinceXML License

splat will attempt to install a PrinceXML license file by default. Just drop your license.dat in the root directory before you build the docker container. The licence file is gitignored for your convenience. If you do not have a licence file, Prince will watermark your PDFs, and you can only use them non-commercially. See their license page for more information.

You can check the status of the licence by invoking the lambda with the {"check_license": true} option, and interpreting the response, you can use this to periodically check the status of the licence and raise an alert if it's about to expire, and to verify that your new licence has updated correctly.

Fonts

splat will add any fonts inside a fonts.zip file. Ensure the zip file contains a folder called fonts with all fonts inside. Simply drop into the root directory and build the docker container. The fonts.zip file is gitignored for your convenience. By default, prince comes with a small suite of liberation fonts.

Library

Splat can be used via the uptick_splat library. Install with pip install uptick_splat.

Usage:

from uptick_splat import configure_splat, pdf_with_splat


configure_splat(
    function_region="ap-southeast-2",
    function_name="splat",
    default_bucket_name="your-bucket-to-upload-html-to",
)

some_html = "<h1>test</h1>"

pdf_with_splat(some_html, bucket_name="test_bucket")
# or
pdf_with_splat(some_html)

Development

Install mise task runner.

mise run install # booststrap the project and install requirements

mise run test # run tests

mise run format # format

Local testing

Use the ./splat_cli.py program (via UV) to execute the lambda. It is possible to target the lambda running in the docker container or a deployed lambda running in aws.

Example usages:

# Invoke using a local function url
./splat_cli.py -o /tmp/google.pdf -b https://google.com

# Invoke using a deployed AWS lambda against an embedded document content
./splat_cli.py -o /tmp/test.pdf -c "<h1> hi </h1>" --function-name splat-staging

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uptick_splat-0.4.3.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uptick_splat-0.4.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file uptick_splat-0.4.3.tar.gz.

File metadata

  • Download URL: uptick_splat-0.4.3.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for uptick_splat-0.4.3.tar.gz
Algorithm Hash digest
SHA256 3034a22ed2948ba07596b8c4d4daf6e7a8a8df497f1d407a748acc517408d435
MD5 26a62827979627df51a0e0b11ba65a58
BLAKE2b-256 f89a525b67581054c5ed2ecf3ce53afda778a7e38d8fd00087ce802625013297

See more details on using hashes here.

File details

Details for the file uptick_splat-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: uptick_splat-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for uptick_splat-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 83b283d13f76a863c6302a68b0d825203db418f7ad9debdceb1c4238e85c313d
MD5 1226611a2d5eb8c9d77e0bbf2b1e545a
BLAKE2b-256 88e9df3efaf6825fbd7f47aa5ff22f1925ac7c105e937d3d164b3f48f3b8eb62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page