Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example how to run in docker #206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
Loading