找回密码
 快速注册
搜索
查看: 121|回复: 36

[pdftex] Merging duplicate embedded fonts

[复制链接]

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2024-2-6 20:43 |阅读模式
用pdfpages的\includepdf嵌入其它PDF時,會把被嵌入的PDF所含的字體原封不動全部引入,即使它與當前的PDF使用了相同的字體,導致重複引入:(下圖有多個CMR10)
Screenshot 2024-02-06 125040.png
用Adobe Acrobat Pro處理後,重複的字體被合併了:
下圖[11 0 R]和[17 0 R]和合併為[28 0 R]

the fonts are TrueType. pdftex can only "merge" Type1 (and Type1C)  fonts.

這裡說pdfTeX可以合併Type1字體?不知是怎樣操作的?上面的就是Type1,但没看到合併啊?

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-6 20:47
這裡說,因為要從字體取出glyph,太複雜,不建議用itext7來做

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-6 20:48
這裡說,Adobe可以合併PDF中的同一字體的不同子集。

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-6 20:49
這裡說,GS也可以合併PDF中的同一字體的不同子集。
In many cases Ghostscript will be able to merge the many subsetted fonts into fewer ones.

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-2-6 22:38
我最近弄的
《kuing网络撸题集》(2022~2023懒人版)
可能也存在字体重复的问题,你可否帮我瞧瞧。

注:
懒人版撸题集 PDF 的制作方法是先从网页一个个保存 PDF 然后用“PDF补丁丁”合并起来的。
前年弄 2020~2021 版时,我记得在合并完后再用 Adobe Acrobat 的“PDF 优化器”处理一下(只处理字体),就能把体积减少1/3以上。
但这次用同样的方法却没有减少,导致这次的 PDF 很大。

2020~2021:
QQ截图20240206223119.png
2022~2023:
QQ截图20240206223349.png

主要就是字体那里大了。

点评

4#說Ghostscript可以,試一下?  发表于 2024-2-7 01:26

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-6 23:52
kuing 发表于 2024-2-6 14:38
我记得在合并完后再用 Adobe Acrobat 的“PDF 优化器”处理一下(只处理字体),就能把体积减少1/3以上。


您的 Adobe Acrobat Pro 是哪裡下載的呀?我也想弄一個

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-2-7 00:01
hbghlyj 发表于 2024-2-6 23:52
您的 Adobe Acrobat Pro 是哪裡下載的呀?我也想弄一個

好多年前下的绿色版了……

竟然还能找到下载链接:pan.baidu.com/s/194okO

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 01:44
$type 1.txt (249.56 KB, 下载次数: 2)
Screenshot 2024-02-06 174247.png

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-2-7 01:48
点评 hbghlyj  4#說Ghostscript可以,試一下?  发表于 2024-2-7 01:26

我不会,你弄一下吧,如果成功就发给我

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 02:42
kuing 发表于 2024-2-6 17:48
我不会,你弄一下吧,如果成功就发给我

我也不會弄只是搜到4#鏈接,說Ghostscript可以。
在4#鏈接中,他說,為了使每頁使用字符的範圍相同,要這樣操作:
Since your source files are Excel sheets made from templates (which usually don't use a lot of different fonts), you could try to use a trick to make sure Ghostscript has all the required glyphs of the fonts used in all to-be-merged-later PDFs:

    For each font and face (standard, italic, bold, bold-italic) add a table cell into your template sheet at the top left of your print area.
    Fill this table cell with all printable characters and punctuation signs from the ASCII alphabet: 0123456789, ABCD...XYZ, abc...xyz, :-_;°%&$§")({}[] etc.
    Make the cell (and the fontsize) as small as you want or need in order to not disturb your overall layout. Use the color white to format the characters in the cell (so they appear invisible in the final PDF).

This method will hopefully make sure that each of your PDFs will use the same subset of glyphs which would then avoid the problems you observed when merging the files with Ghostscript. (Note, that you if you use f.e. Arial and Arial-Italic, you have to create 2 such cells: one formatted with the standard Arial typeface, the other one with the italic one.)

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 02:44
推測應該是包含一個完整的字體,然後用它替换掉所有的子集字體。
替换字體的方法:Substitute a font in a PDF document

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 03:06
hbghlyj 发表于 2024-2-6 12:43
這裡說pdfTeX可以合併Type1字體?不知是怎樣操作的?上面的就是Type1,但没看到合併啊?

(其實1#想問的是:如何測試pdfTeX可以合併Type1字體?)

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 07:14
找到了:texdoc.org/serve/pdftex-a.pdf/0
...Type 1 glyphs can be shared between several embedded pdf files and with text that is typeset by pdfTEX, which helps keeping the resulting pdf file size small, if many files with similar Type 1(C) fonts are embedded

Screenshot 2024-02-06 231237.png

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 09:07
使用stackoverflow.com/questions/10626977/
  1. gswin32c.exe ^
  2.     -o output.pdf ^
  3.     -sDEVICE=pdfwrite ^
  4.     -dPDFSETTINGS=/prepress ^
  5.      input.pdf
复制代码

處理2022-2023.pdf的第3-5頁:
$type 3-5 - Copy.pdf (1.07 MB, 下载次数: 2)
$type output.pdf (860.85 KB, 下载次数: 2)
發現字體没有减少,但是文件大小减少了。
@kuing 看一下PDF有没有變化?我看鏈接都還在。

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 09:31
嘗試提取字體出來,放到extractpdf.com/,没有提取出任何字體!
又按照stackoverflow.com/questions/3488042/ 所述:下載extractFonts.ps並执行:
  1. gswin64c.exe -q -dNODISPLAY -dNOSAFER extractFonts.ps -c "(345.pdf) extractFonts quit"
复制代码

也没有提取出任何字體!

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-2-7 14:01
本帖最后由 kuing 于 2024-2-7 14:19 编辑

按这方法我尝试处理整个文档,出来才少了 4M。
运行时有不少页面出现警告信息,打开生成的 PDF,有些页面丢字,如第 8 页。

不知是我下载的 gswin32c.exe 有问题还是版本问题?你在你那边试一下如何?

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 16:09
kuing 发表于 2024-2-7 06:01
出来才少了 4M。


說明這辦法不能去除重複字體啊需要另找辦法呢

点评

你也试过了吗?  发表于 2024-2-7 16:24

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 16:41
Fonts.PNG
Adobe的PDF optimizer有一個按鈕fonts to unembed去除字體。可以把Tahoma都去掉

点评

你用 7# 那个试一下再说  发表于 2024-2-7 16:58

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 17:00
LaTeX2ε font selection - fntguide.pdf有font substitution替换字體
Screenshot 2024-02-07 090002.png
\DeclareFontSubstitution {⟨encoding⟩} {⟨family⟩} {⟨series⟩} {⟨shape⟩}
Declares the default values for font substitution which will be used when a font
with encoding ⟨encoding⟩ should be loaded but no font can be found with the
current attributes.

3149

主题

8386

回帖

6万

积分

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

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2024-2-7 17:19
texfaq.org/FAQ-pdf-fig-chars
pdfTeX does this to keep file sizes down: suppose you have a document that loads figures fig1.pdf and fig2.pdf; both of those use font font.pfb. If pdfTeX takes no action, there will be two copies of font.pfb in the output. (If your document also uses the font, there could be three copies.)
pdfTeX默認就可以合併字體

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

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

Powered by Discuz!

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