![]() |
#16 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,758
Karma: 731681
Join Date: Oct 2014
Location: Antwerp
Device: Kobo Aura H2O
|
Some quick experimentation shows that key and value seem to be reversed compared to the older version.
Code:
// tested in MuPDF 1.24.3 if (scriptArgs.length < 2) { print("usage: mutool run dejavu.js input.pdf output.pdf"); quit(); } var bgPix = new Pixmap(ColorSpace.DeviceGray, [0,0,1,1], false); var fgPix = new Pixmap(ColorSpace.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 (xobj, name) { var mask = xobj.SMask; if (mask) { // In newer versions this seems to say "Error: truncated jbig2 segment header" // var fgImg = doc.addImage(new Image(fgPix, doc.loadImage(mask))); // Quick workaround for the above problem var fgImg = doc.graftObject(mask); page.Resources.XObject[name] = fgImg; } else { page.Resources.XObject[name] = bgImg; } }); } doc.save(scriptArgs[1], "garbage=compact,compress"); |
![]() |
![]() |
![]() |
#17 |
Member
![]() Posts: 21
Karma: 10
Join Date: Sep 2013
Device: none
|
The mutool version was the issue. 1.23 does not work, but 1.21 did. Thank you very much!
I have added a script that converts all files in a given location. Warning: I made this to be run on my e-reader, so it doesn't keep the originals. Spoiler:
|
![]() |
![]() |
![]() |
#18 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 136
Karma: 33084
Join Date: Jan 2021
Device: Likebook Mars
|
@Frenzie: Using your script above I get white text on black background, but besides that, it works great. Is that how it's supposed to come out? Is there any way to invert it? My mutool version is 1.23.10.
Swapping the .clear() numbers didn't change anything. Last edited by jonnyl; 11-23-2024 at 12:01 PM. |
![]() |
![]() |
![]() |
#19 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,758
Karma: 731681
Join Date: Oct 2014
Location: Antwerp
Device: Kobo Aura H2O
|
Quote:
Code:
// In newer versions this seems to say "Error: truncated jbig2 segment header" // var fgImg = doc.addImage(new Image(fgPix, doc.loadImage(mask))); // Quick workaround for the above problem var fgImg = doc.graftObject(mask); |
|
![]() |
![]() |
![]() |
#20 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 136
Karma: 33084
Join Date: Jan 2021
Device: Likebook Mars
|
I got v1.21 for Windows, and it's working beautifully now. Thanks!
|
![]() |
![]() |
![]() |
#21 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 136
Karma: 33084
Join Date: Jan 2021
Device: Likebook Mars
|
Unfortunately, the script only works on some PDFs. On others, I only get a whole book's worth of empty white pages. I ran `mutool extract` without the script on both kinds of books but I can't tell a difference. All output 2 blurry pages and 1 monochrome inverted legible image (the only one needed, but inverted back to black text-on-white if possible) per page, and in the same order.
Is there anything I could do to make the script work on the other kind of books as well? |
![]() |
![]() |
![]() |
#22 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,758
Karma: 731681
Join Date: Oct 2014
Location: Antwerp
Device: Kobo Aura H2O
|
You'd have to link some of these other books first.
![]() |
![]() |
![]() |
![]() |
#23 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 136
Karma: 33084
Join Date: Jan 2021
Device: Likebook Mars
|
I found the problem. The one not working had the monochrome mask images typed as 'mask', and the working one as 'smask' (according to `pdfimages -list`). I just edited "var mask = xobj.SMask;" to "var mask = xobj.Mask;" and to my astonishment that worked
![]() |
![]() |
![]() |
![]() |
#24 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,758
Karma: 731681
Join Date: Oct 2014
Location: Antwerp
Device: Kobo Aura H2O
|
In that case you can probably just write it like:
Code:
var mask = xobj.SMask || xobj.Mask; |
![]() |
![]() |
![]() |
#25 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 136
Karma: 33084
Join Date: Jan 2021
Device: Likebook Mars
|
Confirmed this works. Thanks!
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Internet Archive | tubemonkey | Audiobook Discussions | 0 | 08-30-2014 02:27 PM |
Internet Archive preserves paper books | wallcraft | General Discussions | 24 | 06-18-2011 02:17 PM |
Shortcovers (Kobo?) adds 1.8 million scanned books from The Internet Archive | anurag | News | 11 | 06-15-2011 06:15 AM |
ARTICLE: Internet Archive BookServer | ekaser | News | 3 | 10-20-2009 10:20 PM |
Images from Google Books, Internet Archive, etc. | vivaldirules | Upload Help | 18 | 09-17-2009 10:00 AM |