Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从PDFStamper itextsharp返回PDFDocument对象_Pdf_Itextsharp_Itext - Fatal编程技术网

从PDFStamper itextsharp返回PDFDocument对象

从PDFStamper itextsharp返回PDFDocument对象,pdf,itextsharp,itext,Pdf,Itextsharp,Itext,我想从下面的代码中返回文档对象。 目前我得到的一份文件没有页面例外 private static Document GeneratePdfAcroFields(PdfReader reader, Document docReturn) { if (File.Exists(System.Configuration.ConfigurationSettings.AppSettings["TEMP_PDF"])) File.Delete(System.

我想从下面的代码中返回文档对象。 目前我得到的一份文件没有页面例外

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;
    }
谢谢你,克里斯


只是重申一下@BrunoLowagie所说的,传递文档对象几乎没有意义。不管名称听起来如何,文档都不能以任何方式表示PDF。调用>ToString()或GetBytes()(如果该方法确实存在)不会得到PDF。文档只是一个>单向漏斗,用于将人性化的命令传递给实际编写原始PDF>标记的引擎。然而,该引擎甚至不是PDF。真正的PDF格式是正在写入的流的原始>字节克里斯·哈斯


你的问题没有真正意义。您使用的是
PdfStamper
来填充,可能还可以在现有的PDF上标记一些文本。到目前为止,一切顺利。但是为什么需要
文档
实例呢<代码>文档用于从头开始创建PDF。很明显,你从头开始创建的文档没有页面。你好,布鲁诺,谢谢你的快速回复。实际上,我想将PDF Stamp创建的文件实例加载到Document对象中。我正在使用的windows应用程序需要一个文档实例,以便最终创建的pdf可以呈现到用户屏幕上。我使用PDFStamper作为我的pdf格式。以前的函数使用AddTemplate&Imported page并返回文档,但表单字段在生成后变平(禁用)。请提供帮助。无法将文件加载到iText
文档
对象中。我不知道任何Windows应用程序需要iText
文档
对象才能将PDF呈现到屏幕上,因为iText不进行渲染。我认为您将iText
文档
类与其他产品混淆了。如果有人使用iText
Document
类来呈现文档,我会非常惊讶。这种设计将有严重缺陷。应用程序的上下文是什么?它是web应用程序还是桌面应用程序?不,Bruno,itext不用于呈现pdf,pdf通过简单的c#从目录中打开文件来呈现。它是一个桌面应用程序。我正在使用itext向acroforms pdf文档添加一些内容,然后将文档保存在新位置。然而,acro场变得平坦。让我试试你所指的代码:使用iText的注释只是为了重申@BrunoLowagie所说的,传递
Document
对象几乎毫无意义。不管名称听起来如何,
文档
在任何方面都不能表示PDF。调用
ToString()
GetBytes()
(如果该方法确实存在)不会得到PDF。
文档
只是一个单向漏斗,用于将人性化的命令传递给实际编写原始PDF标记的引擎。然而,该引擎甚至不是PDF。真正的PDF是正在写入的流的原始字节。