找回密码
 快速注册
搜索
查看: 143|回复: 27

pdf字體去重——全部頁

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2024-2-9 20:17 |阅读模式
使用這帖2楼生成的帶有6種字體的singlepage.pdf
  1. \documentclass{article}
  2. \usepackage{pdfpages,pgffor}
  3. \begin{document}
  4. \includepdf{singlepage.pdf}
  5. \foreach \n in {1,...,313}{\includepdf[pages=\n,fitpaper]{2022-2023.pdf}}
  6. \end{document}
复制代码
運行pdflatex 1.tex
運行python replace.py
運行GS
得到1_modified_compressed.pdf

將2022-2023.pdf從50,229KB减少到了29,528KB
Screenshot 2024-02-09 121609.png
pdffonts結果: $type pdffonts.txt (130.81 KB, 下载次数: 0)
翻到後面看到有一個重複的Tahoma,但Tahoma應該是已經被去重了的,不知為什麼還留著?
  1. MYQGHP+Tahoma-Bold                   CID TrueType      Identity-H       yes yes yes   6408  0
  2. RFOYZW+Tahoma                        CID TrueType      Identity-H       yes yes yes   6400  0
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-9 22:20
hbghlyj 发表于 2024-2-9 12:17
而且,翻到後面看到有一個重複的Tahoma,但Tahoma應該是已經被去重了的,不知為什麼還留著?

检查了,没有問題啊。估計是GS的問題:
把第307,308合併,不會重複;第307,310合併,不會重複;第308,310合併,不會重複.
但把第307,308,310合併,就會重複

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-9 22:31

先用Mutool clean處理,再用GS,可解決此問題

hbghlyj 发表于 2024-2-9 14:20
检查了,没有問題啊。估計是GS的問題:
把第307,308合併,不會重複;第307,310合併,不會重複;第308,310 ...

直接運行GS:可以看到dzicon和Tahoma都重複
Screenshot 2024-02-09 142945.png
mutool clean -gggg再運行GS:可以看到dzicon和Tahoma都只出現一次:
Screenshot 2024-02-09 143121.png

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-9 22:35
本帖最后由 hbghlyj 于 2024-3-2 20:47 编辑
hbghlyj 发表于 2024-2-9 14:31
先mutool clean -gggg再運行GS:可以看到dzicon和Tahoma都只出現一次:

Screenshot 2024-02-09 143529.png
使用此方法,文件减到了29,509KB(1楼直接GS是29,528KB)
運行pax恢復鏈接,增加到31,380KB
但pdffonts發現,還是有零星的幾個重複的Tahoma

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-9 23:03
Consolas也重複了,若要進一步减小文件,可以在singlepage.py添加page.insert_text((50, 50), "Hello, World!", fontname="Consolas",fontfile = r"C:\Windows\Fonts\consola.ttf"),並在replace.py的第一個for中添加Consolas.ttf

而且上面只去重了MathJax_Math-Italic,若要進一步减小文件,剩下的MathJax字體還能去重

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-2-10 00:50
30M 左右就比较符合预期了

2020-2021 版就是差不多这大小

点评

猜測SimSun重複佔的空間最大  发表于 2024-2-10 01:01

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-2-10 01:04
明天如果有空,我试一下将论坛的 mathjax 改回 2.7,再按原先的方式重新保存一部分帖子合并+Adobe优化看会如何。

点评

可以採用 HTML=>Epub 製作電子書(epub格式本质上就是一个压缩包,将HTML(主要是存储文字)和图片等按照一定的规律压缩在一起。)  发表于 2024-2-10 02:40

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-10 01:21
kuing 发表于 2024-2-9 17:04
明天如果有空,我试一下将论坛的 mathjax 改回 2.7,再按原先的方式重新保存一部分帖子合并+Adobe优化看会 ...


可以加URL参數,?mathjax=2.7 就加載2.7,默認的不變

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-10 01:29
忽然想到,只修改CSS @font-face即可。使用舊的otf字體。
cdn.jsdelivr.net/npm/mathjax@2.7.9/fonts/HTML-CSS/TeX/otf/

