Skip to content

node-pdftk + serverless Real world example

License

Notifications You must be signed in to change notification settings

iicdii/node-pdftk-serverless

Repository files navigation

node-pdftk-serverless

pdftk logo serverless logo

node-pdftk + serverless Real world example

Installation

yarn
npm install -g serverless

Testing

You can easily test in local environment thanks to serverless-offline plugin.

Start local server

sls offline

It starts local server on http://localhost:3000. There are two endpoints /stamp, and /merge.

Send POST to http://localhost:3000/stamp to test stamp PDF

stamp_example Postman body example

Note that you should use input, stamp for key name.

It stamps stamp PDF on input PDF, but only first page. You can change the function in stamp.js.

It returns PDF blob with application/pdf header so you can check out the preview in response body in Postman.

Send POST to http://localhost:3000/merge to test merge PDF

merge_example Postman body example

It merges all incoming PDF regardless of key name. Note that the page order is output as a result of sorting the keys in the file in ascending order.

It returns PDF blob with application/pdf header so you can check out the preview in response body in Postman.

Deployment

Configure serverless.yml

provider:
  name: aws
  runtime: nodejs12.x
  stage: production
  region: ap-northeast-2

Update the region, stage, etc to meet your needs.

    layers:
      - arn:aws:lambda:ap-northeast-2:545918303703:layer:pdftkLayer:3

You can use my prebuilt lambda layer (pdftk v2.02) or use your own layer.

Serverless Deploy

sls deploy --stage=production

LICENSE

MIT

About

node-pdftk + serverless Real world example

Topics

Resources

License

Stars

Watchers

Forks