Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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
Java PDF小丑,具有相同字段名的缩写形式_Java_Pdfclown - Fatal编程技术网

Java PDF小丑,具有相同字段名的缩写形式

Java PDF小丑,具有相同字段名的缩写形式,java,pdfclown,Java,Pdfclown,我用Open Office制作了许多单页表单,并将它们导出为PDF文档 我打开我的应用程序,打开这些pdf文档,填写表单元素,并将它们组合起来保存 在我打印出一个列表到每一行的特定形式。问题是,如果列表超过了页面的大小,我需要复制页面,并将其余项目附加到剩余页面上 如果文档上有多个同名字段,则可能会出现问题,只有第一个字段有值,后续同名字段为空 代码是这样的,我现在没有确切的代码 org.pdfclown.files.File output = new org.pdfclown.

我用Open Office制作了许多单页表单,并将它们导出为PDF文档

我打开我的应用程序,打开这些pdf文档,填写表单元素,并将它们组合起来保存

在我打印出一个列表到每一行的特定形式。问题是,如果列表超过了页面的大小,我需要复制页面,并将其余项目附加到剩余页面上

如果文档上有多个同名字段,则可能会出现问题,只有第一个字段有值,后续同名字段为空

代码是这样的,我现在没有确切的代码

        org.pdfclown.files.File output = new org.pdfclown.files.File();
        PageManager pageManager = new PageManager(output.getDocument());

        for(org.pdfclown.files.File pdfPage : pdfPages) {

            //fill in the form element ...
            pdfPage.getDocument().getForm().getFields().get("some_field").setValue("something");

            pageManager.add(pdfPage.getDocument());
        }

        java.io.File temp = Files.createTempFile("Test", ".pdf").toFile();
        output.save(temp, SerializationModeEnum.Standard);

我注意到,当我从OpenOffice导出时,有一个复选框允许重复表单名称。以前有人有过这个问题吗?API中是否存在允许使用不同值显示重复表单名称的内容?

我从未真正解决过这个问题,但我确实找到了一个替代方法。在每个页面上,我迭代了所有表单元素,并通过添加“[x]”更改了它们的名称,其中“x”是页码。这使得每个页面的表单元素都是独一无二的。

无论我做了什么尝试,我都无法使用您的方法解决我的问题。每个页面上的所有字段都以相同的名称结束。生成的文件需要有150份第一页的副本。我的方法是不同的,创建150个只包含第一页的PDF,并在每个PDF上运行这些代码

public override void Run()
{
  // 1. Magic...
  string resourcePath = System.IO.Path.GetFullPath("../../../../main/res/samples/input/" + "pdf");

  // Get the list of available PDF files
  string[] filePaths = System.IO.Directory.GetFiles(resourcePath + System.IO.Path.DirectorySeparatorChar, "*.pdf");

  // Cycle through files
  for (int index = 0; index < filePaths.Length; index++)
  {
      using (File file = new File(filePaths[index]))
      {
          Document document = file.Document;

          // 2. Get the acroform!
          Form form = document.Form;
          foreach (Page page in form.Document.Pages)
          {
              foreach (var s in page.Document.Form.Fields.Values)
              {
                  s.Name = s.FullName + index.ToString();
              }

          }
          Serialize(file, file + index.ToString(), SerializationModeEnum.Incremental);

      }
  }
}
public override void Run()
{
//1.魔法。。。
字符串resourcePath=System.IO.Path.GetFullPath(“../../../../main/res/samples/input/”+“pdf”);
//获取可用PDF文件的列表
字符串[]filepath=System.IO.Directory.GetFiles(resourcePath+System.IO.Path.directorysepartorchar,“*.pdf”);
//循环浏览文件
for(int index=0;index
之后,只需将它们与Adobe Acrobat DC合并在一个文件中即可。此代码是从PDFClown示例中稍微修改的