使用某个实用程序或脚本将嵌入式PDF字体提取到外部ttf文件 [英] Extract embedded PDF fonts to an external ttf file using some utility or script

查看:190
本文介绍了使用某个实用程序或脚本将嵌入式PDF字体提取到外部ttf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用某个实用程序或脚本将PDF文件中嵌入的字体提取到外部ttf文件?


  1. p>如果嵌入(或未嵌入)到PDF文件的字体出现在系统中。使用swftools中的pdf2swf和swfextract工具,我可以确定PDF文件中使用的字体的名称。然后,我可以在运行时编译相应的系统字体,然后加载到我的AIR应用程序。
  2. 但是如果PDF中使用的字体不存在在系统中有两种可能:

    2.1。如果他们不在PDF文件中(不嵌入),我们只能使用基于字体名称的类似系统字体。



    2.2。如果它们被嵌入到PDF文件中,那么我想知道是否有可能将它们提取到外部ttf文件,以便我可以在运行时将它们中的每一个编译成独立的swf文件?



解决方案

我知道这是一段时间,因为你问这个,但我想我可以帮忙。

我不知道是否有任何实用工具可以让你提取字体文件,但你可以手动完成。



基本上PDF文件是具有不同对象的文本文件。您可以使用任何文本编辑器打开它并查找字体。

字体在FontDescriptor对象中指定,例如:


$ b $


基本上,对象24上指定了一个名字为Algerian的字体。文件中的对象24的行是24 0 obj,在这行之后,它显示了带有字体文件的流的属性,并在stream关键字开始之后(它的长度在obj之后的行中定义) 。

这个流包含了ttf文件,压缩后解压缩就可以使用这个方法:

$ $ $ private byte byte [] DecodeFlateDecodeData(byte [] data)
{
MemoryStream outputStream;
using(outputStream = new MemoryStream())
{
using(var compressedDataStream = new MemoryStream(data))
{
//将前两个字节移除跳过标题(它不被DeflateStream类识别)
compressedDataStream.ReadByte();
compressedDataStream.ReadByte();

var deflateStream = new DeflateStream(compressedDataStream,CompressionMode.Decompress,true);

var decompressedBuffer =新字节[1024];
int读取;
while((read = deflateStream.Read(decompressedBuffer,0,decompressedBuffer.Length))!= 0)
{
outputStream.Write(decompressedBuffer,0,read);
}
outputStream.Flush();
compressedDataStream.Close();
}
return GetStreamBytes(outputStream);




$ b $ p
$ b我希望这可以帮助你...或帮助某人其他


Is it possible to extract fonts that are embedded in a PDF file to an external ttf file using some utility or script?

  1. If the fonts that are embedded (or not embedded) to a PDF file are present in system. Using pdf2swf and swfextract tools from swftools I am able to determine names of the fonts used in a PDF file. Then I can compile respective system font(s) at run-time and then load to my AIR application.

  2. BUT if the fonts used in the PDF are absent in the system there are two possibilities:

    2.1. If they are absent in the PDF files as well (not embedded), we can only use similar system font basing on the font name.

    2.2. If they are embedded in the PDF file, then I want to know is it possible at all to extract them to external ttf file so that I can compile each of them to separate swf files at run-time?

解决方案

I know it's been a while since you asked this, but I figured I might be able to help.

I don't know if there is any utility that will allow you to extract the Font files, but you can do it manually.

Basically a PDF file is a text file with different objects. You can open it with any text editor and look for the fonts.

The fonts are specified in FontDescriptor objects, e.g:

<</Type/FontDescriptor/FontName/ABCDEE+Algerian ... /FontFile2 24 0 R>>

This basically says, a font with the name Algerian is specified on the object 24. You can search the document for the object 24 with the line "24 0 obj", after this line, it displays the properties of the stream with the font file and after the "stream" keyword it starts (its length is defined in the line after the obj).

This stream contains the ttf file, compressed, to decompress it you can use this method:

  private static byte[] DecodeFlateDecodeData(byte[] data)
  {
     MemoryStream outputStream;
     using (outputStream = new MemoryStream())
     {
        using (var compressedDataStream = new MemoryStream(data))
        {
           // Remove the first two bytes to skip the header (it isn't recognized by the DeflateStream class)
           compressedDataStream.ReadByte();
           compressedDataStream.ReadByte();

           var deflateStream = new DeflateStream(compressedDataStream, CompressionMode.Decompress, true);

           var decompressedBuffer = new byte[1024];
           int read;
           while ((read = deflateStream.Read(decompressedBuffer, 0, decompressedBuffer.Length)) != 0)
           {
              outputStream.Write(decompressedBuffer, 0, read);
           }
           outputStream.Flush();
           compressedDataStream.Close();
        }
        return GetStreamBytes(outputStream);
     }
  }

I hope this helps you... or helps somebody else

这篇关于使用某个实用程序或脚本将嵌入式PDF字体提取到外部ttf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