Guardar archivo en formato PDF

11 01 2010

Con el siguiente código podremos generar archivos PDF.

Ya que con la función GUI_DOWNLOAD únicamente no se puede hacer. Previamente hay que realizar una conversión para luego sí guardar el fichero .PDF.


 

*&—————————————————————–*
*& Report  Y_TEST
*&
*&—————————————————————–*
*&
*&
*&—————————————————————–*

REPORT y_test NO STANDARD PAGE HEADING.

**********************************************************************
*  Definición de variables                                                                   *
**********************************************************************

DATA: filesize  TYPE i, 
          header  LIKE thead,
          options  LIKE itcpo,
          result    LIKE itcpp, 
          otf        LIKE itcoo OCCURS 0 WITH HEADER LINE, 
          lines     LIKE tline OCCURS 0 WITH HEADER LINE,
          lv_file   TYPE string.

**********************************************************************
*  Definición de la pantalla de selección                                              *
**********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK blq1 WITH FRAME TITLE text-t01.
PARAMETERS:
  p_impre TYPE pri_params-pdest OBLIGATORY,
  p_file  TYPE rlgrap-filename OBLIGATORY DEFAULT ‘C:\PRUEBA.PDF’.
SELECTION-SCREEN END OF BLOCK blq1.

 

**********************************************************************
*  Proceso principal                                                                           *
**********************************************************************

*Se completa tabla lines con el contenido que queramos que tenga el archivo PDF
lines-tdline = ‘Este es el texto que aparecerá en el archivo PDF’.
lines-tdformat = ‘K’.
APPEND lines.

*Se obtienen y definen las opciones de formato del archivo
options-tddest = p_impre. "Nombre de impresora local
options-tdnewid = ‘X’.
options-tdgetotf = ‘X’.

CALL FUNCTION ‘PRINT_TEXT’
EXPORTING
    device           = ‘PRINTER’
    dialog           = ‘ ‘
    application    = ‘TX’
    header          = header
    options         = options
IMPORTING 
    result         = result 
TABLES 
    lines          = lines
    otfdata      = otf
EXCEPTIONS
    canceled     = 01
    device        = 02
    form          = 03 
    options      = 04
    unclosed    = 05
    unknown    = 06
    format       = 07
    textformat  = 08
    communication = 09.

* Se convierte a PDF
CALL FUNCTION ‘CONVERT_OTF’
EXPORTING
    format                = ‘PDF’
    max_linewidth     = 132
IMPORTING
    bin_filesize          = filesize
TABLES
    otf                    = otf
    lines                 = lines
EXCEPTIONS
    err_conv_not_possible = 1.

* Bajamos el archivo
lv_file = p_file.

CALL FUNCTION ‘GUI_DOWNLOAD’
EXPORTING
     bin_filesize = filesize
     filename = lv_file
     filetype = ‘BIN’
* APPEND = ‘ ‘
* CODEPAGE = ‘ ‘
* NO_BYTEORDER_MARK = ‘ ‘
* IMPORTING
* FILELENGTH = c
TABLES
     data_tab = lines
* FORMAT_TAB =
EXCEPTIONS 
     file_write_error = 1
     no_batch = 2
     gui_refuse_filetransfer = 3
     invalid_type = 4
     no_authority = 5
     unknown_error = 6.


Technorati tags:








Seguir

Get every new post delivered to your Inbox.

Únete a otros 31 seguidores