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: 

OTF to PDF conversion giving junk characters

Former Member
0 Kudos
1,175

Hey all,

We have a requirement to convert a smartform into a PDF and send it via email.

I have tried using CONVERT_OTF function module, but this gives me junk characters in the output table.

Example:


CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    format                = 'PDF'
    max_linewidth         = 132
  IMPORTING
    bin_filesize          = lv_binfilesize
    bin_file              = lv_bin_file
  TABLES
    otf                   = lt_otf
    lines                 = lt_tline
  EXCEPTIONS
    err_max_linewidth     = 1
    err_format            = 2
    err_conv_not_possible = 3
    err_bad_otf           = 4
    OTHERS                = 5.
IF sy-subrc <> 0.

ENDIF.

The table LT_TLINE gives me characters such as -- ⴱ⸳ഊ◢팍ਲ‰扪ഊ㰼ഊ

What might be the reason, and how can i overcome this?

Due to this we are not able to send mails since it dumps.

Any help would be highly appreciated!

Thanks in advance!

19 REPLIES 19

Former Member
0 Kudos
374

Are you using any other languanges in the Smartform display?

0 Kudos
374

No, it is just english...

0 Kudos
374

Hi,

Just work with the line width and see if that helps in any way.

Thanks,

Shambu

Former Member
0 Kudos
374

Use function module CONVERT_OTF_2_PDF

Former Member
0 Kudos
374

Hi,

Yuo can Use FM SX_OBJECT_COVERT_OTF_PDF ,IF you have to send it through mail.

Regards

Ajit

0 Kudos
374

Hi Veena,

Please follow this link.

http://scn.sap.com/thread/1737091

0 Kudos
374

I have used CONVERT_OTF_2_PDF as well.. But it gives the same junk values.

0 Kudos
374

Hi Ajit,

The function module you mentioned, uses CONVERT_OTF itself.

0 Kudos
374

In smartforms attribute section check if you translate to all languages option chosen.

0 Kudos
374

Hi Pratik,

Yes, it is selected. But what has that got to do with getting junk data in the output of CONVERT_OTF?

0 Kudos
374

nothing..just a hunch...

I had an old piece of code..see if it helps...

* Internal Table declarations

DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,

I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

* Objects to send mail.

I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

I_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

* Work Area declarations

WA_OBJHEAD TYPE SOLI_TAB,

W_CTRLOP TYPE SSFCTRLOP,

W_COMPOP TYPE SSFCOMPOP,

W_RETURN TYPE SSFCRESCL,

WA_DOC_CHNG TYPE SODOCCHGI1,

W_DATA TYPE SODOCCHGI1,

WA_BUFFER TYPE STRING,”To convert from 132 to 255

* Variables declarations

V_FORM_NAME TYPE RS38L_FNAM,

V_LEN_IN LIKE SOOD-OBJLEN,

V_LEN_OUT LIKE SOOD-OBJLEN,

V_LEN_OUTN TYPE I,

V_LINES_TXT TYPE I,

V_LINES_BIN TYPE I.

CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’

EXPORTING

FORMNAME = ‘ZTEST’

IMPORTING

FM_NAME = V_FORM_NAME

EXCEPTIONS

NO_FORM = 1

NO_FUNCTION_MODULE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

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

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

ENDIF.

W_CTRLOP-GETOTF = ‘X’.

W_CTRLOP-NO_DIALOG = ‘X’.

W_COMPOP-TDNOPREV = ‘X’.

CALL FUNCTION V_FORM_NAME

EXPORTING

CONTROL_PARAMETERS = W_CTRLOP

OUTPUT_OPTIONS = W_COMPOP

USER_SETTINGS = ‘X’

IMPORTING

JOB_OUTPUT_INFO = W_RETURN

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 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.

I_OTF[] = W_RETURN-OTFDATA[].

CALL FUNCTION ‘CONVERT_OTF’

EXPORTING

FORMAT = ‘PDF’

MAX_LINEWIDTH = 132

IMPORTING

BIN_FILESIZE = V_LEN_IN

TABLES

OTF = I_OTF

LINES = I_TLINE

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

* Fehlerhandling

IF SY-SUBRC <> 0.

ENDIF.

LOOP AT I_TLINE.

TRANSLATE I_TLINE USING ‘~’.

CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.

ENDLOOP.

TRANSLATE WA_BUFFER USING ‘~’.

DO.

I_RECORD = WA_BUFFER.

APPEND I_RECORD.

SHIFT WA_BUFFER LEFT BY 255 PLACES.

IF WA_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

* Attachment

REFRESH:

I_RECLIST,

I_OBJTXT,

I_OBJBIN,

I_OBJPACK.

CLEAR WA_OBJHEAD.

I_OBJBIN[] = I_RECORD[].

o

+

#

*

o

+ Create Message Body

# Title and Description

I_OBJTXT = ‘test with pdf-Attachment!’.

APPEND I_OBJTXT.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

READ TABLE I_OBJTXT INDEX V_LINES_TXT.

WA_DOC_CHNG-OBJ_NAME = ’smartform’.

WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

WA_DOC_CHNG-OBJ_DESCR = ’smartform’.

WA_DOC_CHNG-SENSITIVTY = ‘F’.

WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

# Main Text

* wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + strlen( i_objtxt )

*.

CLEAR I_OBJPACK-TRANSF_BIN.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

I_OBJPACK-BODY_NUM = V_LINES_TXT.

I_OBJPACK-DOC_TYPE = ‘RAW’.

APPEND I_OBJPACK.

o

+

# Attachment

* (pdf-Attachment)

I_OBJPACK-TRANSF_BIN = ‘X’.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

* Länge des Attachment ermitteln

DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

READ TABLE I_OBJBIN INDEX V_LINES_BIN.

I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

I_OBJPACK-BODY_NUM = V_LINES_BIN.

I_OBJPACK-DOC_TYPE = ‘PDF’.

I_OBJPACK-OBJ_NAME = ’smart’.

I_OBJPACK-OBJ_DESCR = ‘test’.

APPEND I_OBJPACK.

CLEAR I_RECLIST.

I_RECLIST-RECEIVER = ‘email id’.

I_RECLIST-REC_TYPE = ‘U’.

APPEND I_RECLIST.

CALL FUNCTION ‘SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WA_DOC_CHNG

PUT_IN_OUTBOX = ‘X’

TABLES

PACKING_LIST = I_OBJPACK

OBJECT_HEADER = WA_OBJHEAD

CONTENTS_BIN = I_OBJBIN

CONTENTS_TXT = I_OBJTXT

RECEIVERS = I_RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

DOCUMENT_TYPE_NOT_EXIST = 3

OPERATION_NO_AUTHORIZATION = 4

PARAMETER_ERROR = 5

X_ERROR = 6

ENQUEUE_ERROR = 7

OTHERS = 8.

Another EXample

you may use the FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF' to convert the fom

into PDF.

But first to get the printed form from the spool, use FUNCTION

'RSPO_FIND_SPOOL_REQUESTS'.

Then you may send it to your PC, email, fax, etc by reading the record in

the lines of table IT_PDF_OUTPUT.

Note: You may also use program RSTXPDFT4 as a reference to get code

examples which uses different functions to perform the creation of PDFand

download the form to the PC,etc.

CALL FUNCTION 'RSPO_FIND_SPOOL_REQUESTS'

EXPORTING

RQOWNER = SY-UNAME

TABLES

SPOOLREQUESTS = SPOOL_REQUESTS.

READ TABLE SPOOL_REQUESTS INDEX 1.

GD_SPOOL_NR = SPOOL_REQUESTS-RQIDENT.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = GD_SPOOL_NR

NO_DIALOG = C_NO

IMPORTING

PDF_BYTECOUNT = GD_BYTECOUNT

PDF_SPOOLID = PDFSPOOLID

BTC_JOBNAME = JOBNAME

BTC_JOBCOUNT = JOBCOUNT

TABLES

PDF = IT_PDF_OUTPUT

EXCEPTIONS

ERR_NO_OTF_SPOOLJOB = 1

ERR_NO_SPOOLJOB = 2

ERR_NO_PERMISSION = 3

ERR_CONV_NOT_POSSIBLE = 4

ERR_BAD_DSTDEVICE = 5

USER_CANCELLED = 6

ERR_SPOOLERROR = 7

ERR_TEMSEERROR = 8

ERR_BTCJOB_OPEN_FAILED = 9

ERR_BTCJOB_SUBMIT_FAILED = 10

ERR_BTCJOB_CLOSE_FAILED = 11.

CHECK SY-SUBRC = 0.

0 Kudos
374

Hi all,

After using CONVERT_OTF, i used GUI_DOWNLOAD, and the file was opening as a PDF.

However, when im trying to send it via email, it gives an error while trying to open the PDF saying "The file is damaged..."

Any ideas why?

0 Kudos
374

Are you passing the file size in the FM which sends the email?

You need to pass the document size also.

0 Kudos
374

Yes i am...

Former Member
0 Kudos
374

Hi veena that will surely give junk.

As

CALL FUNCTION 'CONVERT_OTF' 

    max_linewidth         = 132

max line width is 132 but For PDF it should be 255.

So after that you need to convert   max_linewidth   from 132 to 255 .

You can use below sample code.


FORM OTF_CONVERT .

DATA: WA_BUFFER      TYPE  STRING,

      WA_IT_RECORD   TYPE  SOLISTI1,

      IT_RECORD  TYPE STANDARD TABLE OF  SOLISTI1.

CALL FUNCTION 'CONVERT_OTF'

  EXPORTING

   FORMAT                      = 'PDF'

  MAX_LINEWIDTH               = 132

  ARCHIVE_INDEX               = ' '

  COPYNUMBER                  = 0

  ASCII_BIDI_VIS2LOG          = ' '

  PDF_DELETE_OTFTAB           = ' '

  IMPORTING

   BIN_FILESIZE                = BINFILESIZE

*  BIN_FILE                    =

TABLES

   OTF                         = IT_OTF[]

   LINES                       = PDFTAB[]

EXCEPTIONS

   ERR_MAX_LINEWIDTH           = 1

   ERR_FORMAT                  = 2

   ERR_CONV_NOT_POSSIBLE       = 3

   ERR_BAD_OTF                 = 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.

  ELSE.

* Convert PDF from 132 to 255.

    LOOP AT PDFTAB.

      TRANSLATE PDFTAB USING ' ~'.      " Replacing space by ~

      CONCATENATE WA_BUFFER PDFTAB INTO WA_BUFFER.

    ENDLOOP.

    TRANSLATE WA_BUFFER USING '~ '.         " Replacing space by ~

    DO.

 

      WA_IT_RECORD = WA_BUFFER.

      APPEND WA_IT_RECORD TO IT_RECORD.     " Appending 255 characters as a record

      SHIFT WA_BUFFER LEFT BY 255 PLACES.

      IF WA_BUFFER IS INITIAL.

        EXIT.

      ENDIF.

    ENDDO.

    ENDIF.

     REFRESH:OBJBIN.

* Object with PDF.

    OBJBIN[] = IT_RECORD[].

    DESCRIBE TABLE OBJBIN LINES TAB_LINES.

ENDFORM.                    " OTF_CONVERT


0 Kudos
374

veena try this it will surely solve your problem.

thers no need to use GUI download if you dont want to download file.

And in My sample code Instead of using PDFTAB use lt_tline.

0 Kudos
374

Hey Hasan,

I have tried the above code, but it still gives junk characters.

Former Member
0 Kudos
374

I assume that you did your SmartForm call with parameters similar to this:

   data: gt_job_info   type ssfcrescl,

. . .

SmartForms call:

   importing
          job_output_info    = gt_job_info  " to get your OTF?

then for your conversion:

   tables
      otf                   = gt_job_info-otfdata

My experience is that just using the table name fails...you have to point to the otfdata in the otf table.

Former Member
0 Kudos
374

Problem solved.

I have used CL_BCS for sending an email.

Thanks!