将字体的子集放入手动创建的 PDF

问题描述 投票:0回答:1

我正在使用文本编辑器创建 PDF(手动编码对象、

xref table
trailer
等)。我想包含现有字体的一个子集,例如字体
ABCD
中的字符
LiberationMono-Bold.ttf
,到这样的PDF中。

PDF

FontDescriptor
对象需要一个
FontFile2
对象。
FontFile2
本身需要以下内容:

  • Length
    (字节)嵌入字体程序
  • Length1
    (字节)字体程序的明文部分
  • stream
    包含字体程序。

如何从 TrueType 字体的子集中提取这些项目?

pdf pdf-generation
1个回答
0
投票

有很多方法可以解决这个问题,但一般来说,你会建立一组字形或拆解一个完整的字体,所以还有一些次要的考虑因素(除了被许可编辑以建立或拆解的字体)。

通常最好建立一小组字形,但最好分解 95% 的子集。

这里有一些关于如何编写小型 PDF 结构的粗略指南,但最好使用库构建二进制字体,然后将其转换为 ascii/ansi 兼容文本。当然,我永远不会尝试手动编写必要的字体规格,因为它是一个高度复杂的组件,因此 4 个字母不太可能是值得的 4 倍。

字体文件很大

Liberation Mono embedding

    bytes filename

3,259,968 ABACADABA-subset.rtf      = an example of TXT saved with a subset Liberation Mono but has tons of other font garbage.  
  197,577 ABACADABA-PDFAsub-set.pdf = A SubSetFont but with all the baggage that comes with PDF/A compliance !
   23,083 ABACADABA.docx            = should have less garbage and smaller as a zip?
    4,382 ABACADABA.odt             = seems to not have the font included just its name ? my error ?
      211 ABACADABA.rtf             = certainly just text and fontname so not embeded

    8,411 LiberationMono.pdf        = Lean BUT still bloated XMP with reduced Liberation Mono as subset binary
    6,536 LiberationMonoBinary.pdf  = cLeaner  Liberation Mono as subset binary
   12,080 LiberationMonoAscii.pdf   = cLeaner  Liberation Mono as subset Ascii

    1,957 Binary_Untitled1Font.pdf  = ABCD Liberation Mono subset untitled as binary
    2,910 Ascii_Untitled1Font.pdf   = ABCD Liberation Mono subset untitled as ascii

所以这是最小的工作文件(Binary_Untitled1Font.pdf)

%PDF-1.4
%µ¶

1 0 obj
<</CreationDate(D:20230427)/CreatorTool( )/ModDate(D:20230427)/Producer( )>>
endobj

2 0 obj
<</Pages 3 0 R/Type/Catalog>>
endobj

3 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj

4 0 obj
<</Contents 5 0 R/MediaBox[0 0 595.2 841.92]/Parent 3 0 R/Resources<</ExtGState<</GS0 6 0 R>>/Font<</F0 7 0 R>>>>/Type/Page>>
endobj

5 0 obj
<</Length 95>>
stream
q
/GS0 gs
1 0 0 1 56.64 752.16 cm
0 g
BT
.039 Tc /F0 12 Tf 0 1.54 Td [(ABACADABA)] TJ
ET
Q
q
Q

endstream
endobj

6 0 obj
<</ca 1/CA 1/Type/ExtGState>>
endobj

7 0 obj
<</BaseFont/EWGWZO+Untitled1/Encoding/WinAnsiEncoding/FirstChar 65/FontDescriptor 8 0 R/LastChar 68/Subtype/TrueType/Type/Font/Widths[1323 1121 1136 1105]>>
endobj

8 0 obj
<</Ascent 800/CapHeight 1349/Descent -200/Flags 32/FontBBox[33 -20 1271 1370]/FontFile2 9 0 R/FontName/EWGWZO+Untitled1/ItalicAngle 0/StemV 0/Type/FontDescriptor>>
endobj

9 0 obj
<</Length1 780/Length 636/Filter/FlateDecode>>
stream
xœeR_HSQÿ}w÷î63Ü27“¨]gÓXù 6+ZxIÈ„9¬4°†ÎFi®’ÚÊ"…b‹‚@!   %Ó’Œ¢zz)êÁ—žúKô ”•g}÷®‡ ïðóý~|ç;ßïœ`Ã2Xìè   Ç°)fÒì5§úÜФǯØåÃ݉®ô³µ8ž(„;×#€TÏœ?ÊDÞ„²Žq?ã²hO_¼ÈJùŒo0^ÓÝÛF†œŒ2¶÷„ã14¢…ñsÆîXïɾìªÏ˜¸/£Ã|Ȩ0zàaàúl–ç€9sà<
¬f¿|œº¨èP±Ð,šÅCÕ6* ŽäÍ——^¤ž’xMKé|}˜^NÐy1¨è?ÈÓå³¢•¾›õt®ááv¬†‡Y¥Z=šCs;8P.'Õ”{}ä¨vÖ«VUë—=©ä‚¨ 4}mØun¬ý€ø²»qøÍ;ÚœÊü¦¼L(Hýw"Š.îŸi–¬lm¥G7UŠCbàD\”n¯c5þ으MiC Phw9«¹n­KÒÜpØ5w¡ê-÷zJU«ØÛ2 †¶^¿&¦ÄñI*¦æ·¼MMÑñPHº-æ“)½þj@\¡#’&Ådàx`çÀ ß¡ËƺòPĪìªu7ïv9-öœC‡mdD¼C´…FGŸëÎvE¥Œ¸7=¥èc7Å]R‰_ß.^‚ù¦ŸÞ÷±ó`AÝ–[>ôÛØàÙÜš|U-²*ð_“3Þ£´eçЦø(/š•þ5•º¡™©{8ן†.Çà—ƒ†Ž¿VŠvaÆÜ­¢ŒßÎ0É<Áàv Òdr<²ÓÆûßþ Bõ®©
endstream
endobj

