The colorspace options for mutool recolor
are rather limited (gray, rgb, cmyk). To make my own recoloring, I tried to write a javascript for use with mutool run
. The script should read a PDF file, apply some changes (recoloring) to each page, and write the modified PDF file.
Creating a script that copies the objects on each page into a new PDF document was not too difficult. My next step, I thought, would be to use Page.prototype.run(device, transform)
with my own Device
object that does the recoloring (or anything else I need). This means writing several callback functions like fillText(text, ctm, colorspace, color, alpha)
.
This is where I get stuck. I can change the color
or colorspace
in fillText
, but then what am I supposed to do? I think I want to call the fillText
callback of a device that creates PDF, like the pdfwrite
device in ghostscript. However, such a device does not exist in MuPDF, it seems.
My question is, what is the best way to create a pdfwrite
device, and is that even possible?
I did try to do what I want in ghostscript, but I have a PDF document with complicated figures that ghostscript does not copy correctly. Also, having a pdfwrite
device for MuPDF.js would open up many possibilities for PDF transformations in javascript.