How to convert PDF XFA Form to XML in C#, VB.NET and VBScript using PDF Extractor SDK - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

How to convert PDF XFA Form to XML in C#, VB.NET and VBScript using PDF Extractor SDK

  • Home
  • /
  • Articles
  • /
  • How to convert PDF XFA Form to XML in C#, VB.NET and VBScript using PDF Extractor SDK

With ByteScout PDF Extractor SDK, you can convert PDF XFA Form to XML. Check the code samples in C#, VB.NET and VBScript below.

Select your programming language:

How to convert PDF XFA Form to XML in C#


using System;
using Bytescout.PDFExtractor;

namespace XFAFormToXML
{
	class Program
	{
		static void Main(string[] args)
		{
			// Create Bytescout.PDFExtractor.XFAFormExtractor instance
			XFAFormExtractor extractor = new XFAFormExtractor();
			extractor.RegistrationName = "demo";
			extractor.RegistrationKey = "demo";

			// Load sample PDF document
			extractor.LoadDocumentFromFile("samplexfa.pdf");

            // Enumerate XFA form content part types
		    foreach (XFAFormContentType contentType in Enum.GetValues(typeof(XFAFormContentType)))
		    {
                // Get count of content parts of specified type
		        int partCount = extractor.GetCount(contentType);

                // Save parts as XML files
                for (int i = 0; i < partCount; i++)
                {
                    string fileName = contentType.ToString() + i + ".xml";
                    extractor.SaveToFile(contentType, i, fileName);
                    Console.WriteLine("Saved form part " + fileName);
                }
		    }
			
			Console.WriteLine();
			Console.WriteLine("Press any key to continue...");
			Console.ReadLine();
		}
	}
}

How to convert PDF XFA Form to XML in Visual Basic .NET

Imports Bytescout.PDFExtractor

Class Program
	Friend Shared Sub Main(args As String())

        ' Create Bytescout.PDFExtractor.XFAFormExtractor instance
        Dim extractor As New XFAFormExtractor()
		extractor.RegistrationName = "demo"
		extractor.RegistrationKey = "demo"

		' Load sample PDF document
        extractor.LoadDocumentFromFile("samplexfa.pdf")

        ' Enumerate XFA form content part types
        For Each contentType As XFAFormContentType In [Enum].GetValues(GetType(XFAFormContentType))

            'Get count of content parts of specified type
            Dim partCount As Integer = extractor.GetCount(contentType)

            ' Save parts as XML files
            For i As Integer = 0 To partCount - 1
                Dim fileName As String = contentType.ToString() + i.ToString() + ".xml"
                extractor.SaveToFile(contentType, i, fileName)
                Console.WriteLine("Saved form part " + fileName)
            Next

        Next

        Console.WriteLine()
        Console.WriteLine("Press any key to continue...")
        Console.ReadLine()

	End Sub
End Class

How to convert PDF XFA Form to XML in VBScript (Visual Basic 6)

' Create Bytescout.PDFExtractor.XMLExtractor object
Set extractor = CreateObject("Bytescout.PDFExtractor.XFAFormExtractor")

extractor.RegistrationName = "demo"
extractor.RegistrationKey = "demo"

' Load sample PDF document
extractor.LoadDocumentFromFile "..\..\samplexfa.pdf"


for i=0 to 12 ' iterate through 12 content types (see XFAFormContentType enum in the documentation, there are 13 types)

count = extractor.GetCount(i) ' get count of the given type
 For j=0 to count-1
   extractor.SaveToFile i, j, CStr(i) & "-" & CStr(j) & ".xml"
 Next

Next


MsgBox "XFA xml data has been extracted"

Tutorials:

prev
next