-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