-2
我想从下面的代码返回Document对象。 目前我得到的文件没有页面异常。从PDFStamper返回PDFDocument对象itextsharp
private static Document GeneratePdfAcroFields(PdfReader reader, Document docReturn)
{
if (File.Exists(System.Configuration.ConfigurationSettings.AppSettings["TEMP_PDF"]))
File.Delete(System.Configuration.ConfigurationSettings.AppSettings["TEMP_PDF"]);
PdfStamper stamper = new PdfStamper(reader, new FileStream(System.Configuration.ConfigurationSettings.AppSettings["TEMP_PDF"],FileMode.Create));
AcroFields form = stamper.AcroFields;
///INSERTING TEXT DYNAMICALLY JUST FOR EXAMPLE.
form.SetField("topmostSubform[0].Page16[0].topmostSubform_0_\\.Page78_0_\\.TextField3_9_[0]", "This value was dynamically added.");
stamper.FormFlattening = false;
stamper.Close();
FileStream fsRead = new FileStream(System.Configuration.ConfigurationSettings.AppSettings["TEMP_PDF"], FileMode.Open);
Document docret = new Document(reader.GetPageSizeWithRotation(1));
return docret;
}
你的问题没有任何意义。您正在使用'PdfStamper'来填写填充并可能在现有PDF上添加一些文本。到现在为止还挺好。但为什么你需要一个'Document'实例? 'Document'用于从头开始创建PDF。很明显,您从头创建的文档没有页面。 – 2014-12-07 08:55:19
嗨布鲁诺,感谢您的快速回复。其实我想加载由PDF压缩器创建的文件的实例到Document对象中。我正在使用的Windows应用程序需要一个Document实例,以便最终创建的PDF可以呈现给用户屏幕。我正在使用PDFStamper,因为我的pdf有acroform。早期的函数使用AddTemplate&Imported页面,并且正在返回一个文档,但表单字段在生成后变得平坦(禁用)。请帮忙。 – DevXR 2014-12-07 09:05:15
将文件加载到iText文档对象是不可能的。我不知道任何需要iText'Document'对象将PDF呈现到屏幕的Windows应用程序,因为iText不会进行渲染。我认为你把iText的'Document'类与其他产品搞混了。如果有人使用iText'Document'类来渲染文档,我会感到非常惊讶。这种设计会有严重缺陷。你的应用程序的上下文是什么?它是一个Web应用程序还是桌面应用程序? – 2014-12-07 11:42:04