xref
0 10
0000000000 65536 f 
0000000016 00000 n 
0000000109 00000 n 
0000000155 00000 n 
0000000207 00000 n 
0000000349 00000 n 
0000000493 00000 n 
0000000539 00000 n 
0000000712 00000 n 
0000000892 00000 n 

trailer
<</Size 10/Info 1 0 R/Root 2 0 R/ID[<0D10EC815A3554E2CF8CE7CA6CE7231C><32346E25D4A60D82FEA82C4F8F900EBA>]>>
startxref
1609
%%EOF

这个应该是“WEB SAFE”(Ascii_Untitled1Font.pdf)

%PDF-1.4
%µ¶

1 0 obj
<</CreationDate(D:20230427)/CreatorTool( )/ModDate(D:20230427)/Producer( )>>
endobj

2 0 obj
<</Pages 3 0 R/Type/Catalog>>
endobj

3 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj

4 0 obj
<</Contents 5 0 R/MediaBox[0 0 595.2 841.92]/Parent 3 0 R/Resources<</ExtGState<</GS0 6 0 R>>/Font<</F0 7 0 R>>>>/Type/Page>>
endobj

5 0 obj
<</Length 95>>
stream
q
/GS0 gs
1 0 0 1 56.64 752.16 cm
0 g
BT
.039 Tc
/F0 12 Tf
0 1.54 Td
[(ABACADABA)] TJ
ET
Q
q
Q

endstream
endobj

6 0 obj
<</ca 1/CA 1/Type/ExtGState>>
endobj

7 0 obj
<</BaseFont/EWGWZO+Untitled1/Encoding/WinAnsiEncoding/FirstChar 65/FontDescriptor 8 0 R/LastChar 68/Subtype/TrueType/Type/Font/Widths[1323 1121 1136 1105]>>
endobj

8 0 obj
<</Ascent 800/CapHeight 1349/Descent -200/Flags 32/FontBBox[33 -20 1271 1370]/FontFile2 9 0 R/FontName/EWGWZO+Untitled1/ItalicAngle 0/StemV 0/Type/FontDescriptor>>
endobj

9 0 obj
<</Length1 780/Length 1585/Filter/ASCIIHexDecode>>
stream
000100000009000800030088636d6170005800890000009c0000003463767420
00210279000000d000000004676c79669cc71ebe000000d40000017068656164
251851650000024400000036686865610aad051f0000027c00000024686d7478
1506010c000002a00000001c6c6f636100b00116000002bc000000106d617870
004c0055000002cc00000020706f7374ffb80032000002ec0000002000000001
000300010000000c00040028000000040004000100000044ffff00000041ffff
00000001000400000003000400050006002102790002002b000004f705450007
000d00002103210323013309010f0103210304358afdcd89c401fed901f5fd9c
0c459701cfad017efe820545fabb04b527d4fe5901f400000003004500000423
054500100019002300000114070623211121201114070607161716013427262b
011133201334262b01112132373604238988f5fe28019c01f048477da55e5bfe
ee4b4c97dfe1012c51b2b0fc010ab05351017cb365640545feb97a52511a1259
5901e36b2d2efe60fe817278fe223d3c00010036ffec043a055a001a00001310
17163332373637170221200011102120130726272623220706fe5655b1655153
399e94feb2fef8fee60218015280a8264e4e68aa535302a9feef888945449141
fe8c016a015302b1feb141714142818200020045000004090545000a00150000
0110070629011121201716031027262b01113332373604099a9afee2fe8e0138
0148a2a2c06e6fef78a2d4666802b0feb7b5b20545a5a4feb401077979fbf385
8600000000010000000100007757e4645f0f3cf5000b03e800000000e070827b
00000000e07088bf0021ffec04f7055a00000008000200000000000000010000
055affec005a052b0000000004f7000100000000000000000000000000000007
016c002100000000014d0000052b002b04610045047000360451004500000000
000000000022005e008e00b80001000000070024000300000000000200000001
000100000040002e000000000003000000000000ffb500320000000000000000
000000000000000000000000>
endstream
endobj

xref
0 10
0000000000 00001 f 
0000000016 00000 n 
0000000109 00000 n 
0000000155 00000 n 
0000000207 00000 n 
0000000349 00000 n 
0000000493 00000 n 
0000000539 00000 n 
0000000712 00000 n 
0000000892 00000 n 

trailer
<</Size 10/Info 1 0 R/Root 2 0 R/ID[<0D10EC815A3554E2CF8CE7CA6CE7231C><54E595899FDF1CAFF1E8A2C42A586CF6>]>>
startxref
2562
%%EOF
© www.soinside.com 2019 - 2024. All rights reserved.