As of NetWeaver 7.0 SPS10-SPS12 (with OSS note 1055738) or SPS13+, functionality was provided to automatically map the context of an offline interactive form uploaded via the FileUpload UI element to the Web Dynpro Context. You need only use the displayType "native" - which you should be using regardless.Below given is a solution to read the form using code.
To read a value from adobe interactive PDF we have to read each and every node that is binded to the form from the context. To read a single field that is binded to the PDF can be achieved in some simple 12 steps, which are explained below. After getting focus to a node that is binded to the PDF, we need to travel inside the node to read the value of the attribute that is created inside the node. Using the the methods provided we can read individual variables with a parent child pointer relationship.
For Getting the table Values from the PDF, a small Logic can Help You.Once the individual variables are read, we need to read the tables in the PDF to an internal table, so that we can bind the whole data to context in one go. which is explained in this chapter after single variable reading.
DATA: l_fp TYPE REF TO if_fp.
l_fp = cl_fp=>get_reference( ).
Step2. Get reference to the Pdf Object Class
DATA: l_pdfobj TYPE REF TO if_fp_pdf_object.
l_pdfobj = l_fp->create_pdf_object( ).
l_pdfobj->set_document( pdfdata = lv_pdf_data_source ). lv_pdf_data_sourcce can be retrived by using an upload UI element and get the xml string to an attribute of type xstring
l_pdfobj->set_extractdata( ).
l_pdfobj->execute( ).
DATA: pdf_form_data TYPE xstring.
l_pdfobj->get_data( IMPORTING formdata = pdf_form_data ).
DATA: converter TYPE REF TO cl_abap_conv_in_ce, formxml TYPE string.
Converter = cl_abap_conv_in_ce=>create( input = pdf_form_data ).
Converter->read( IMPORTING data = formxml ).
TYPE-POOLS: ixml.
DATA: l_ixml TYPE REF TO if_ixml.
l_ixml = cl_ixml=>create( ).
DATA: streamfactory TYPE REF TO if_ixml_stream_factory,
istream TYPE REF TO if_ixml_istream.
streamfactory = l_ixml->create_stream_factory( ).
istream = streamfactory->create_istream_string( formxml ).
DATA: document TYPE REF TO if_ixml_document.
Document = l_ixml->create_document( ).
DATA: parser TYPE REF TO if_ixml_parser.
parser = l_ixml->create_parser( stream_factory = streamfactory
istream = istream
document = document ).
Start parsing theDocument with parsing interface referenced.
Parser->parse( ).
Now we have to define an interface to process the XML nodes in the xml Document.
DATA: node TYPE REF TO if_ixml_node.
We can now use the methods of the xml interface to read values from the xml Document.Eg: Iam using the method Find_From_name() to retrive the value of an attribute by giving the name of the node in form interface. Here node name, attribute name, field names all refer to the names in the form.
interface.node = document->find_from_name(NAME_OF_EMPLOYEE).
IF NOT node IS INITIAL.
Name = node->get_value( ).
ENDIF.node = document->find_from_name(GROUP_OF_EMPLOYEE).
IF NOT node IS INITIAL.
group = node->get_value( ).
ENDIF.node = document->find_from_name(QUALIFICATION_OF_EMPLOYEE).
IF NOT node IS INITIAL.
Qualification = node->get_value( ).
ENDIF.need to repeat this procedure for all the indudual variable in the PDF.
For reading a table from the pdf , first we need to focus the node that contains attributes that is binded to the table in the form. Then move inside the node and read its children one by one.For the simplicity of understanding , here iam considering a table that contains a student's record for 5 consicutive years, say from 1998 to 2002. thats a table with colums year, total mark, percentage, Class positionA single row in the table should be like
Year | TotalMark | Percentage | ClassPosition |
1998 | 520 | 95 | 3 |
1999 | 450 | 62 | 5 |
2000 | 562 | 85 | 6 |
2001 | 480 | 59 | 2 |
2002 | 526 | 96 | 1 |
Declerations for Reading the Table.
data : item type string. DATA: nodechild TYPE REF TO if_ixml_node,
Childschild TYPE REF TO if_ixml_node.
data: num_of_children type i.
Get Focus to the parent node thats binded to the table.
node = document->find_from_name('TABLE').
Read the number of children available for the node 'table'. Which is the number of rows Available for the table
num_of_children = node->num_children( ).
Now you have to loop the table 'number_of_children' times inorder to read the table completely.And inside this loop you have to find the number of attributes available for each row and loop this number of times to read value of each attribute.
nodechild = node->get_first_child( )."Getting focus to child node's First attribute
do Num_of_children times.
x = 1.
Childschild = nodechild->get_first_child( ).
num_of_attribute = Childschild->num_children( )." Getting the number of attributes
do num_of_attribute times.
item = Childschild->GET_value( ).
I am considering the case were the numbers of attributes are max 4 and I am sure about the attribute position
case x.
when 1.
wa_table-year = item.
when 2.
wa_table-total_mark= item.
when 3.
wa_table-percentage= item.
when 4.
wa_table-class_position= item.
endcase. Childschild = Childschild->get_next( ).
x = x + 1.
enddo. nodechild = nodechild->get_next( ).
append wa_table to ls_table.
enddo.
Now the whole values from the table are there in the itab ls_table. You can bind the table to a context node.
Enjoy!!