Extract Data from AcroForm using Rust

Export Data to XML from a PDF File

This code snippet shows how to export AcroForm data from a PDF document to an XML file using Aspose.PDF for Rust. The process involves opening an existing PDF file with form fields, then exporting those fields and their values to an XML document for further processing, storage, or data exchange.

  1. Open the PDF document.
  2. Call the ’export_xml’ method to extract the form field data and save it as an XML file.

    use asposepdf::Document;

    fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Open a PDF-document with filename
        let pdf = Document::open("sample.pdf")?;

        // Export from the previously opened PDF-document with AcroForm to XML-document
        pdf.export_xml("sample.xml")?;

        Ok(())
    }

Export Data to FDF from a PDF File

Aspose.PDF for Rust via C++ allows you to export AcroForm data from a PDF document to an FDF file. The Forms Data Format (FDF) file stores form field names and values separately from the PDF, making it useful for data exchange, form submission workflows, and archiving form data without embedding it in the original document.


    use asposepdf::Document;

    fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Open a PDF-document with filename
        let pdf = Document::open("sample.pdf")?;

        // Export from the previously opened PDF-document with AcroForm to FDF-document
        pdf.export_fdf("sample.fdf")?;

        Ok(())
    }

Export Data to XFDF from a PDF File

XFDF (XML Forms Data Format) is an XML-based format that represents form field data separately from the PDF file, making it ideal for data interchange, form submissions, and integration with web-based workflows. Aspose.PDF for Rust via C++ helps to export AcroForm data from a PDF document to an XFDF file.


    use asposepdf::Document;

    fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Open a PDF-document with filename
        let pdf = Document::open("sample.pdf")?;

        // Export from the previously opened PDF-document with AcroForm to XFDF-document
        pdf.export_xfdf("sample.xfdf")?;

        Ok(())
    }