Sign inSign up

ariefsn/html-to-pdf

By ariefsn

•Updated 2 months ago

Image
Developer tools
0

1.1K

ariefsn/html-to-pdf repository overview

⁠HTML to PDF

A mini service to generate PDF from HTML, uses Handlebars for parsing the HTML, Puppeteer to run the headless browser, and NATS for handling queue.

⁠Tools

⁠How to

  1. Go to compose directory cd compose.
  2. Copy the .env.example to .env and set the variables.
  3. Run docker compose up --build -d.
  4. The swagger documentation is on path /docs.
  5. The main endpoint is /pdf with method POST, for the payload⁠ described below.

⁠Tag Management

Commands to manage git tags for Docker image releases.

CommandUsageDescription
tag-deletemake tag-delete TAG=v1.0.0Delete tag from local and remote
tag-pushmake tag-push TAG=v1.0.0Create and push a new tag
tag-repushmake tag-repush TAG=v1.0.0Delete existing tag and re-push (useful when a build fails)

⁠Notes

  • This service is using NATS, run NATS server locally or either with docker already in compose/compose.yaml file.
  • The client directory is only the example how to interact with the service.

⁠Payload

FieldRequiredDesc
htmlYesThe escaped HTML string for rendering.
headerNoThe escaped HTML string for header purpose.
footerNoThe escaped HTML string for footer purpose.
marginNoThe object for setting the margin { top, right, bottom, left }.
aliasNoThe alias for the filename.
valuesNoThe object for the data that needed by the html.
formatNoThe format for generated PDF, should be one of "letter" | "legal" | "tabloid" | "ledger" | "a0" | "a1" | "a2" | "a3" | "a4" | "a5" | "a6", this field will take over the width and height.
widthNoWidth of document. Ignored if format is filled.
heightNoHeight of document. Ignored if format is filled.
webhookUrlNoURL to receive the generated PDF. The service will POST a JSON body containing alias, metadata, and pdf (base64-encoded). See Webhook Payload⁠ below.
metadataNoArbitrary key-value object sent along with the webhook, so the receiver can identify/route the data (e.g. { "orderId": "123", "userId": "456" }).

⁠Webhook Payload

When webhookUrl is provided, the service will POST a JSON body to that URL:

{
  "alias": "my-document",
  "metadata": { "orderId": "123", "userId": "456" },
  "pdf": "<base64-encoded PDF>"
}
FieldTypeDescription
aliasstringThe filename alias (without .pdf extension).
metadataobjectThe metadata object from the original request (defaults to {}).
pdfstringThe generated PDF file, base64-encoded.

⁠Registered Helper

NameArgumentsReturn
addnumber, numbernumber
minnumber, numbernumber
mulnumber, numbernumber
divnumber, numbernumber
gtnumber, numberboolean
gtenumber, numberboolean
ltnumber, numberboolean
ltenumber, numberboolean
eqnumber, numberboolean
nenumber, numberboolean
orboolean, booleanboolean
andboolean, booleanboolean
notbooleanboolean
containsstring, stringboolean
startWithstring, stringboolean
endWithstring, stringboolean
replacestring, string, stringstring
jsonobjectstring
lowerstringstring
upperstringstring
isEmptyanyboolean

Tag summary

Content type

Image

Digest

sha256:e2d40a4b5…

Size

471.1 MB

Last updated

2 months ago

docker pull ariefsn/html-to-pdf