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: 

Multi-page PDF to external email.

Former Member
0 Kudos

Hi,

I wrote a program which takes a spool job, converts it to PDF and sends it to an external email. The program is successful except for one thing:

When the spool job is more than one page long, the PDF attachment is corrupt.

Has anyone experienced this before?

Thanks,

Ofer

7 REPLIES 7

Former Member
0 Kudos

hi,

provide the code it will be helpful to correct.

0 Kudos

The two relevant forms:

&----


*& Form CONVERT_TO_PDF

&----


  • Convert spool request p_spool into pdf format

----


FORM CONVERT_TO_PDF.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = P_SPOOL

NO_DIALOG = ' '

IMPORTING

PDF_BYTECOUNT = G_BYTES

TABLES

PDF = GT_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

OTHERS = 12.

IF SY-SUBRC <> 0.

PERFORM PRINT_SPOOL_REQUEST.

ENDIF.

LOOP AT GT_OUTPUT.

TRANSLATE GT_OUTPUT USING ' ~'.

CONCATENATE G_BUFFER GT_OUTPUT INTO G_BUFFER.

ENDLOOP.

TRANSLATE G_BUFFER USING '~ '.

DO.

GT_PDF = G_BUFFER.

APPEND GT_PDF.

SHIFT G_BUFFER LEFT BY 255 PLACES.

IF G_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

DESCRIBE TABLE GT_PDF LINES G_PDF_LINES.

ENDFORM. " CONVERT_TO_PDF_AND_DOWNLOAD

&----


*& Form SEND_EMAIL_WITH_PDF

&----


  • text

----


FORM SEND_EMAIL_WITH_PDF.

*get length of email text

DESCRIBE TABLE GT_BODY LINES G_BODY_LINES.

*gt_doc_data setup

*Subject Line

CONCATENATE 'Order # ' P_VBELN

INTO G_DOC_DATA-OBJ_DESCR.

G_DOC_DATA-SENSITIVTY = 'F'.

G_DOC_DATA-DOC_SIZE = G_BODY_LINES * 255.

*gt_packing setup

GT_PACK-TRANSF_BIN = ' '.

GT_PACK-HEAD_START = 1.

GT_PACK-HEAD_NUM = 0.

GT_PACK-BODY_START = 1.

GT_PACK-BODY_NUM = G_BODY_LINES.

GT_PACK-DOC_TYPE = 'RAW'.

APPEND GT_PACK.

CLEAR GT_PACK.

GT_PACK-TRANSF_BIN = 'X'.

GT_PACK-HEAD_START = 1.

GT_PACK-HEAD_NUM = 1.

GT_PACK-BODY_START = 1.

GT_PACK-BODY_NUM = G_PDF_LINES.

GT_PACK-DOC_TYPE = 'PDF'.

GT_PACK-DOC_SIZE = G_PDF_LINES * 255.

CONCATENATE P_VBELN '.pdf' INTO GT_PACK-OBJ_NAME.

*Filename

CONCATENATE 'Order' P_VBELN

INTO GT_PACK-OBJ_DESCR SEPARATED BY ' '.

APPEND GT_PACK.

CLEAR GT_PACK.

*gt_head setup

CONCATENATE 'Confirmation for Order' P_VBELN

INTO GT_HEAD SEPARATED BY ' '.

APPEND GT_HEAD.

CLEAR GT_HEAD.

*gt_receivers setup

GT_REC-RECEIVER = FAKE_EMAIL.

GT_REC-REC_TYPE = 'U'.

GT_REC-COM_TYPE = 'INT'.

APPEND GT_REC.

CLEAR GT_REC.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = G_DOC_DATA

PUT_IN_OUTBOX = ' '

TABLES

PACKING_LIST = GT_PACK

OBJECT_HEADER = GT_HEAD

CONTENTS_TXT = GT_BODY

CONTENTS_BIN = GT_PDF

RECEIVERS = GT_REC

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.

.

IF SY-SUBRC <> 0.

PERFORM PRINT_SPOOL_REQUEST.

ENDIF.

ENDFORM. " SEND_EMAIL_WITH_PDF

Former Member
0 Kudos

Hi,

Use the following code to convert spool job to pdf, this should work

DATA: spool TYPE tsp01-rqident,
            tab1 TYPE TABLE OF soli,
            otf TYPE TABLE OF itcoo,
            doc TYPE TABLE OF docs,
            size TYPE i,
           pdf TYPE TABLE OF tline,
        lv_pdfsource TYPE xstring,
pdf_line LIKE LINE OF pdf.

  FIELD-SYMBOLS: <p> TYPE x.

        spool = ls_spoollist-rqident.
        CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
          EXPORTING
            rqident              = spool
          TABLES
            buffer               = tab1
          EXCEPTIONS
            no_such_job          = 1
            job_contains_no_data = 2
            selection_empty      = 3
            no_permission        = 4
            can_not_access       = 5
            read_error           = 6
            type_no_match        = 7
            OTHERS               = 8.

   APPEND tab1 TO otf.

      CALL FUNCTION 'CONVERT_OTF_2_PDF'
        EXPORTING
          use_otf_mc_cmd         = 'X'
        IMPORTING
          bin_filesize           = size
        TABLES
          otf                    = otf
          doctab_archive         = doc
          lines                  = pdf
        EXCEPTIONS
          err_conv_not_possible  = 1
          err_otf_mc_noendmarker = 2
          OTHERS                 = 3.


      LOOP AT pdf INTO pdf_line.
        ASSIGN pdf_line TO <p> CASTING TYPE x.
        CONCATENATE lv_pdfsource <p> INTO lv_pdfsource IN BYTE MODE.
      ENDLOOP.

lv_pdfsource should have the desired PDF output

you can attach this to mail

Regards,

Kinshuk

0 Kudos

I should have stated that I am using 4.5B. Your code doesn't run for me. xstring is not recognized and neither is the field-symbol statement.

I'm pretty sure the problem is not with the pdf conversion, but rather with the attachment in the email function (maybe the packing?). I'm gonna do some more testing just to make sure this is true.

Former Member
0 Kudos

Try to use the Doc size returned by the function 'CONVERT_OTFSPOOLJOB_2_PDF' instead of G_BODY_LINES * 255 when assigning to G_DOC_DATA-DOC_SIZE

0 Kudos

That did not work either. But the problem is definitely in the conversion (from gt_output to gt_pdf). The conversion works for a one page document, but not for a multi page one.

If I try downloading instead of emailing, and I use gt_output (conerted pdf) along with size = g_bytes, it works for a one page, but not for a multi-page document.

Former Member
0 Kudos

The problem was in the conversion routine. The form table_shift in the following link does the job:

Edited by: Ofer Eckstein on Sep 24, 2008 4:09 PM