cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Sapscript to PDF

Former Member
0 Kudos

Hi,

I have to convert a sapscript to pdf but I don't know exactly how. I converted a smartform to pdf using the FM

CALL FUNCTION 'CONVERT_OTF_2_PDF'

EXPORTING

use_otf_mc_cmd = 'X'

IMPORTING

bin_filesize = L_PDF_LEN

TABLES

otf = OUTPUT_DATA-OTFDATA

doctab_archive = itab2

lines = l_t_pdfdata_tab

EXCEPTIONS

err_conv_not_possible = 1

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

But I don't know if it's the same to sapscript and how to obtain the data.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Here is the sample code.Kindly reward points if it helps.

REPORT zzz_jaytest .

  • Types Declaration

TYPES : BEGIN OF ty_pa0001,

pernr TYPE pa0001-pernr,

bukrs TYPE pa0001-bukrs,

werks TYPE pa0001-werks,

END OF ty_pa0001.

  • Internal Table Declaration

DATA : i_pa0001 TYPE STANDARD TABLE OF ty_pa0001, "For pa0001 Details

i_otf TYPE STANDARD TABLE OF itcoo, "For OTF data

i_content_txt TYPE soli_tab, "Content

i_content_bin TYPE solix_tab, "Content

i_objhead TYPE soli_tab,

  • Work Area Declaration

w_pa0001 TYPE ty_pa0001, "For pa0001 Details

w_res TYPE itcpp, "SAPscript output

"parameters

w_otf TYPE itcoo, "For OTF

w_pdf TYPE solisti1, "For PDF

w_transfer_bin TYPE sx_boolean, "Content

w_options TYPE itcpo, "SAPscript output

"interface

  • Variable Declaration

v_len_in TYPE so_obj_len,

v_size TYPE i.

  • Constants Declaration

CONSTANTS : c_x TYPE c VALUE 'X', "X

c_locl(4) TYPE c VALUE 'LOCL', "Local Printer

c_otf TYPE sx_format VALUE 'OTF', "OTF

c_pdf TYPE sx_format VALUE 'PDF', "PDF

c_printer TYPE sx_devtype VALUE 'PRINTER', "PRINTER

c_bin TYPE char10 VALUE 'BIN', "BIN

c_name TYPE string VALUE 'C:\ZZZ_JAYTEST.PDF',"Downloading

"File Name

c_form(11) TYPE c VALUE 'ZZZ_JAYTEST'. "Form Name

START-OF-SELECTION.

  • Selecting the records from pa0001

SELECT pernr bukrs werks FROM pa0001

INTO TABLE i_pa0001 UP TO 10 ROWS.

  • Setting the options

w_options-tdcopies = 1 ."Number of copies

w_options-tdnoprev = c_x."No print preview

w_options-tdgetotf = c_x."Return of OTF table

w_options-tddest = c_locl."Spool: Output device

  • Opening the form

CALL FUNCTION 'OPEN_FORM'

EXPORTING

form = c_form

device = c_printer

language = sy-langu

OPTIONS = w_options

IMPORTING

RESULT = w_res.

LOOP AT i_pa0001 INTO w_pa0001.

  • Writting into the form

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'MAIN'

window = 'MAIN'.

ENDLOOP.

  • Closing the form

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = w_res

TABLES

otfdata = i_otf

EXCEPTIONS

unopened = 1

bad_pageformat_for_print = 2

send_error = 3

spool_error = 4

codepage = 5

OTHERS = 6.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • Converting OTF data to single line

LOOP AT i_otf INTO w_otf.

CONCATENATE w_otf-tdprintcom w_otf-tdprintpar

INTO w_pdf.

APPEND w_pdf TO i_content_txt.

ENDLOOP.

  • Converting to PDF Format

CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'

EXPORTING

format_src = c_otf

format_dst = c_pdf

devtype = c_printer

CHANGING

transfer_bin = w_transfer_bin

content_txt = i_content_txt

content_bin = i_content_bin

objhead = i_objhead

len = v_len_in

EXCEPTIONS

err_conv_failed = 1

OTHERS = 2.

v_size = v_len_in.

  • Downloading the PDF File

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = v_size

filename = c_name

filetype = c_bin

TABLES

data_tab = i_content_bin.

Former Member
0 Kudos

Thanks a lot

Former Member
0 Kudos

Hi,

I tried this and generate the PDF but it has 0KB. I don't know what happend. Can you help me? 🐵

Thanks

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Are you sure that you used those things which I mentioned?

  • Setting the options

w_options-tdcopies = 1 ."Number of copies

w_options-tdnoprev = c_x."No print preview

w_options-tdgetotf = c_x."Return of OTF table

w_options-tddest = c_locl."Spool: Output device

  • Opening the form

CALL FUNCTION 'OPEN_FORM'

EXPORTING

form = c_form

device = c_printer

language = sy-langu

OPTIONS = w_options

IMPORTING

RESULT = w_res.

Former Member
0 Kudos

Ok Now it's works

Thanks

Message was edited by: Laura Portal

Answers (2)

Answers (2)

Former Member
0 Kudos

HI Laura Portal

Use this Function module to Convert SAP Script to PDF.

<b>SAMPLE CODE:</b>

CALL FUNCTION "CONVERT_OTF"

EXPORTING FORMAT = "PDF"

IMPORTING BIN_FILESIZE = FILE_LEN

TABLES OTF = OTFDATA

LINES = PDFDATA

EXCEPTIONS ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

Cheers,

Vijay Raheja

athavanraja
Active Contributor
0 Kudos

check demo program

RSTXPDFT4

RSTXPDF4

Regards

Raja

athavanraja
Active Contributor
0 Kudos

and check the following weblog for code samples.

/people/sap.user72/blog/2004/11/10/bsphowto-generate-pdf-output-from-a-bsp

Regards

Raja

Former Member
0 Kudos

I know that this FM can use in the sapscript but I don't know how, the samples are for smartforms but not for sapscript. So I don't know if OUTPUT_DATA-OTFDATA is the same in the sapscript

Former Member
0 Kudos

Have a look at these FM also

<b>CONVERT_OTFSPOOLJOB_2_PDF</b> ==== converts a OTF spool to PDF (i.e. Sapscript document)

<b>SX_OBJECT_CONVERT_OTF_PDF</b> ==== Conversion From OTF to PDF (SAPScript conversion)

Cheers,

Vijay Raheja

Former Member
0 Kudos

But in the sapscript where I obtain the data to convert to pdf. The variable OUTPUT_DATA-OTFDATA is the output of the sapscript so where I assign it?

Former Member
0 Kudos

Hi Laura Portal

Visit this link for SAMple code of SAPSCRIPT to PDF.:

http://www.sapgenie.com/abap/pdf_creation.htm

And if your requirement is to convert Sapscript spools request to PDF:

SAP have created a standard program <b>RSTXPDFT4</b> to convert your Sapscripts spools into a PDF format.

Specify the spool number and you will be able to download the sapscripts spool into your local harddisk.

Cheers,

Vijay Raheja