Quote:
but the script in the two versions does absolutely nothing.
|
Define nothing. It comes out black for me, which isn't nothing.
Swapping the colors in the .clear() commands and changing the mask to SMask takes care of that, and it is indeed a lot faster. Getting rid of the paper also improves render quality on eink.
Code:
if (scriptArgs.length < 2) {
print("usage: mutool run dejavu.js input.pdf output.pdf");
quit();
}
var bgPix = new Pixmap(DeviceGray, [0,0,1,1], false);
var fgPix = new Pixmap(DeviceGray, [0,0,1,1], false);
bgPix.clear(255);
fgPix.clear(0);
var doc = new PDFDocument(scriptArgs[0]);
var bgImg = doc.addImage(new Image(bgPix));
for (var i = 0; i < doc.countPages(); ++i) {
var page = doc.findPage(i);
page.Resources.XObject.forEach(function (name, xobj) {
var mask = xobj.SMask;
if (mask) {
var fgImg = doc.addImage(new Image(fgPix, doc.loadImage(mask)));
page.Resources.XObject[name] = fgImg;
} else {
page.Resources.XObject[name] = bgImg;
}
});
}
doc.save(scriptArgs[1], "garbage=compact,compress");