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

查看:480
本文介绍了我如何嵌入现有的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.

为什么字体没有嵌入时产生的:

我创建PDF的使用SQL Reporting Services的2008年有一个已知的问题SQL Reporting Services中,它不会嵌入字体(除非一系列的要求得到满足 - 的 http://technet.microsoft.com/en-us/library/ms159713%28SQL.100%29.aspx )。不要问我为什么,PDF格式符合所有的MS上市要求和字体仍显示为未嵌入 - 有过的字体是否被嵌入没有真正的控制,所以我接受了,这是不工作,并继续前行。微软的建议的解决方法(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的嵌入到PDF 字体

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

不过,对于我的生活,我似乎无法使用ByteArrayOutputStream对象。它似乎无法找到它。我研究和研究,但似乎没有人说这是什么类或者我觉得这样我就可以将其包含在using语句。我甚至已经裂了开来反射似乎并不能在任何地方找到它。

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.

这是我迄今为止,它编译等等等等
(结果是我的byte []生成的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天全站免登陆