如何在现有 PDF 中嵌入字体? [英] How do I embed fonts in an existing PDF?

查看:36
本文介绍了如何在现有 PDF 中嵌入字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我有以编程方式生成的 PDF.我需要能够将 PDF 直接从服务器发送到打印机(而不是通过中间应用程序).目前我可以执行上述所有操作(生成 PDF,发送到打印机),但由于字体未嵌入 PDF 中,因此打印机正在进行字体替换.

I have PDF's I am programmatically generating. I need to be able to send the PDF directly to a printer from the server (not through an intermediate application). At the moment I can do all of the above (generate PDF, send to printer), but because the fonts aren't embedded in the PDF the printer is doing font substitution.

为什么字体在生成时没有嵌入:

我正在使用 SQL Reporting Services 2008 创建 PDF.SQL Reporting Services 存在一个已知问题,即它不会嵌入字体(除非满足一系列要求 - http://technet.microsoft.com/en-us/library/ms159713%28SQL.100%29.aspx).不要问我为什么,PDF 满足 MS 列出的所有要求,并且字体仍然显示为未嵌入 - 无法真正控制是否嵌入字体,所以我接受了这不起作用并继续前进.Microsoft 建议的解决方法 (http://blogs.msdn.com/b/donovans/archive/2007/07/20/reporting-services-pdf-renderer-faq.aspx 在报告服务何时进行字体嵌入"下)是对 PDF 进行后期处理以手动嵌入字体.

I am creating PDF's using SQL Reporting Services 2008. There is a known issue with SQL Reporting Services in that it will not embed fonts (unless a series of requirements are met - http://technet.microsoft.com/en-us/library/ms159713%28SQL.100%29.aspx). Don't ask me why, the PDF meets all of MS's listed requirements and the fonts still show up as not embedded - there is no real control over whether the fonts are embedded, so I have accepted that this isn't working and moved on. The suggested workaround from Microsoft (http://blogs.msdn.com/b/donovans/archive/2007/07/20/reporting-services-pdf-renderer-faq.aspx under 'When will Reporting Services do font embedding') is to post process the PDF to manually embed the fonts.

目标取一个已经生成的 PDF 文档,以编程方式打开"它并嵌入字体,重新保存 PDF.

Goal Take an already generated PDF document, programmatically 'open' it and embed the fonts, resave the PDF.

方法我被指向 iTextSharp,但大多数示例都是针对 Java 版本的,我在翻译到 iTextSharp 版本时遇到了麻烦(我找不到 iTextSharp 的任何文档).

Approach I was pointed towards iTextSharp, but most of the examples are for the Java version and I'm having trouble translating to the iTextSharp version (I can't find any documentation for iTextSharp).

我正在写这篇文章,我需要做的是:Itext embed font in一个 PDF.

I am working on this post for what I need to do: Itext embed font in a PDF.

然而,在我的一生中,我似乎无法使用 ByteArrayOutputStream 对象.它似乎无法找到它.我已经研究和研究过,但似乎没有人说它在哪个类中或我在哪里找到它,因此我可以将它包含在 using 语句中.我什至打开了 Reflector,但似乎在任何地方都找不到.

However for the life of me, I cannot seem to use the ByteArrayOutputStream object. It can't seem to find it. I've researched and researched but nobody seems to say what class it's in or where I find it so I can include it in the using statements. I've even cracked open Reflector and can't seem to find it anywhere.

这是我到目前为止所拥有的,它可以编译等等.(结果是生成的 PDF 的我的字节 []).

This is what I have so far and it compiles etc. etc. (result is my byte[] of the generated PDF).

PdfReader pdf = new PdfReader(result);            
BaseFont unicode = BaseFont.CreateFont("Georgia", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
// the next line doesn't work as I need a ByteArrayOutputStream variable to pass in
PdfStamper stamper = new PdfStamper(pdf, MISSINGBYTEARRAYOUTPUTSTREAMVARIABLE);
stamper.AcroFields.SetFieldProperty("test", "textfont", unicode, null); 
stamper.Close();
pdf.Close();

那么任何人都可以帮助我使用 iTextSharp 将字体嵌入到 PDF 中或为我指明正确的方向吗?

So can anybody either help me with using iTextSharp to embed fonts into a PDF or point me in the right direction?

我非常乐意使用 iTextSharp 以外的任何其他解决方案来完成这个目标,但它需要免费并且能够被企业用于内部应用程序(即 Affero GPL).

I'm more than happy to use any other solutions other than iTextSharp to complete this goal, but it needs to be free and able to be used by a business for an internal application (i.e. Affero GPL).

推荐答案

这可能不是您要寻找的答案(因为您希望以编程方式解决问题,而不是通过外部工具).

This may not be the answer you are looking for (since you want to get your problems solved programmatically, not by an external tool).

但是您可以使用 Ghostscript 命令行将丢失的字体嵌入到没有嵌入它们的 PDF 中:

But you can use Ghostscript commandline to embed missing fonts in retrospect to PDFs which have not embedded them:

gs 
  -sFONTPATH=/path/to/fonts:/another/dir/with/more/fonts 
  -o output-pdf-with-embedded-fonts.pdf 
  -sDEVICE=pdfwrite 
  -dPDFSETTINGS=/prepress 
   input-pdf-where-some-fonts-are-not-embedded.pdf

一件重要的事情是缺少的字体都可以在 -sFontPath=... 开关指向的目录之一中找到.

One important thing is that the missing fonts are all available in one of the directories pointed to by the -sFontPath=... switch.

这篇关于如何在现有 PDF 中嵌入字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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