diff --git a/examples/docker/.dockerignore b/examples/docker/.dockerignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/examples/docker/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/examples/docker/Dockerfile b/examples/docker/Dockerfile new file mode 100644 index 0000000..118fcb2 --- /dev/null +++ b/examples/docker/Dockerfile @@ -0,0 +1,10 @@ +FROM node:20.9.0-alpine3.18 + +RUN apk update && apk add --no-cache make g++ python3 ghostscript graphicsmagick ghostscript-fonts + +WORKDIR /worker +COPY . /worker + +RUN npm install + +CMD node index.mjs diff --git a/examples/docker/README.md b/examples/docker/README.md new file mode 100644 index 0000000..53d6961 --- /dev/null +++ b/examples/docker/README.md @@ -0,0 +1,11 @@ +# Example Docker alpine + +Build the image: +```shell +docker build -t pdf2pic-docker . +``` + +Run the container: +```shell +docker run pdf2pic-docker +``` diff --git a/examples/docker/example.pdf b/examples/docker/example.pdf new file mode 100644 index 0000000..8ec5ae9 Binary files /dev/null and b/examples/docker/example.pdf differ diff --git a/examples/docker/index.mjs b/examples/docker/index.mjs new file mode 100644 index 0000000..7419706 --- /dev/null +++ b/examples/docker/index.mjs @@ -0,0 +1,10 @@ +import { fromBuffer } from 'pdf2pic'; +import fs from 'fs/promises' + +const pdfBuffer = await fs.readFile('example.pdf'); +const convert = fromBuffer(pdfBuffer, { width: 1024, preserveAspectRatio: true }); +const result = await convert(1, { responseType: 'buffer' }); + +console.log(result); + +await fs.writeFile('page_1.png', result.buffer, 'binary'); diff --git a/examples/docker/package.json b/examples/docker/package.json new file mode 100644 index 0000000..b870550 --- /dev/null +++ b/examples/docker/package.json @@ -0,0 +1,14 @@ +{ + "name": "example-docker", + "version": "1.0.0", + "description": "", + "main": "index.mjs", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "pdf2pic": "^3.1.1" + } +}