Skip to content

Script to create PDF from image files (JPEG, PNG) without reencoding. To use with mutool (from MuPdf).

Notifications You must be signed in to change notification settings

RoEdAl/mu-img2pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

img2pdf.coffee

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.

Requirements

  • NodeJS - required only to build JavaScript from CoffeeScript.
  • MuPDF toolkit.

Building js script

  1. Clone repository to any directory you like.

  2. Run npm install

    This command installs all required packages.

  3. Run npm run build (or npm run build:dev)

    This command generates img2pdf.js script in public subfolder. It is minified by WebPack.

Usage

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

Links

About

Script to create PDF from image files (JPEG, PNG) without reencoding. To use with mutool (from MuPdf).

Resources

Stars

Watchers

Forks