Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
丢失使用itext添加到pdf中的javascript_Pdf_Itext - Fatal编程技术网

丢失使用itext添加到pdf中的javascript

丢失使用itext添加到pdf中的javascript,pdf,itext,Pdf,Itext,我试图使用itext将javascript添加到pdf中,然后将其与另一个pdf合并。 但是最终合并的pdf不包含javascript。如果pdf没有与另一个pdf合并,javascript工作正常 合并代码: FileOutputStream sectionR=新的FileOutputStream(结果) 我试图将JS添加到合并后的pdf中,但它没有这样做。我想它是不可编辑的 下面是将JS添加到尚未合并的pdf的代码。 FileOutputStream section1Pdf = new Fi

我试图使用itext将javascript添加到pdf中,然后将其与另一个pdf合并。 但是最终合并的pdf不包含javascript。如果pdf没有与另一个pdf合并,javascript工作正常

合并代码: FileOutputStream sectionR=新的FileOutputStream(结果)

我试图将JS添加到合并后的pdf中,但它没有这样做。我想它是不可编辑的

下面是将JS添加到尚未合并的pdf的代码。

FileOutputStream section1Pdf = new FileOutputStream("newPDFSection");

PdfReader readerSection1 = new PdfReader("Existing PDF - Section 1");

PdfStamper stamperSection1 = new PdfStamper(readerSection1,section1Pdf);

stamperSection1.addJavaScript(
"var nameField = this.getField('txtOwnerCity');" +              "nameField.setAction('Keystroke'," +"'forceUpperCase()');" +
      "" +"function forceUpperCase(){" +
"if(!event.willCommit)event.change = " +
"event.change.toUpperCase();" +
"}");
当我尝试将JS添加到合并后的pdf时,它不允许我说它不再可编辑

这就是我试图添加的内容

FileOutputStream sectionR = new FileOutputStream(RESULT);

            PdfCopyFields copier = new PdfCopyFields(sectionR);


            for (String curInPath : listFile) {

                PdfReader reader = new PdfReader(curInPath);
                copier.addDocument(reader);             
}
copier.close();

PdfReader readersectionResult = new PdfReader("result.pdf");

PdfStamper stamper = new PdfStamper(readersectionResult, new FileOutputStream("newResult.pdf"));

stamper.addJavaScript(some JS);
我收到的错误是“警告:无法设置标题”。已作出答复。”

我不确定我是否在上面做得对,我所要做的就是让生成的pdf的pdfstamper添加新的JS

当我试图编辑表单字段值时,它会显示“不再可编辑”。

FileOutputStream section1Pdf = new FileOutputStream("newPDFSection");

PdfReader readerSection1 = new PdfReader("Existing PDF - Section 1");

PdfStamper stamperSection1 = new PdfStamper(readerSection1,section1Pdf);

stamperSection1.addJavaScript(
"var nameField = this.getField('txtOwnerCity');" +              "nameField.setAction('Keystroke'," +"'forceUpperCase()');" +
      "" +"function forceUpperCase(){" +
"if(!event.willCommit)event.change = " +
"event.change.toUpperCase();" +
"}");
AcroFields acro=stamper.getAcroFields()


acro.setField(“txtOfficerName”+officechar,officerSO.getFullName())

请提供合并代码和示例文档。许多人在网上使用iText合并文档时发现了错误的示例代码,这会丢失很多信息。此外,文档级JS代码可能会在合并例程中丢失,因为大多数例程从其他文档导入页面,而不是文档级特征。在这段代码中,我试图将所有pdf添加到最终pdf的复印机中。但是我如何提供一个示例文档…我不确定…您可以通过文件宿主提供一个示例文档,并可以选择共享,例如dropbox或google drive,然后在此处发布链接。顺便说一句,使用
Pdf*Copy*
类系列是一个良好的开端。这至少复制了与表单字段关联的JS。是的PDF Copy正在复制使用adobe关联的JS。但是使用itext关联的JS已经不存在了。示例文档是否真的很重要,因为我不确定是否可以共享它。或者,也可以添加代码,使用iText将JS添加到PDF中。