【发布时间】:2016-05-07 01:52:18
【问题描述】:
我想使用 iText 将文本标记为 certain pdf。由于此文本可以是西里尔文,因此我使用 unicode 字体和编码。 以下示例代码代表我是如何做到的:
string inputFile = @"sampleStamped.pdf";
PdfReader reader;
PdfStamper stamper;
FileStream fs;
byte[] binaryPdf = File.ReadAllBytes(inputFile);
reader = new PdfReader(binaryPdf);
fs = new FileStream(inputFile, FileMode.Create, FileAccess.Write);
stamper = new PdfStamper(reader, fs);
BaseFont bf = BaseFont.CreateFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
PdfContentByte cb = stamper.GetOverContent(1);
Phrase p = new Phrase();
p.Font = new Font(bf, 25, Font.NORMAL, BaseColor.BLUE);
p.Add("Sample Text");
ColumnText.ShowTextAligned(cb, PdfContentByte.ALIGN_LEFT, p, 200, 200, 0);
if (stamper != null)
stamper.Close();
if (fs != null)
fs.Close();
if (reader != null)
reader.Close();
程序按预期运行,没有错误。但是,如果我想在 Windows 上的 Acrobat Reader 11 或 DC 中打开 stamped pdf,它会说显示内容存在问题,并且没有标记文本。 我使用 itextsharp 5.5.8。
知道如何解决这个问题吗?
谢谢
【问题讨论】:
标签: pdf unicode itextsharp itext acrobat