【发布时间】:2012-05-13 17:52:47
【问题描述】:
我在使用 iText 时遇到了一些问题。 (特别是 iTextSharp。)我正在尝试将一个大的 PDF 文件拆分成一堆较小的文件。那不是问题。行得通。
我发现输入 PDF 文件中的一些字体(只有一个;其余的仍然嵌入得很好。)虽然它们嵌入在输入 PDF 文件中,但不再嵌入在输出中PDF 文件,尽管是用 iText 复制的。
这最终会导致一个可读的输出 PDF 文件,当在 Adobe Reader 中打开时,会出现错误:“字体 'ZurichBT-BoldItalic' 包含错误的 /BBOX。”。原始输入文件没有问题。
我真的不明白为什么。
下面是一个测试用例应用程序,它将简单地复制输入 PDF。我无法提供我自己的输入 PDF 的样本,因为它包含机密信息,但如果不能纯粹用代码回答,我很快就会看到用一个小而简单的文件复制它。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
static void Main(string[] args)
{
PdfReader reader = new PdfReader("input.pdf");
Document doc = new Document();
PdfSmartCopy writer = new PdfSmartCopy(doc, new FileStream("output.pdf", fileMode.OpenOrCreate, FileAccess.Write));
doc.Open();
for (int i = 1; i <= reader.NumberOfPages; i++)
{
//byte[] page = reader.GetPageContent(i);
//string data = ExtractTextFromPDFBytes(page);
if (true)//data.Contains("Search Token"))
{
doc.SetPageSize(reader.GetPageSizeWithRotation(i));
doc.NewPage();
PdfImportedPage iPage = writer.GetImportedPage(reader, i);
writer.AddPage(iPage);
}
}
doc.Close();
}
有什么想法吗? :)
编辑更多信息
在获得了我正在使用的输入 pdf 的另一个副本后,问题似乎出在输入 pdf 上,尽管原始输入 pdf 没有被 Adobe Reader 检测到的错误。我无法分享确切的文件,这使得这很困难,但我想知道是否有人对这怎么可能有任何理论?文件损坏或错误在源 pdf 中不明显,在通过 iText 的 pdfCopy 或 pdfSmartCopy 函数运行后在输出 pdf 中变得明显?
【问题讨论】:
-
您好,我复制您的代码以尝试使用我的 PDF,即 PDF/A-1B。没关系。
标签: c# pdf fonts itextsharp itext