3

主题

452

回帖

6188

积分

积分
6188
QQ

显示全部楼层

爪机专用 发表于 2024-2-10 09:21
忽然想到,能否加插一个目录页?
(虽然目前有书签,但公式是代码
I am majia of kuing

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-10 20:25
爪机专用 发表于 2024-2-10 01:21
忽然想到,能否加插一个目录页?
(虽然目前有书签,但公式是代码

可能相關:zhmakeindex 是一个通用的中文多级索引处理程序,它从一个或多个输入文件读入索引项

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-11 01:03
爪机专用 发表于 2024-2-10 01:21
(虽然目前有书签,但公式是代码


hyperref
Some postprocessing of the bookmark file (file extension .out) may be needed to translate $\LaTeX$ codes, since bookmarks must be written in PDFEncoding. To aid this process, the .out file is not rewritten by $\LaTeX$ if it is edited to contain a line \let\WriteBookmarks\relax

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-11 01:31
爪机专用 发表于 2024-2-10 01:21
(虽然目前有书签,但公式是代码


hyperref
6.1 Bookmark macros
6.1.1 Setting bookmarks
Usually hyperref automatically adds bookmarks for \section and similar macros. But they can also set manually.
\pdfbookmark[level]{text}{name}
creates a bookmark with the specified text and at the given level (default is 0). As name for the internal anchor name is used (in conjunction with level). Therefore the name must be unique (similar to \label).

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-11 01:34
hyperref文檔裡的
\texorpdfstring{TEXstring}{PDFstring}
For example,
\section{Pythagoras:
  \texorpdfstring{\$ a^2 + b^2 = c^2 \$}{%
    a\texttwosuperior\ + b\texttwosuperior\ =
    c\texttwosuperior
  }%
}

這裡的\texttwosuperior是什麼,文檔中好像没寫?

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-2-11 02:07
hbghlyj 发表于 2024-2-10 01:29
忽然想到,只修改CSS 即可。使用舊的otf字體。
https://cdn.jsdelivr.net/npm/mathjax@2.7.9/fonts/HTML-CS ...

具体怎么做啊

点评

可以寫個Greasymonkey腳本,等待MathJax注入CSS?  发表于 2024-2-11 02:14

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-11 02:11

像在這帖測試的:
  1. @font-face /* 3 */ {
  2.   font-family: MJXTEX-I;
  3.   src: url("https://cdn.jsdelivr.net/npm/mathjax@2.7.9/fonts/HTML-CSS/TeX/otf/MathJax_Math-Italic.otf");
  4. }
复制代码

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-2-11 03:03
hbghlyj 发表于 2024-2-11 02:11
像在這帖測試的:

把这些全替换掉吗?
  1. @font-face /* 0 */ {
  2.   font-family: MJXZERO;
  3.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Zero.woff") format("woff");
  4. }
  5. @font-face /* 1 */ {
  6.   font-family: MJXTEX;
  7.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Main-Regular.woff") format("woff");
  8. }
  9. @font-face /* 2 */ {
  10.   font-family: MJXTEX-B;
  11.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Main-Bold.woff") format("woff");
  12. }
  13. @font-face /* 3 */ {
  14.   font-family: MJXTEX-I;
  15.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Math-Italic.woff") format("woff");
  16. }
  17. @font-face /* 4 */ {
  18.   font-family: MJXTEX-MI;
  19.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Main-Italic.woff") format("woff");
  20. }
  21. @font-face /* 5 */ {
  22.   font-family: MJXTEX-BI;
  23.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Math-BoldItalic.woff") format("woff");
  24. }
  25. @font-face /* 6 */ {
  26.   font-family: MJXTEX-S1;
  27.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Size1-Regular.woff") format("woff");
  28. }
  29. @font-face /* 7 */ {
  30.   font-family: MJXTEX-S2;
  31.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Size2-Regular.woff") format("woff");
  32. }
  33. @font-face /* 8 */ {
  34.   font-family: MJXTEX-S3;
  35.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Size3-Regular.woff") format("woff");
  36. }
  37. @font-face /* 9 */ {
  38.   font-family: MJXTEX-S4;
  39.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Size4-Regular.woff") format("woff");
  40. }
  41. @font-face /* 10 */ {
  42.   font-family: MJXTEX-A;
  43.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_AMS-Regular.woff") format("woff");
  44. }
  45. @font-face /* 11 */ {
  46.   font-family: MJXTEX-C;
  47.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Calligraphic-Regular.woff") format("woff");
  48. }
  49. @font-face /* 12 */ {
  50.   font-family: MJXTEX-CB;
  51.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Calligraphic-Bold.woff") format("woff");
  52. }
  53. @font-face /* 13 */ {
  54.   font-family: MJXTEX-FR;
  55.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Fraktur-Regular.woff") format("woff");
  56. }
  57. @font-face /* 14 */ {
  58.   font-family: MJXTEX-FRB;
  59.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Fraktur-Bold.woff") format("woff");
  60. }
  61. @font-face /* 15 */ {
  62.   font-family: MJXTEX-SS;
  63.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_SansSerif-Regular.woff") format("woff");
  64. }
  65. @font-face /* 16 */ {
  66.   font-family: MJXTEX-SSB;
  67.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_SansSerif-Bold.woff") format("woff");
  68. }
  69. @font-face /* 17 */ {
  70.   font-family: MJXTEX-SSI;
  71.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_SansSerif-Italic.woff") format("woff");
  72. }
  73. @font-face /* 18 */ {
  74.   font-family: MJXTEX-SC;
  75.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Script-Regular.woff") format("woff");
  76. }
  77. @font-face /* 19 */ {
  78.   font-family: MJXTEX-T;
  79.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Typewriter-Regular.woff") format("woff");
  80. }
  81. @font-face /* 20 */ {
  82.   font-family: MJXTEX-V;
  83.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Vector-Regular.woff") format("woff");
  84. }
  85. @font-face /* 21 */ {
  86.   font-family: MJXTEX-VB;
  87.   src: url("https://kuing.cjhb.site/mathjax3/es5/output/chtml/fonts/woff-v2/MathJax_Vector-Bold.woff") format("woff");
  88. }
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-11 03:24
kuing 发表于 2024-2-10 19:03
把这些全替换掉吗?

v3加入的CSS能否全部替换成v2加入的CSS

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-11 06:04
hbghlyj 发表于 2024-2-10 17:34
hyperref文檔裡的
這裡的\texttwosuperior是什麼,文檔中好像没寫?


找到了:textcomp Commands包含\texttwosuperior
Screenshot 2024-02-10 220416.png

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-2-11 18:14
本帖最后由 kuing 于 2024-2-11 18:51 编辑
hbghlyj 发表于 2024-2-11 03:24
v3加入的CSS能否全部替换成v2加入的CSS


应该不行,font-family 的名称全都不一样,只能修改 v3 的那些 url。

现在得知道
cdn.jsdelivr.net/npm/mathjax@3.0.0/es5/output/chtml/fonts/woff-v2/

cdn.jsdelivr.net/npm/mathjax@2.7.9/fonts/HTML-CSS/TeX/otf/
这两套字体的对应关系才行。

比如 v3 的 MathJax_Zero.woff 我就不知道对应于 v2 的哪个 otf

看第二、三行的
v2 的 MathJax_Caligraphic-Bold.otf 与 v3 的 MathJax_Calligraphic-Bold.woff
不仅后缀不同,名字其实也是不同的,不仔细看都不会注意到后者多一个字母 `l`

v2 有 MathJax_WinChrome-Regular.otf 和 MathJax_WinIE6-Regular.otf
v3 有 MathJax_Zero.woff

除了上述之外,其他应该都一样。

看来 woff 确实比 otf 体积要小。

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 12:01

Powered by Discuz!

× 快速回复 返回顶部 返回列表