Embed
Email

Imprimir PDF en WebDynpro para JAVA sin utilizar Interactive

Document Sample
Imprimir PDF en WebDynpro para JAVA sin utilizar Interactive
Imprimir PDF en WebDynpro para JAVA sin utilizar Interactive Forms en llamadas RFC.



Se puede imprimir un pdf utilizando una llamada RFC el cual entregará el pdf vía una variable

binaria.



Entonces si en sap generamos un smartform (tran. SMARTFORMS) lo convertimos a PDF, y lo

enviamos vía un parámetro export en una función RFC, el WebDynpro Java es capaz de

interpretarlo y desplegarlo como un archivo Adobe PDF.



En SAP



Si tenemos el siguiente smartform ZWEBDYNPRO_TEST









Entonces generamos el módulo de función (SE37) de tipo RFC, con el siguiente parámetro

export:

En código fuente:



FUNCTION Z_WEBDYNPRO_PDF_TEST .

*"----------------------------------------------------------------------

*"*"Local Interface:

*" EXPORTING

*" VALUE(BIN_FILE) TYPE XSTRING

*"----------------------------------------------------------------------

DATA : lv_fnam TYPE rs38l_fnam,

gs_control TYPE ssfctrlop,

gs_output_options TYPE ssfcompop,

gs_otfdata TYPE itcoo,

gs_job_output_info TYPE ssfcrescl,

gt_otfdata TYPE STANDARD TABLE OF itcoo INITIAL SIZE 0.



* get smartform

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZWEBDYNPRO_TEST'

IMPORTING

fm_name = lv_fnam

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.



CLEAR gs_job_output_info.



CLEAR gs_job_output_info-otfdata.



MOVE : 'X' TO gs_control-no_dialog,

'X' TO gs_control-getotf,

'LP01'(047) TO gs_output_options-tddest.



CALL FUNCTION lv_fnam

EXPORTING

control_parameters = gs_control

output_options = gs_output_options

user_settings = space

IMPORTING

job_output_info = gs_job_output_info

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.



*Populate OTF data table



LOOP AT gs_job_output_info-otfdata INTO gs_otfdata.

APPEND gs_otfdata TO gt_otfdata.

CLEAR gs_otfdata.

ENDLOOP. " LOOP AT t_outtab-otfdata



DATA: lv_bytes TYPE p,

lv_bin_file TYPE xstring,

gt_pdfdata TYPE STANDARD TABLE OF tline INITIAL SIZE 0.



* Convert OTF into PDF

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

* max_linewidth = 800

IMPORTING

bin_filesize = lv_bytes

bin_file = bin_file

TABLES

otf = gt_otfdata

lines = gt_pdfdata

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.



ENDFUNCTION.



En WebDynpro Java (SAP DEVELOPER STUDIO)



Creamos el proyecto WebDynpro TestPdf

Creamos modelo TestPdfModel (Adaptative RFC Model).









Nos conectamos al servidor SAP correspondiente e importamos función

Z_WEBDYNPRO_PDF_TEST.

Entonces tenemos









Creamos componente TestPdfComp

Agregamos TestPdfModel en Used Models

Creamos el TestPdfCust Custom Controller









Editamos el model binding en TestPdfCust (se puede realizar en el Diagram View del

componente TestPdfComp)

Ahora editamos el Context Mapping de la vista TestPdfView (creada al crear el componente)

En contexto de vista TestPdfView, creamos nodo internal con value attribute url de tipo string.









Ojo que la cardinalidad de internal es 1..1

Ahora en layout de vista insertamos un Iframe









En source indicamos Internal.url

Este WebDynpro está diseñado para llamar automáticamente a la función RFC en SAP, por lo

tanto en el implementation de la vista TestPdfVie, agregamos en wdDoInit:



try {

// Calls remote function module

wdContext.currentZ_Webdynpro_Pdf_Test_InputElement().modelObject().execu

te();

// Synchronise the data in the context with the data in the model

wdContext.nodeOutput().invalidate();

} catch (Exception ex) {

// If an exception is thrown, then the stack trace will be printed

ex.printStackTrace();

}









Ahora debemos tomar la variable Bin_File de tipo byte[] y transformarla a string (Url):



byte[] pdfContent =

wdContext.currentOutputElement().getBin_File();

IWDCachedWebResource pdfResource =

WDWebResource.getWebResource(pdfContent,WDWebResourceType.PDF); //this

line will convert that byte array into pdf form



try{

wdContext.currentInternalElement().setUrl(pdfResource.getURL());

//Pdf ur l is a value attribute in the context of type string . bind

this string attribute to Iframe or adobe interactive form.

}catch (Exception e) {

wdComponentAPI.getMessageManager().reportException(e.getMessage(

),true);

}



Si da error de sintaxis, utilizar menú contextual Source Organize Imports.



Finalmente creamos aplicación TestPdfApp

Hacemos el deploy & run, lo más posible es que surja el siguiente error:

java.lang.NullPointerException









Esto es porque nos falto agregar en el implementation del TestPdfCust



public void wdDoInit()

{

//@@begin wdDoInit()

Z_Webdynpro_Pdf_Test_Input input = new Z_Webdynpro_Pdf_Test_Input();

wdContext.nodeZ_Webdynpro_Pdf_Test_Input().bind(input);



//@@end

}









Entonces ahora:


Related docs
Other docs by Sarahsinthekin...
Pathways brochure.pub
Views: 7  |  Downloads: 0
CONTAINERS BROCHURE
Views: 17  |  Downloads: 0
2009 Road Show Brochure 8-4-09
Views: 20  |  Downloads: 0
SBR Forms in scope testing schedule
Views: 4  |  Downloads: 0
Brochure 09.qxp
Views: 2  |  Downloads: 0
MLA 2009 Fall Meeting Registration Brochure
Views: 39  |  Downloads: 0
EFT Brochure
Views: 26  |  Downloads: 0
2008 brochure.indd
Views: 9  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!