Code Monkey home page Code Monkey logo

pdf-renderer's Introduction

PDF Renderer

Docker/dblworks/pdf-renderer

It's an HTTP service that will convert a HTML string to PDF. It uses Puppeteer under the hood, which means rendering is performed by Chromium's render engine; thus the HTML sent to this service should be developed and tested using Chrome/Chromium.

Read more about technical details of Puppeteer on their Github repo.

Installation

Because it's a docker image, it can be installed anywhere

To try out locally:

docker build -t pdf-renderer .
docker run --name pdf-renderer -d -p 5017:5017 pdf-renderer

If you prefer running the code in your system

⚠️ macOS Monterey runs the ControlCenter on port 5000.

Prepend e.g. PORT=5017 to the command

yarn run dev

or

yarn run local

which runs NODE_ENV=development yarn run dev.

Passing NODE_ENV=development will let puppeteer auto-detect the executable path, which is different from the hardcoded path, that is specifc for a Linux deploy.

      browser = await puppeteer.launch({
        headless: 'new',
        args: [
          '--no-sandbox',
          '--disable-setuid-sandbox',
        ],
        // executablePath: 'google-chrome-stable',
      })

Environment variables

AWS_BUCKET_NAME

AWS

To store the files to AWS we need to config the system to use aws-sdk

AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY

(this will need to be provided to you)

API Reference

Generate a PDF from HTML markup

POST /
content="<div>Hello World</div>"
filename="pdf_example.pdf"
saveFile=true
format={"landscape": false}

Parameters

content(required) - String - Html markup that will be converted to a PDF

saveFile(optional) - Boolean, true by default - Whether it should respond with a base64 encoded string for the pdf (e.g. to attach to an email provider) or upload the file as PDF to AWS S3

filename(optional) - String, current timestamp by default - The filename that the PDF file will be created.

format(optional) - Object, {} by default.

{
  "landscape": false, // - Boolean, `false` by default - Whether the PDF should be in landscape mode
}

Building

On a x86 chip

docker build -t dblworks/pdf-renderer:$TAGNAME .

On a ARM chip (for a x86 target):

docker build -t dblworks/pdf-renderer:$TAGNAME . --platform linux/amd64

Publishing

git fetch --all --tags
TAGNAME="$(git describe --abbrev=0 --tags)"

docker push dblworks/pdf-renderer:$TAGNAME

Deployment

Using AWS ECR as container registry

yarn build

docker build -t localhost/pdf-renderer .

git fetch --all --tags
LATEST_RELEASE="$(git describe --abbrev=0 --tags)"
AWS_REGION=eu-central-1
AWS_PROFILE=
AWS_ACCOUNT_ID=

aws ecr get-login-password --profile $AWS_PROFILE --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
docker tag localhost/pdf-renderer $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/pdf-renderer:$LATEST_RELEASE
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/pdf-renderer:$LATEST_RELEASE

pdf-renderer's People

Contributors

swiknaba avatar dependabot[bot] avatar bruno-goncalves avatar marcqualie avatar morozred avatar puckzxz avatar pieterbeulque avatar

Stargazers

Alexander Astafurov avatar  avatar Kevin Dierkx avatar ouquoi avatar Matjaž Kavčič avatar  avatar Alexander Rechsteiner avatar

Watchers

Svetlin Simonyan avatar  avatar  avatar  avatar  avatar Mohammed Abdulkareem avatar João Viana avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.