Вы находитесь на странице: 1из 14

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 va una variable binaria. Entonces si en sap generamos un smartform (tran. SMARTFORMS) lo convertimos a PDF, y lo enviamos va un parmetro export en una funcin 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 mdulo de funcin (SE37) de tipo RFC, con el siguiente parmetro export:

En cdigo 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 funcin 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 diseado para llamar automticamente a la funcin RFC en SAP, por lo tanto en el implementation de la vista TestPdfVie, agregamos en wdDoInit:
// te(); // try { Calls remote function module wdContext.currentZ_Webdynpro_Pdf_Test_InputElement().modelObject().execu 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 aplicacin TestPdfApp

Hacemos el deploy & run, lo ms 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:

Вам также может понравиться