PDF object API

The PDF object API allows communicating with the ADS and carrying out necessary functions from an ABAP program. These include creation of forms and extraction of data, and so on. In this recipe, we will see the code that will allow you to communicate with the ADS in order to generate a PDF form object for a filled PDF form and then extract necessary data from it. We assume that we are not using the Adobe offline infrastructure.

There are a few classes and interfaces involved. The factory class CL_FP is used for creating the PDF document object instance that is based on the class CL_FP_PDF_OBJECT (using interface IF_FP_PDF_OBJECT). The main implementation class for the PDF object is CL_FP_PDF_OBJECT.

In this recipe, we will see how a filled form may be programmatically processed using the ADS functions and then the entered data within the form may be extracted. We assume that the form to be processed is stored in the variable MYFORM having type XSTRING. The recipe takes on from there. Only the part that is relevant to the instantiation of the PDF object and extraction is shown in the recipe.

How to do it...

Follow these steps:

  1. We first need to declare variables for the factory class interface IF_FP and the interface IF_FP_PDF_OBJECT.
    How to do it...
  2. The static method GET_REFERENCE of the CL_FP interface is then called and the object returned is stored in MY_FP.
    How to do it...
  3. Next, the PDF object is then created using the CREATE_PDF_OBJECT method of the CL_FP class. The value ADS is passed for the CONNECTION parameter. Then the SET_DOCUMENT method is called and the PDF data contained in the xstring MYFORM is assigned to it.
    How to do it...
  4. The SET_EXTRACTDATA method of the class CL_FP_PDF_OBJECT is then called followed by the EXECUTE method.
    How to do it...
  5. The GET_DATA method is then called.
    How to do it...
  6. The entire block of code may be placed within the TRY and ENDTRY statements and the Exception class CX_FP_RUNTIME_SYSTEM may be used.
    How to do it...

How it works...

We initially declare references to the factory class CL_FP and the main implementation class CL_IF_PDF_OBJECT (using appropriate interface names). The static GET_REFERENCE method the CL_FP class is then called and an object is instantiated belonging to class CL_FP. This is pointed to by the reference variable MY_FP.

The CREATE_PDF_OBJECT method of the factory class CL_FP is then called to create the PDF object instance, the reference to which is stored in the variable MYPDFOBJECT.

The SET_DOCUMENT method is called for the variable MYPDFOBJECT in order to link the PDF data stored in the MYFORM xstring. The SET_EXTRACTDATA method is then called in order to specify the extraction of the entered data in the form. The Execute method allows the PDF form to be passed to the ADS and the extraction of data to takes place.

It is only at the EXECUTE method that the ADS comes into action (the Execute method triggers execution of all method beginning with SET_). The data entered in the form is extracted and is made available in XML format. Once the extraction has been done, the GET_DATA method may be called in order to read the form data into the xstring XMLDATA. We can use transformations to place the data in ABAP variables.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.254.103