Generate a print-ready PDF from a folder of images.
The tool automatically:
- Reads all images from the
imagesfolder - Scales every image to 5.5 cm wide
- Preserves the original aspect ratio
- Arranges images across A4 pages
- Creates new rows automatically
- Creates new pages automatically
- Exports a single PDF ready for printing
- Node.js 18+
- npm
Install dependencies:
npm install pdfkit sharpimage-pdfmaker/
│
├── images/
│ ├── image1.jpg
│ ├── image2.png
│ ├── image3.jpeg
│ └── ...
│
├── index.cjs
├── package.json
└── README.md
Place all images you want to print inside the images folder.
Open index.cjs and adjust these values if needed:
const PAGE_SIZE = "A4";
const MARGIN_MM = 10;
const GAP_MM = 3;
const IMAGE_WIDTH_CM = 5.5;| Setting | Description |
|---|---|
| PAGE_SIZE | Paper size (A4, Letter, etc.) |
| MARGIN_MM | Page margin in millimeters |
| GAP_MM | Gap between images in millimeters |
| IMAGE_WIDTH_CM | Width of each image in centimeters |
Generate the PDF:
node index.cjsAfter completion:
output.pdf
will be created in the project root.
Input:
images/
├── photo1.jpg
├── photo2.jpg
├── photo3.jpg
└── photo4.jpg
Output:
output.pdf
Images will be arranged automatically across one or more A4 sheets.
- JPG
- JPEG
- PNG
- WEBP
✅ Fixed image width (5.5 cm)
✅ Aspect ratio preserved
✅ Automatic row wrapping
✅ Automatic page creation
✅ A4 print layout
✅ Multiple page support
✅ Works with portrait and landscape images
Make sure images are placed inside:
./images
Verify that the images are valid JPG, PNG, JPEG, or WEBP files.
Reinstall dependencies:
rm -rf node_modules package-lock.json
npm installMIT