This is a CoffeeScript whitch creates PDF from image files (JPEG, PNG, JP2) without reencoding.
It was inspired by img2pdf Python script.
Use it with mutool run
from MuPDF toolkit.
mutool
accepts only scripts written in JavaScript (ES5) so you must build one from img2pdf.coffee
first.
- NodeJS - required only to build JavaScript from CoffeeScript.
- MuPDF toolkit.
-
Clone repository to any directory you like.
-
Run
npm install
This command installs all required packages.
-
Run
npm run build
(ornpm run build:dev
)This command generates
img2pdf.js
script inpublic
subfolder. It is minified by WebPack.
img2pdf
accepts only one parameter - path to configuration file.
Configuration is described in JSON format.
Example:
{
"tmpDocPath": "c:\\temp\\~img2pdf-doc.pdf",
"src": [
"front.jpg",
{"img": "img.jpg", "resolution": 1200},
{"pdf": "pdf2.pdf"},
{"doc": "svg1.svg", "scaleX": 5, "scaleY": 10},
{"pdf": "pdf1.pdf"},
{"img": ["img.jp2", "img.png"], "resolutionX": 300, "resolutionY": 400},
{"doc": ["svg2.svg", "svg3.svg"], "scale": 5},
],
"output": "images.pdf",
"outputOpts": ["sanitize"],
"info": {
"author": "Author",
"producer": "mu-img2pdf",
"title": "This is my super complex title",
"creationDate": [],
"modDate": [],
}
}
tmpDocPath
element is mandatory if you want to import/convert SVG documents.
It is a path to temporary PDF document with rendered SVG document.
Empty array []
in info.creationDate
and info.modDate
elements means current timestamp.
After preparing configuration file run mutool
:
mutool run img2pdf.js cfg.json