|
本帖最后由 hbghlyj 于 2023-7-1 03:06 编辑
修改~(CID: 001f)- import fitz
- doc = fitz.open("waiweifen.pdf")
- page = doc[7]
- xref = page.get_contents()[0]
- def get_key(xref,key):
- return int(doc.xref_get_key(xref,key)[1].split()[0].replace("[", ""))
- doc.update_stream(xref,doc.xref_stream(xref).replace(b"0066>-332<0048",b"0066001f0048"))
- Resources = get_key(page.xref,"Resources")
- doc.update_object(Resources, doc.xref_object(Resources).replace(" /F9 12 0 R\n",""))
- page.insert_font("F9",fontfile="D:/MiKTeX/fonts/opentype/public/lm/lmroman10-regular.otf")
- ### For debugging:
- # print(doc.xref_stream(page.get_contents()[0]).decode())
- # print(doc.xref_object(Resources))
- doc.subset_fonts()
- doc.save("output.pdf", garbage=4, deflate=True, clean=True)
复制代码
效果:
链接正常了。 |
|
原文件1.4MB,没有加doc.subset_fonts()时输出文件尺寸为1.5MB(因为嵌入了整个LMRoman10字体),加上doc.subset_fonts()就变成1.4MB(文件尺寸不会增加很多,因为在字体中只加了1个字符~)
第9行在Resource中把F9的引用删了,然后第10行插入lmroman10-regular.otf并命名为F9。
若去掉第9行,第10行的insert_font就无效,因为insert_font时新字体名不能与已有的字体名相同。 |
|