Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reading a PDF data after uploading through GUI_UPLOAD

Former Member
0 Likes
5,746

Hello all,

I have a situation.

I am reading a PDF document using GUI_UPLOAD.

Now the contents in the internal table are in binary format in form of Astreiks and other characters

It is possible to convert the contents to the text format.

Because i have to read the contents and manipulate accordingly.

thanks in advance.

Regards,

Krishna

1 ACCEPTED SOLUTION
Read only

JerryWang
Product and Topic Expert
Product and Topic Expert
2,394

Hello friend,

as far as I know, if a PDF meets with following prerequisite, it is possible to extract text information from such PDF

1. a PDF which is rendered by ADS ( Adobe Document Service ). For example , all PDF rendered in SAP Business by Design is rendered by ADS.

2. a PDF which is interactive form. Actually from technical point of view, a interactive PDF consists of template ( xdp file ) and xml file. In the PDF generation the two is merged into PDF by ADS. So it is possible to extract text information ( xml format ) from such PDF.

You can use the following code to extract text information from such PDF.

PROGRAM fp_pdf_test_03.
* Extract data.

INCLUDE fp_utilities.

SELECTION-SCREEN BEGIN OF BLOCK s_files WITH FRAME TITLE text-100.
PARAMETERS: p_pdf TYPE localfile VISIBLE LENGTH 64 OBLIGATORY,
            p_xml TYPE localfile VISIBLE LENGTH 64 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK s_files.
SELECTION-SCREEN BEGIN OF BLOCK s_conn WITH FRAME TITLE text-101.
PARAMETERS p_dest TYPE rfcdest OBLIGATORY.
SELECTION-SCREEN END OF BLOCK s_conn.

DATA: l_fp     TYPE REF TO if_fp,
      l_pdfobj TYPE REF TO if_fp_pdf_object,
      l_pdf    TYPE xstring,
      l_data   TYPE xstring,
      l_fpex   TYPE REF TO cx_fp_runtime.

INITIALIZATION.
  MOVE cl_fp=>get_ads_connection( ) TO p_dest.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pdf.
  PERFORM value_help_for_file USING 'PDF' CHANGING p_pdf.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_xml.
  PERFORM value_help_for_output_file USING 'XML' CHANGING p_xml.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dest.
  PERFORM value_help_for_destination USING 'P_DEST'.

START-OF-SELECTION.

  PERFORM load_file USING p_pdf CHANGING l_pdf.

* Get FP reference.
  l_fp = cl_fp=>get_reference( ).

  TRY.
* Create PDF Object.
      l_pdfobj = l_fp->create_pdf_object( connection = p_dest ).

* Set document.
      l_pdfobj->set_document( pdfdata = l_pdf ).

* Tell PDF object to extract data.
      l_pdfobj->set_task_extractdata( ).

* Execute, call ADS.
      l_pdfobj->execute( ).

* Get the result.
      l_pdfobj->get_data( IMPORTING formdata = l_data ).

    CATCH cx_fp_runtime_internal
          cx_fp_runtime_system
          cx_fp_runtime_usage INTO l_fpex.
      PERFORM error USING l_fpex.
  ENDTRY.

* Download data.
  PERFORM download_file USING l_data p_xml.

Hello all,

I have a situation.

I am reading a PDF document using GUI_UPLOAD.

Now the contents in the internal table are in binary format in form of Astreiks and other characters

It is possible to convert the contents to the text format.

Because i have to read the contents and manipulate accordingly.

thanks in advance.

Regards,

Krishna

5 REPLIES 5
Read only

Former Member
0 Likes
2,394

Please check the following Program.

http://www.sapgenie.com/abap/code/abap51.htm

check out this sample code for uploading PDF file and downloading the same again.

REPORT y_pdf

NO STANDARD PAGE HEADING.

DATA: wf_filetab TYPE filetable .

DATA: wf_filerc TYPE i ,

wf_filename TYPE string ,

wf_filename1 TYPE string ,

wf_path TYPE string ,

wf_full_path TYPE string .

DATA: BEGIN OF int_tab1 OCCURS 0,

int_txt(300) TYPE x,

END OF int_tab1.

DATA: filelength TYPE i .

DATA: wf_extension TYPE string ,

wf_fname TYPE string .

PARAMETERS: p_file LIKE file_table-filename LOWER CASE VISIBLE LENGTH 80 .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file .

PERFORM browse_file CHANGING p_file .

START-OF-SELECTION .

CLEAR wf_filename .

MOVE: p_file TO wf_filename .

PERFORM load_file USING wf_filename .

perform download_file using wf_filename .

&----


*& Form browse_file

&----


  • text

----


  • <--P_P_FILE text

----


FORM browse_file CHANGING p_p_file.

CLEAR wf_filename .

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = 'Select the File'

  • DEFAULT_EXTENSION = cl_gui_frontend_services=>FILETYPE_TEXT

  • DEFAULT_FILENAME =

  • FILE_FILTER = cl_gui_frontend_services=>FILETYPE_EXCEL

  • INITIAL_DIRECTORY =

  • MULTISELECTION =

