Skip to main content
Participating Frequently
September 3, 2016
Question

action wizard to process many pdf forms and create a csv file for each

  • September 3, 2016
  • 2 replies
  • 2616 views

trying to use action wizard to process many pdf forms and create a csv file for each, so far I have something like this but it does not seem to be working, any ideas?

 

  if ( app.viewerVersion >= 7 ) {

    this.createDataObject(this.title + ".xls");

  // Get the file stream object of the embedded file

  var oFile = this.getDataObjectContents(this.title + ".xls");

  // Convert to a string

  var myApp = util.stringFromStream(oFile, "utf-8");

  // Get Field Names separated by comma

  for (var i = 0; i < this.numFields; i++) {

              myApp + this.getNthFieldName(i) + ",";

  console.println("Field[" + i + "] = " + this.getNthFieldName(i));

  }

  // Add newline

  var myApp = myApp + "\r\n";

  // Get Field Values separated by comma

  for (var i = 0; i < this.numFields; i++) {

  var fieldName = this.getNthFieldName(i);

              myApp + this.getField(fieldName).value + ",";

  console.println("FieldValue[" + i + "] = " + this.getField(fieldName).value);

  }

  // Convert back to a file stream

  var oFile = util.streamFromString(myApp, "uft-8");

  // Now "overwrite" budget.xls

  this.setDataObjectContents(this.title + ".xls", oFile);

  } else {

  app.alert("Acrobat 7.0 or later is required.");

  }

This topic has been closed for replies.

2 replies

NKOWA555
Inspiring
September 9, 2016

I don't know if you are having any success with Adobe's JavaScript; but, you can use VB.net to get a CSV file for each PDF (acrobat PDF) file in a directory. You can use FDFToolkit.net and Visual Studio to create the application (windows, console or server side). Let me know if you need a custom programming solution.

Note: FDFToolkit.net and Visual Studio.net can be downloaded for free.

Example VB.net Code

Imports FDFApp.FDFDoc_Class

Imports FDFApp.FDFApp_Class

Imports System.IO

''' <summary>

''' Call clsPdfDirectory2Csv.createCsv("C:\path\to\pdf\directory\")

''' </summary>

''' <remarks></remarks>

Public Class clsPdfDirectory2Csv

    Public Shared Sub createCsv(ByVal directory_path As String)

        If Not String.IsNullOrEmpty(directory_path & "") Then

            For Each f As String In Directory.GetFiles(directory_path)

                If File.Exists(f) Then

                    If Path.GetExtension(f).Replace(".", "") = "pdf" Then

                        Try

                            Dim p As New FDFApp.FDFApp_Class, fdf As New FDFApp.FDFDoc_Class

                            fdf = p.PDFOpenFromFile(f, True, True, "")

                            Dim csv As String = CreateCSVRow(fdf.XDPGetAllFields().ToList())

                            File.WriteAllText(Path.GetDirectoryName(f).TrimEnd("\") & "\" & Path.GetFileNameWithoutExtension(f) & ".csv", csv.ToString, System.Text.Encoding.UTF8)

                        Catch ex As Exception

                            Err.Clear()

                        End Try

                    End If

                End If

            Next

        End If

    End Sub

    Public Shared Function CreateCSVRow(ByVal fldArray As List(Of FDFApp.FDFDoc_Class.FDFField)) As String

        Dim csvCols As New List(Of String)

        Dim csvValue As String

        Dim needQuotes As Boolean

        Dim strCsv As String = ""

        For i As Integer = 0 To fldArray.Count - 1

            If Not String.IsNullOrEmpty(strCsv & "") Then

                strCsv &= ","

            End If

            strCsv &= """" & fldArray(i).FieldName.ToString() & """"

        Next

        For i As Integer = 0 To fldArray.Count - 1

            csvValue = fldArray(i).FieldValue(0)

            needQuotes = (csvValue.IndexOf(",", StringComparison.InvariantCulture) >= 0 _

                          OrElse csvValue.IndexOf("""", StringComparison.InvariantCulture) >= 0 _

                          OrElse csvValue.IndexOf(vbCrLf, StringComparison.InvariantCulture) >= 0)

            csvValue = csvValue.Replace("""", """""")

            csvCols.Add(If(needQuotes, """" & csvValue & """", csvValue))

        Next

        strCsv &= Environment.NewLine & String.Join(",", csvCols.ToArray())

        Return strCsv

    End Function

End Class

Bernd Alheit
Community Expert
Community Expert
September 3, 2016

In lines 18 and 30 you don't change myApp.

Participating Frequently
September 4, 2016

thanks but still doesn't generate the xls file, is there something else I'm missing?

try67
Community Expert
Community Expert
September 4, 2016

Are there any errors when you run the code? What exactly is the result of running it?