on 06-16-2011 11:38 AM
Hi .
I am new to ABAP & Smartform.I have a requirement to convert smartform PDF to Base 64.I've tried the methods provided in the related SDN threads.But while decoding , junk characters are coming.Please find my code below :
**************************************
Convert SF output to PDF format
*convert the smartform to .pdf file
**************************************
DATA : I_DOC TYPE TABLE OF DOCS,
WA_DOC TYPE DOCS,
L_PDF_STRING TYPE XSTRING.
I_OTFDATA[] = ST_JOB_OUTPUT_INFO-OTFDATA[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
IMPORTING
BIN_FILESIZE = V_BIN_FILESIZE
BIN_FILE = L_PDF_STRING
TABLES
OTF = I_OTFDATA
LINES = I_LINES.
Convert Table i_bin to base64 encoding
DATA : I_BASE64 TYPE STANDARD TABLE OF SOLISTI1,
WA_BASE64 TYPE SOLISTI1,
WA_LINES TYPE TLINE.
DATA: LV_OUTPUT(255) TYPE C,
LV_INPUT(132) TYPE C,
LV_X(255) TYPE X,
LV_I TYPE I.
DATA: CONV TYPE REF TO CL_ABAP_CONV_OUT_CE.
LOOP AT I_LINES INTO WA_LINES.
LV_INPUT = WA_LINES-TDLINE.
LV_I = STRLEN( LV_INPUT ).
CONDENSE lv_input.
IF LV_I > 0.
TRY.
CALL METHOD CL_ABAP_CONV_OUT_CE=>CREATE
EXPORTING
ENCODING = 'UTF-8'
ENDIAN = 'L'
replacement = '#'
ignore_cerr = ABAP_FALSE
RECEIVING
CONV = CONV .
CATCH CX_PARAMETER_INVALID_RANGE .
CATCH CX_SY_CODEPAGE_CONVERTER_INIT .
ENDTRY.
CALL METHOD CONV->WRITE
EXPORTING
N = LV_I
DATA = LV_INPUT
view =
IMPORTING
len =
.
LV_X = CONV->GET_BUFFER( ).
CALL FUNCTION 'HTTP_BASE64_ENCODE'
EXPORTING
INPUT = LV_X
INPUT_LENGTH = LV_I
IMPORTING
OUTPUT = LV_OUTPUT.
Append to Table
WA_BASE64-LINE = LV_OUTPUT.
APPEND WA_BASE64 TO I_BASE64.
CLEAR : LV_OUTPUT, LV_X, LV_I, WA_BASE64, WA_LINES.
ENDIF.
ENDLOOP.
***********************************************************************************************
Thanks,
Jayita Ganguly
Hello
Please refer to the following SAP note regarding conversion - 999712 - PDF conversion for Unicode
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jayita Ganguly,
I have a requirement to convert smartform PDF to Base 64.I've tried the methods provided in the related SDN threads.But while decoding , junk characters are coming
If you encode and decode, then you revert back to the original PDF, which is a binary stream. So it's normal you get weird characters if you try to display it as characters! But maybe you didn't give enough information about where you got the junk characters!?
Sandra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Sandra ,
For decoding we are using the following link where binary file is created but unable to open that in PDF.
http://www.opinionatedgeek.com/dotnet/tools/Base64Decode/Default.aspx
Thanks,
Jayita
Hi,
I have removed the encoding but the Output is Null only series of AAAAAAAAAAAAAAAAAAAA coming in BASE 64 conversion.
Please find below my new code ..
It would be helpful if you can provide me the exact code for conversion.
LOOP AT I_PDF to WA_PDF .
LV_X = WA_PDF-TDLINE .
CALL FUNCTION 'HTTP_BASE64_ENCODE'
EXPORTING
INPUT = LV_X
INPUT_LENGTH = LV_I
IMPORTING
OUTPUT = LV_OUTPUT.
Write : / LV_OUTPUT.
ENDLOOP.
Hi,
LV_X = WA_PDF-TDLINE.
As WA_PDF-TDLINE is type C, and LV_X is type X, it does a conversion BUT it is not what you expect: LV_X = 'RMjlùIOJM%8RUZ3T', it will set LV_X = all zeroes as 'RM...' does not start with an hexadecimal string (and so base 64 would return AAAAAA). See the ABAP doc for more info.
Moreover, base 64 encoding must be done with the whole byte stream (more precisely you must not split it outside chunks of 3 bytes, as this encoding converts 3 bytes into 4 characters, converting 2 bytes makes no sense for example, except at the end of the stream).
I advise you to use CL_HTTP_UTILITY=>ENCODE_BASE64 which converts a string which is casted as bytes. Before, you must concatenate the lines into a string, either using CONCATENATE LINES OF lt_char INTO l_target RESPECTING BLANKS, or SWA_STRING_FROM_TABLE (keep_trailing_spaces='X') depending on your release. Don't forget to shorten the string at exactly the number of representative characters (LV_I in your example).
BR
Sandra
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.