CHANGING

file_table = wf_filetab

rc = wf_filerc

  • USER_ACTION =

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 e398(00) WITH 'Error Opening File' .

ELSE .

READ TABLE wf_filetab INDEX 1 INTO p_file .

ENDIF.

ENDFORM. " browse_file

&----


*& Form load_file

&----


  • text

----


  • -->P_WF_FILENAME text

----


FORM load_file USING p_wf_filename.

CLEAR int_tab1 .

REFRESH int_tab1 .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_wf_filename

filetype = 'BIN'

IMPORTING

filelength = filelength

  • HEADER =

TABLES

data_tab = int_tab1

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

OTHERS = 17 .

ENDFORM. " load_file

&----


*& Form download_file

&----


  • text

----


  • -->P_WF_FIELNAME text

----


form download_file using p_wf_fielname.

replace all occurrences of '.pdf' in p_wf_fielname with 'new.pdf' .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE = filelength

filename = p_wf_fielname

FILETYPE = 'BIN'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH = FILELENGTH

TABLES

data_tab = int_tab1

  • FIELDNAMES = FIELDNAMES

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

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. " download_file

Read only

0 Likes
2,394

Hello Anurag,

I am already doing the same thing exactly as mentioned below.

But once you upload the PDF file the internal table contents will be in the Binary format. But i want to see the contents as text as i want to manipulate the data from PDF.

Is there any way ?

Thanks.

Read only

0 Likes
2,394

Hello Krishnakumar ,

I am facing the same problem .

I changed that Binary data into text by using SCMS_BINARY_TO_TEXT.

But it is not in readable format ( String ).

So, Did you solve this .If yes Let me know.

Regards,

B. Krishna.

Read only

JerryWang
Product and Topic Expert
Product and Topic Expert
2,395

Hello friend,

as far as I know, if a PDF meets with following prerequisite, it is possible to extract text information from such PDF

1. a PDF which is rendered by ADS ( Adobe Document Service ). For example , all PDF rendered in SAP Business by Design is rendered by ADS.

2. a PDF which is interactive form. Actually from technical point of view, a interactive PDF consists of template ( xdp file ) and xml file. In the PDF generation the two is merged into PDF by ADS. So it is possible to extract text information ( xml format ) from such PDF.

You can use the following code to extract text information from such PDF.

PROGRAM fp_pdf_test_03.
* Extract data.

INCLUDE fp_utilities.

SELECTION-SCREEN BEGIN OF BLOCK s_files WITH FRAME TITLE text-100.
PARAMETERS: p_pdf TYPE localfile VISIBLE LENGTH 64 OBLIGATORY,
            p_xml TYPE localfile VISIBLE LENGTH 64 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK s_files.
SELECTION-SCREEN BEGIN OF BLOCK s_conn WITH FRAME TITLE text-101.
PARAMETERS p_dest TYPE rfcdest OBLIGATORY.
SELECTION-SCREEN END OF BLOCK s_conn.

DATA: l_fp     TYPE REF TO if_fp,
      l_pdfobj TYPE REF TO if_fp_pdf_object,
      l_pdf    TYPE xstring,
      l_data   TYPE xstring,
      l_fpex   TYPE REF TO cx_fp_runtime.

INITIALIZATION.
  MOVE cl_fp=>get_ads_connection( ) TO p_dest.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pdf.
  PERFORM value_help_for_file USING 'PDF' CHANGING p_pdf.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_xml.
  PERFORM value_help_for_output_file USING 'XML' CHANGING p_xml.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dest.
  PERFORM value_help_for_destination USING 'P_DEST'.

START-OF-SELECTION.

  PERFORM load_file USING p_pdf CHANGING l_pdf.

* Get FP reference.
  l_fp = cl_fp=>get_reference( ).

  TRY.
* Create PDF Object.
      l_pdfobj = l_fp->create_pdf_object( connection = p_dest ).

* Set document.
      l_pdfobj->set_document( pdfdata = l_pdf ).

* Tell PDF object to extract data.
      l_pdfobj->set_task_extractdata( ).

* Execute, call ADS.
      l_pdfobj->execute( ).

* Get the result.
      l_pdfobj->get_data( IMPORTING formdata = l_data ).

    CATCH cx_fp_runtime_internal
          cx_fp_runtime_system
          cx_fp_runtime_usage INTO l_fpex.
      PERFORM error USING l_fpex.
  ENDTRY.

* Download data.
  PERFORM download_file USING l_data p_xml.

Read only

Former Member
0 Likes
2,394

Hi Jerry,

I have a similar requirement and I copied your code and executed the program. But I got below error.

ADS: com.adobe.ProcessingException: Error exporting Data into PDF - PDF Exception: Invalid object for the XFA entry in the forms dictionary

Please help me on this?

Thanks

Raghu