Skip to Content
-1

Read PDF DATA using ADS

Nov 24, 2016 at 12:46 PM

200

avatar image
Former Member

Hi expert,

I try to get data from PDF using ADS but i get this error

ADS: com.adobe.ProcessingException: com.adobe.ProcessingException: PDF is not an interactive form. Data cannot be exported from it.(200.201).

Can i get data from pdf non interactive using ADS?

this is code that i use

SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS:

  p_file LIKE rlgrap-filename " File path

                   OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

DATA:

  w_filename    TYPE string, " File name

  w_length      TYPE i,

  lt_file_table TYPE filetable,

  lv_filelength TYPE i,

  lv_rc         TYPE i,

  lv_filename   TYPE string,

  w_pdf_data    TYPE xstring,

  lt_rawtab     TYPE TABLE OF char255,

  w_pdf_file    TYPE string,

* Create PDF Object using destination 'ADS' (<-- this is how it is

* defined in SM59)

  lo_pdfobj     TYPE REF TO if_fp_pdf_object VALUE IS INITIAL,

  xslt_message  TYPE string,

  exc           TYPE REF TO cx_root.

*  fs_per_info   TYPE zwd_per_info.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  PERFORM f4_help_for_file.



START-OF-SELECTION.

  PERFORM get_pdf_data.

  PERFORM get_pdf_instantiate.

  PERFORM extract_data.

*&----------------------------------------------------------------*

*&      Form  F4_HELP_FOR_FILE

*&----------------------------------------------------------------*

FORM f4_help_for_file .

  CALL METHOD cl_gui_frontend_services=>file_open_dialog

    CHANGING

      file_table              = lt_file_table

      rc                      = lv_rc

*     USER_ACTION             =

*     FILE_ENCODING           =

    EXCEPTIONS

      file_open_dialog_failed = 1

      cntl_error              = 2

      error_no_gui            = 3

      not_supported_by_gui    = 4

      OTHERS                  = 5.

  IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

*  READ TABLE lt_file_table

*        INTO lv_filename

*        INDEX 1.

  READ TABLE lt_file_table

      INTO p_file

      INDEX 1.

  IF sy-subrc EQ 0.

    lv_filename = p_file.

  ENDIF.

  cl_gui_frontend_services=>gui_upload(

    EXPORTING

      filename = lv_filename

      filetype = 'BIN' "Binary

    IMPORTING

      filelength = lv_filelength

    CHANGING

      data_tab = lt_rawtab

    EXCEPTIONS

      file_open_error = 1

      file_read_error = 2

      no_batch = 3

      gui_refuse_filetransfer = 4

      invalid_type = 5

      no_authority = 6

      unknown_error = 7

      bad_data_format = 8

      header_not_allowed = 9

      separator_not_allowed = 10

      header_too_long = 11

      unknown_dp_error = 12

      access_denied = 13

      dp_out_of_memory = 14

      disk_full = 15

      dp_timeout = 16

      not_supported_by_gui = 17

      error_no_gui = 18

      OTHERS = 19 ).

ENDFORM.                    " F4_HELP_FOR_FILE

*&----------------------------------------------------------------*

*&      Form  GET_PDF_INSTANTIATE

*&----------------------------------------------------------------*

FORM get_pdf_instantiate .

* Get FP reference

  DATA: lo_fp TYPE REF TO if_fp VALUE IS INITIAL.

  lo_fp = cl_fp=>get_reference( ).

* For handling exceptions

  DATA: lo_fpex TYPE REF TO cx_fp_runtime VALUE IS INITIAL.

  TRY.

      lo_pdfobj = lo_fp->create_pdf_object( connection = 'ADS' ).

*   Set document

      lo_pdfobj->set_document(

        EXPORTING

          pdfdata = w_pdf_data ).

*   Tell PDF object to extract data

      lo_pdfobj->set_extractdata( ).

*   Execute the call to ADS

      lo_pdfobj->execute( ).

    CATCH cx_fp_runtime_system INTO exc.

      xslt_message = exc->get_text( ).

  ENDTRY.

ENDFORM.                    " GET_PDF_INSTANTIATE

*&----------------------------------------------------------------*

*&      Form  EXTRACT_DATA

*&----------------------------------------------------------------*



FORM extract_data .

  DATA: xml_data     TYPE xstring,

        t_return     TYPE STANDARD TABLE OF bapiret2,

        t_per_info   TYPE STANDARD TABLE OF smum_xmltb,

        lfs_per_info TYPE smum_xmltb.

  lo_pdfobj->get_data(

  IMPORTING

  formdata = xml_data ).

  CALL FUNCTION 'SMUM_XML_PARSE'

    EXPORTING

      xml_input = xml_data

    TABLES

      xml_table = t_per_info

      return    = t_return.



  BREAK-POINT.

*  LOOP AT t_per_info INTO lfs_per_info.

*    CASE lfs_per_info-cname.

*      WHEN 'FNAME'.

*        fs_per_info-fname = lfs_per_info-cvalue.

*      WHEN 'LNAME'.

*        fs_per_info-lname = lfs_per_info-cvalue.

*      WHEN 'DOB'.

*        REPLACE ALL OCCURRENCES OF '-' IN lfs_per_info-cvalue WITH space.

*        CONDENSE lfs_per_info-cvalue.

*        fs_per_info-dob = lfs_per_info-cvalue.

*      WHEN 'TEXP'.

*        fs_per_info-texp = lfs_per_info-cvalue.

*      WHEN 'CEMPLOYER'.

*        fs_per_info-cemployer = lfs_per_info-cvalue.

*      WHEN 'CSALARY'.

*        fs_per_info-csalary = lfs_per_info-cvalue.

*      WHEN 'ESALARY'.

*        fs_per_info-esalary = lfs_per_info-cvalue.

*      WHEN OTHERS.

*    ENDCASE.

*  ENDLOOP.

*  fs_per_info-waers = 'INR'.

*  INSERT INTO zwd_per_info VALUES fs_per_info.

ENDFORM.                    " EXTRACT_DATA

*&----------------------------------------------------------------*

*&      Form  GET_PDF_DATA

*&----------------------------------------------------------------*

FORM get_pdf_data .

  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

    EXPORTING

      input_length = lv_filelength

*     FIRST_LINE   = 0

*     LAST_LINE    = 0

    IMPORTING

      buffer       = w_pdf_data

    TABLES

      binary_tab   = lt_rawtab

* EXCEPTIONS

*     FAILED       = 1

*     OTHERS       = 2

    .

  IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

ENDFORM.                    " GET_PDF_DATA

how can i solve this problem?

Thanks

Noor K Sejati

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers