diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-09-05 15:16:30 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-09-21 14:21:05 +0200 |
commit | 41c6a5a06acfa9386c980d24c538fc22cc7c1bb3 (patch) | |
tree | a147d86de73f145deaac8bb64177ab25a5fe0755 | |
parent | 211234411c68f4578c3bbfafeb84e8d26040443a (diff) | |
download | mupdf-41c6a5a06acfa9386c980d24c538fc22cc7c1bb3.tar.xz |
Add 'fix-s22pdf.js' script to examples.
-rw-r--r-- | docs/examples/fix-s22pdf.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/docs/examples/fix-s22pdf.js b/docs/examples/fix-s22pdf.js new file mode 100644 index 00000000..276cbb1b --- /dev/null +++ b/docs/examples/fix-s22pdf.js @@ -0,0 +1,33 @@ +// A simple script to fix the broken fonts in PDF files generated by S22PDF. + +if (scriptArgs.length != 2) { + print("usage: mutool run fix-s22pdf.js input.pdf output.pdf"); + quit(); +} + +var doc = new PDFDocument(scriptArgs[0]); + +var font = new Font("zh-Hans"); +var song = doc.addCJKFont(font, "zh-Hans", "H", "serif"); +var heiti = doc.addCJKFont(font, "zh-Hans", "H", "sans-serif"); +song.Encoding = 'GBK-EUC-H'; +heiti.Encoding = 'GBK-EUC-H'; + +var MAP = { + "/#CB#CE#CC#E5": song, // SimSun + "/#BA#DA#CC#E5": heiti, // SimHei + "/#BF#AC#CC#E5_GB2312": song, // SimKai + "/#B7#C2#CB#CE_GB2312": heiti, // SimFang + "/#C1#A5#CA#E9": song, // SimLi +} + +var i, n = doc.countPages(); +for (i = 0; i < n; ++i) { + var fonts = doc.findPage(i).Resources.Font; + fonts.forEach(function (name, font) { + if (font.BaseFont in MAP && font.Encoding == 'WinAnsiEncoding') + fonts[name] = MAP[font.BaseFont]; + }); +} + +doc.save(scriptArgs[1]); |