Skip to content

Commit

Permalink
docs(docker): example how to run in alpine docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
mskec committed Jul 9, 2024
1 parent 4aaefd1 commit ef936a3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 10 additions & 0 deletions examples/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions examples/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Example Docker alpine

Build the image:
```shell
docker build -t pdf2pic-docker .
```

Run the container:
```shell
docker run pdf2pic-docker
```
Binary file added examples/docker/example.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions examples/docker/index.mjs
Original file line number Diff line number Diff line change
@@ -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');
14 changes: 14 additions & 0 deletions examples/docker/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit ef936a3

Please sign in to comment.