Application Development 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: 

How to convert a pdf file into hexadecimal in abap.

SVT
Explorer
0 Kudos
2,046

Hi guys,

I need your valuable replies here,

My requirement is

1.Upload a pdf file into a abap program.

2.Convert into Hexadecimal format .

3.Send it to the client.

I'm using gui_upload to upload my invoice file into abap.

Getting the input values in a internal table.(172 lines are coming now).

Looping the internal table and converting each line into xstring.

FM : SCMS_STRING_TO_XSTRING

Appending all into a Xsrting.

CONCATENATE lv_xstrin_format lv_xpdf into lv_xstrin_format IN BYTE MODE.

Like this.

If I use the file string in the site https://tomeko.net/online_tools/hex_to_file.php?lang=en to convert into pdf file ,its not working for me.

Showing error as ,unable to open the file.



So I want the correct steps to upload a pdf and convert into hexadecimal format and again convert into PDF .

Thanks in advance.



1 ACCEPTED SOLUTION

SVT
Explorer
0 Kudos
1,878

Working program:

Types : BEGIN OF ty_tab,
tdline type string,
END OF ty_tab.


DATA : it_pdf type table of tdline.

DATA : lv_len type int4.

"Upload pdf file

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING
filename = lv_name "File name with full path 'C:\folder1\Invoice.PDF'
filetype = 'BIN'
IMPORTING
filelength = lv_len
TABLES
data_tab = it_pdf
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.
IF sy-subrc <> 0.

ENDIF.

"Convertion

DATA : lv_xstring type xstring.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_len
FIRST_LINE = 0
LAST_LINE = 0
IMPORTING
BUFFER = lv_xstring
tables
binary_tab = it_pdf
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


This is working for me now, If I upload the lv_string in the below website. Able to get the pdf file.

https://tomeko.net/online_tools/hex_to_file.php?lang=en ==>Convert xstring to pdf website.


Thanks for your replies.



8 REPLIES 8

raymond_giuseppi
Active Contributor
0 Kudos
1,878

You convert a PDF to an HEX string to convert it to PDF, I'm puzzled and not really sure I understood your requirement?

raymond_giuseppi
Active Contributor
0 Kudos
1,878

Does the tool require an Abap XSTRING flow or a Human Readable Hexadecimal display of this flow (I'd go for the second option)

  • In this case the hexadecimal input should begin with "25504446" (actually %PDF)

Tomas_Buryanek
Active Contributor
0 Kudos
1,878

Can you share simplified code for these steps below? And how are you calling BIN_UPLOAD (parameters + values)? These two places are where many beginner developers are doing mistakes, when working with binary data. Another question is documentation from client where it really says they want PDF in "hexadecimal" format?

Getting the input values in a internal table.(172 lines are coming now).
Looping the internal table and converting each line into xstring.
FM : SCMS_STRING_TO_XSTRING
Appending all into a Xsrting.
-- Tomas --

Sandra_Rossi
Active Contributor
1,878

I guess this part of your program is buggy: "Upload a pdf file into a abap program".

You should not upload to a STRING. You should upload to an XSTRING directly (or via table of X ==> XSTRING / Never do it via table of C)

SVT
Explorer
0 Kudos
1,878

Yes ,I should upload it directly to a xstring table.

Issue has been resolved.

SVT
Explorer
0 Kudos
1,879

Working program:

Types : BEGIN OF ty_tab,
tdline type string,
END OF ty_tab.


DATA : it_pdf type table of tdline.

DATA : lv_len type int4.

"Upload pdf file

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING
filename = lv_name "File name with full path 'C:\folder1\Invoice.PDF'
filetype = 'BIN'
IMPORTING
filelength = lv_len
TABLES
data_tab = it_pdf
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.
IF sy-subrc <> 0.

ENDIF.

"Convertion

DATA : lv_xstring type xstring.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_len
FIRST_LINE = 0
LAST_LINE = 0
IMPORTING
BUFFER = lv_xstring
tables
binary_tab = it_pdf
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


This is working for me now, If I upload the lv_string in the below website. Able to get the pdf file.

https://tomeko.net/online_tools/hex_to_file.php?lang=en ==>Convert xstring to pdf website.


Thanks for your replies.



Sandra_Rossi
Active Contributor
1,878

Again, please edit both your answer and your question (Actions>Edit), select your code and press the button [CODE], which makes the code appear colored/indented, it'll be easier for people to look at it. Thanks!

Instead of the weird old SCMS_BINARY_TO_XSTRING, I recommend this shorter form:

DATA it_pdf type solix_tab.

CALL FUNCTION 'GUI_UPLOAD'
  ...
  IMPORTING
    filelength = lv_len
  TABLES
    data_tab = it_pdf
  ...

data(xstring) = cl_bcs_convert=>solix_to_xstring( IT_SOLIX = it_pdf IV_SIZE = lv_len ).

Sandra_Rossi
Active Contributor
0 Kudos
1,878

Hopefully it's not an "xstring table", just a xstring elementary variable.