05-08-2009 2:30 PM
Hi Friends,
Can anyone tell me how do I import external PDF file that is Interactive Adobe form in PDF format into SAP.
Not only this but even I need to convert the imported file in SAP to XML format so that I can get back the updated form in the system and update the respective data in the Backend tables.
Regards,
Ameet
05-08-2009 5:52 PM
Hi,
If you are using a web dynpro program then its very simple.
Use a "File Upload" UI Element to upload the existing PDF and assign a XSTRING type attribute to data field property of "File Upload" UI element.
This XSTRING will contain the PDF file source and then you have to manipulate the XSTRING to get the values.
But if you are not using a WD and it is normal ABAP program then you need to call GUI_UPLOAD to upload the pdf and get BINARY data of PDF. Then Convert this BINARY data to XSTRING form using BINARY_TO_XSTRING Function Module.
After you have the XSTRING follow the steps below.
Step 1: Get the FP Reference
DATA: lo_fp TYPE REF TO if_fp.
lo_fp = cl_fp=>get_reference( ).
*Step 2: Get reference to PDF Object Class
DATA: lo_pdfobj TYPE REF TO if_fp_pdf_object.
lo_pdfobj = lo_fp->create_pdf_object( ).
*Step 3: Set the pdf in PDF object.
lo_pdfobj->set_document( pdfdata = lv_filedata ). "lv_filedata is your XSTRING data
*Step 4: Set the PDF Object to extract data from Form Data
lo_pdfobj->set_extractdata( ).
*Step 5: Call ADS Execute
lo_pdfobj->execute( ).
*Step 6: Get the Form Data
DATA: lv_pdf_data TYPE xstring.
lo_pdfobj->get_data( IMPORTING formdata = lv_pdf_data ).
*Step 7: Convert the XSTRING
DATA: lo_converter TYPE REF TO cl_abap_conv_in_ce.
lo_converter = cl_abap_conv_in_ce=>create( input = lv_pdf_data ).
DATA formxml TYPE string.
lo_converter->read( IMPORTING data = formxml ).
*Pull in IXML type group
TYPE-POOLS: ixml.
*get reference to ixml object
DATA: lo_ixml TYPE REF TO if_ixml.
lo_ixml = cl_ixml=>create( ).
*get Istream object
DATA: lo_stream_factory TYPE REF TO if_ixml_stream_factory.
DATA: lo_istream TYPE REF TO if_ixml_istream.
lo_stream_factory = lo_ixml->create_stream_factory( ).
lo_istream = lo_stream_factory->create_istream_string( formxml ).
*Create an XML document
DATA: lo_document TYPE REF TO if_ixml_document.
lo_document = lo_ixml->create_document( ).
Create Parser
DATA lo_parser TYPE REF TO if_ixml_parser.
lo_parser = lo_ixml->create_parser(
stream_factory = lo_stream_factory
istream = lo_istream
document = lo_document
).
parse
lo_parser->parse( ).
defien XML node type
DATA : lo_node TYPE REF TO if_ixml_node.
*now you can read the values and for that you need to know the XML nodes
for ex : if the uploaded file has a "GREETINGS" node then
get greeting node
DATA lv_greeting TYPE string.
lo_node = lo_document->find_from_name( name = 'GREETINGS' ).
lv_greeting = lo_node->get_value( ).
follow the procedure for other node values.
-
Thanks,
Abhishek
05-11-2009 9:19 AM
Hi Abhishek,
Can you help me any example on the same which does the same as asked by me.
I am not able to interpret what you have sent me as it just doesn't work.
Regards,
Ameet