【问题标题】:Executing "pdftk my-pdf-form.pdf dump_data_fields" shows nothing执行“pdftk my-pdf-form.pdf dump_data_fields”什么也没显示
【发布时间】:2015-05-20 12:24:28
【问题描述】:

我正在使用工具 pdftk,我有一个可编辑的 PDF,我在文档中看到参数 dump_data_fields 应该向我显示表单的字段。

我使用这个命令(windows):pdftk my-pdf-form.pdf dump_data_fields

我使用的是pdftk 服务器版。

文档:https://www.pdflabs.com/docs/pdftk-man-page/

关键是 PDF 是可编辑的,它有一些字段可以用 Adob​​e PDF Viewer 编写。

【问题讨论】:

    标签: pdftk


    【解决方案1】:

    问题在于 pdf 是由 Adob​​e LiveCycle Designer 创建的,并保存为“Adobe Dynamic XML From”。解决方案是将文件另存为“Adobe 静态 PDF 表单”。可能 pdftk 无法处理该 livecycle 文件。

    【讨论】:

      【解决方案2】:

      我认为接受的答案可能是我的解决方案,但事实证明我正在使用的 PDF 文档实际上没有设置表单域。如果文档看起来像一个表单,但表单字段没有变灰,则不会检测到任何字段。

      我可以解决此问题的唯一方法是在 Acrobat Pro 中打开文档并通过其表单工具添加字段。然后 pdftk 工作正常。

      【讨论】:

        【解决方案3】:

        如果您在 Windows 环境中遇到 OP 问题,请按照以下说明操作。

        1- 打开 GUI PDFtk 程序。 (如果您愿意,也可以使用 cli)

        2- 单击“添加 PDF...”按钮并搜索准备好填写的 PDF 文件。

        3- 向下滚动到 GUI PDFtk 窗口的底部,然后单击“创建 PDF...”而不添加或更改任何设置。

        4- 将新的填充就绪 PDF 文件以新名称保存到您选择的目录中

        5- 最后,使用 cmd 发出 Windows 版本的 dump_data_fields 命令,如下所示。(注意如何使用“输出”而不是“>”)

        6- 打开文本文件“fields.txt”,您将看到字段名称。示例如下所示。

        【讨论】:

          【解决方案4】:

          我不知道这是否有帮助,但我编写了一些 C# 代码来计算文档中的数据字段。请看以下函数。

          1. 这里我们将文件路径传递给文件,它会计算文档中的字段总数。

            public int countDataFields(string inputFile)
            {
                int fieldCount = 0;
                string arguments = "";
            
                using (Process newProcess = new Process())
                {
                    arguments = inputFile + " dump_data_fields";
                    newProcess.StartInfo = new ProcessStartInfo("pdftk ", arguments);
                    newProcess.StartInfo.RedirectStandardInput = true;  
                    newProcess.StartInfo.RedirectStandardOutput = true;
                    newProcess.StartInfo.RedirectStandardError = true;
                    newProcess.StartInfo.UseShellExecute = false;
                    newProcess.StartInfo.CreateNoWindow = false;
                    newProcess.Start();
            
                    while (!newProcess.StandardOutput.EndOfStream)
                    {
                        var line = newProcess.StandardOutput.ReadLine();
                        fieldCount = fieldCount + 1;
                    }
            
                    Console.WriteLine("Field Counts: " + fieldCount);
                    newProcess.WaitForExit();
                }
            
                return fieldCount;
            }
            
          2. 如果您想通过标准输入将文件作为流传递

            public void countDataFieldsWhenFilePassedAsBinaryStream(string file1)
            {
                int fieldCount = 0;
                // initialize the binary reader and open the binary reader with the file stream of the incoming file.
                BinaryReader binaryReader = new BinaryReader(File.Open(file1, FileMode.Open, FileAccess.Read));
            
                //create a buffer array of 1024.
                byte[] buffer = new byte[1024];
            
                using (Process newProcess = new Process())
                {
                    newProcess.StartInfo = new ProcessStartInfo("pdftk");
                    newProcess.StartInfo.Arguments = @" - dump_data_fields";
                    newProcess.StartInfo.UseShellExecute = false;
                    newProcess.StartInfo.RedirectStandardInput = true;
                    newProcess.StartInfo.RedirectStandardOutput = true;
                    newProcess.Start();
            
                    int bytesRead = 0;
            
                    // we are reading the binary files in chunks of 1024 bytes
                    // we loop through as long as the byte read is greater than 0
                    while ((bytesRead = binaryReader.Read(buffer, 0, 1024)) > 0)
                    {
                        //  we write the standard input bytes into the buffer.
                        newProcess.StandardInput.BaseStream.Write(buffer, 0, bytesRead);
                    }
            
                    //closing the binaryReader
                    binaryReader.Close();
            
                    //closing the standard input stream
                    newProcess.StandardInput.Close();
            
                    // here we are going to loop through the standard output stream till the eof. we are counting the
            
                    while (newProcess.StandardOutput.EndOfStream == false)
                    {
                        //read the line;
                        newProcess.StandardOutput.ReadLine();
                        //increment the counter
                        fieldCount++;;
                    }
            
                    // console writeline the field count.
                    Console.WriteLine(fieldCount);
            
                    newProcess.WaitForExit();
                }// end of using
            }// end of function convertPDFToStandardInput
            

          希望这会有所帮助:)

          【讨论】:

            猜你喜欢
            • 2014-09-02
            • 2016-04-24
            • 2014-02-13
            • 1970-01-01
            • 1970-01-01
            • 2012-03-29
            • 1970-01-01
            • 1970-01-01
            • 2021-06-13
            相关资源
            最近更新 更多