This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Read data from PDF forms


data = readPDFFormData(filename)
data = readPDFFormData(filename,'Password',password)



data = readPDFFormData(filename) reads the data from a PDF form into a struct.

data = readPDFFormData(filename,'Password',password) specifies the password for opening the PDF form.


collapse all

Read the data from the form fields in weatherReportForm1.pdf using readPDFFormData. The function returns a struct containing the data from the PDF form fields.

filename = "weatherReportForm1.pdf";
data = readPDFFormData(filename)
data = struct with fields:
         event_type: "Thunderstorm Wind"
    event_narrative: "Large tree down between Plantersville and Nettleton."

Read the data from the form fields in multiple files using a file datastore.

Create a file datastore for the weather reports forms. The forms are named "weatherReportFormN.pdf", where N is the number of the form.. Specify the file name using the wildcard "*" to find all file names of this structure. To specify the read function to be readPDFFormData, input this function to fileDatastore using a function handle.

fds = fileDatastore("weatherReportForm*.pdf",'ReadFcn',@readPDFFormData)
fds = 
  FileDatastore with properties:

                       Files: {
                              ' .../tpa3cfb019/textanalytics-ex39762425/weatherReportForm1.pdf';
                              ' .../tpa3cfb019/textanalytics-ex39762425/weatherReportForm2.pdf';
                              ' .../tpa3cfb019/textanalytics-ex39762425/weatherReportForm3.pdf'
                               ... and 1 more
                 UniformRead: 0
                    ReadMode: 'file'
                   BlockSize: Inf
                  PreviewFcn: @readPDFFormData
                     ReadFcn: @readPDFFormData
    AlternateFileSystemRoots: {}

Loop over the files in the datastore and read each PDF form.

data = [];
while hasdata(fds)
    textData = read(fds);
    data = [data; textData];
data = 4x1 struct array with fields:

Input Arguments

collapse all

Name of the file, specified as a string scalar or character vector.

readPDFFormData supports AcroForm PDF files (interactive forms) only.

Data Types: string | char

Password to open PDF file, specified as a character vector or a string scalar.

Example: 'skroWhtaM'

Data Types: string | char

Output Arguments

collapse all

Output struct. The fields of data correspond to the names of the form fields in the PDF. If the form field names are not valid struct field names, then the function automatically edits them to construct valid names.

Introduced in R2018a