Introduction:
I came across a situation where on clicking the hyperlink in a webdynpro application a pdf of an adobe form to be generated and downloaded in the local system.
So I found the simplest way to make my work done using Webdynpro element(LinkToAction) and simple block of code for pdf generation.
Step1:
Create an adobe form to which pdf have to be generated.
The preview of our adobe form:
Step 2:
Now create a webdynpro application in which we want to call the form.
Give the description, save, check and activate the application.
Step 3:
Create a text view in the application for the text display purpose.
Right click on RootElementContainer and select insert element.
Give the ID and Select TextView from dropdown.
Give the text for property ‘text’.
Step 4:
Insert another UI element ‘LinkToAction’.
Click on create icon of ‘onAction’ property and give the name and description for action method.
Double click on the method and paste the following code:
METHOD onactionon_link_click .
DATA: lv_fmname TYPE fpname.
DATA: fp_docparams TYPE sfpdocparams.
DATA: fp_formoutput TYPE fpformoutput.
DATA : function TYPE funcname,
ftype TYPE fpinterfacetype,
fname TYPE funcname.
DATA : outputparams TYPE sfpoutputparams.
DATA: filename TYPE string,
path TYPE string,
fullpath TYPE string,
default_extension TYPE string VALUE 'PDF'.
**--OPEN JOB FOR ADOBE
outputparams-nodialog = 'X'.
outputparams-preview = 'X'.
outputparams-dest = 'LP01'.
outputparams-getpdf = 'X'.
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 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.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = 'ZADOBE_TEST'
IMPORTING
e_funcname = lv_fmname.
fp_docparams-langu = 'E'.
fp_docparams-country = 'IN'.
fp_docparams-fillable = 'X'.
fp_docparams-dynamic = 'X'.
CALL FUNCTION '/1BCDWB/SM00000135'
EXPORTING
/1BCDWB/DOCPARAMS = fp_docparams
IMPORTING
/1BCDWB/FORMOUTPUT = fp_formoutput
EXCEPTIONS
USAGE_ERROR = 1
SYSTEM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION 'FP_JOB_CLOSE' .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
cl_wd_runtime_services=>attach_file_to_response( i_filename = 'Adobeformgen.pdf'
i_content = fp_formoutput-pdf
i_mime_type = 'application/pdf' ).
ENDMETHOD.
Step 5:
Create the webdypro application and test it.
Activate and test.
The output in webynpro application.
Step 6:
Click on the hyperlink.
We can find the attachment saved in downloads folder of local desktop .
Note: Even after we can save the pdf in our desired location.
No comments:
Post a Comment