2015 Jul 09 10:15 AM
Hi Experts,
I have requirement to copy the image from HTML display.
The Third party sending the HTML files to SAP server. I want to execute the file from SAP.
I did this using CL_GUI_HTML_VIEWER. In that file output is QR barcode.
Its showing in preview correctly.
But requirement is I want to print that QR code in smartforms.
How to get the QR code image from preview to code level?
code below
*&---------------------------------------------------------------------*
*& Report zRSDEMO_HTML_VIEWER *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT zRSDEMO_HTML_VIEWER.
DATA OK_CODE TYPE SY-UCOMM.
DATA SAVE_OK TYPE SY-UCOMM.
DATA INIT.
DATA SHOW_URL(255).
DATA MY_URL(255).
DATA LIFETIME TYPE I.
DATA HTML_VIEWER TYPE REF TO CL_GUI_HTML_VIEWER.
* class definition for OO event handler
CLASS LCL_EVENT_RECEIVER DEFINITION." INHERITING FROM CL_GUI_HTML_VIEWER.
PUBLIC SECTION.
CLASS-METHODS NAVIGATECOMPLETE
FOR EVENT NAVIGATE_COMPLETE OF CL_GUI_HTML_VIEWER
IMPORTING URL
SENDER.
METHODS: GENERATE_HTML_BUTTON,
ON_SAPEVENT
FOR EVENT SAPEVENT OF CL_GUI_HTML_VIEWER
IMPORTING ACTION " Action from button
FRAME
GETDATA
POSTDATA
QUERY_TABLE. " Additional parameters
ENDCLASS. "lcl_event_receiver DEFINITION
DATA: LO_REPORT TYPE REF TO LCL_EVENT_RECEIVER.
* class implementation for OO event handler
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD NAVIGATECOMPLETE.
MESSAGE S300(EU) WITH URL. "#EC NOTEXT
MY_URL = URL. "evtl. zur Demonstration System-/Applikationsevent
ENDMETHOD. "navigatecomplete
METHOD ON_SAPEVENT.
DATA: LS_QUERY_TABLE LIKE LINE OF QUERY_TABLE.
DATA: LV_STRING TYPE STRING.
CASE ACTION.
WHEN 'MY_BUTTON_1'.
LV_STRING = 'HTML button says: '.
READ TABLE QUERY_TABLE INTO LS_QUERY_TABLE WITH KEY NAME = 'PARAM1'.
CONCATENATE LV_STRING LS_QUERY_TABLE-VALUE
INTO LV_STRING
SEPARATED BY SPACE.
READ TABLE QUERY_TABLE INTO LS_QUERY_TABLE WITH KEY NAME = 'PARAM2'.
CONCATENATE LV_STRING LS_QUERY_TABLE-VALUE
INTO LV_STRING
SEPARATED BY SPACE.
MESSAGE LV_STRING TYPE 'I'.
ENDCASE.
*
ENDMETHOD. "on_sapevent
METHOD GENERATE_HTML_BUTTON.
LIFETIME = CL_GUI_HTML_VIEWER=>LIFETIME_DYNPRO.
* create control container for html control
DATA CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
CREATE OBJECT CONTAINER
EXPORTING
CONTAINER_NAME = 'CUSTOM'
LIFETIME = LIFETIME.
* create html control
CREATE OBJECT HTML_VIEWER
EXPORTING
PARENT = CONTAINER
LIFETIME = LIFETIME
EXCEPTIONS
CNTL_ERROR = 1
CNTL_INSTALL_ERROR = 2
DP_INSTALL_ERROR = 3
DP_ERROR = 4.
IF SY-SUBRC NE 0.
* error handling only in debugging mode
ENDIF.
* load and show URL
* SHOW_URL = 'C:\Users\addcuser.MIN06100470LD01\Downloads\cross-browser-qrcode\index.html'. "#EC NOTEXT
SHOW_URL = 'http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=|1&chl=/chart.png''. "#EC NOTEXT
MY_URL = SHOW_URL.
CALL METHOD HTML_VIEWER->SHOW_URL
EXPORTING
URL = SHOW_URL
EXCEPTIONS
CNTL_ERROR = 1.
IF SY-SUBRC NE 0.
* error handling only in debugging mode
ENDIF.
ENDMETHOD. "generate_html_button
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
START-OF-SELECTION.
CALL SCREEN 100 STARTING AT 10 10 ENDING AT 40 25.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS'.
IF INIT IS INITIAL.
INIT = 'X'.
CREATE OBJECT LO_REPORT.
LO_REPORT->GENERATE_HTML_BUTTON( ).
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module EXIT INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE EXIT INPUT.
LEAVE PROGRAM.
ENDMODULE. " EXIT INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'REFRESH'.
CALL METHOD HTML_VIEWER->GET_CURRENT_URL
IMPORTING
URL = SHOW_URL
EXCEPTIONS
CNTL_ERROR = 1.
IF SY-SUBRC <> 0.
* error handling only in debugging mode
ENDIF.
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
IF SY-SUBRC <> 0.
* error handling only in debugging mode
ENDIF.
IF MY_URL <> SHOW_URL.
SHOW_URL = MY_URL.
CALL METHOD HTML_VIEWER->SHOW_URL
EXPORTING
URL = SHOW_URL
EXCEPTIONS
CNTL_ERROR = 1.
IF SY-SUBRC <> 0.
* error handling only in debugging mode
ENDIF.
ENDIF.
WHEN OTHERS.
CALL METHOD CL_GUI_CFW=>DISPATCH."for application events
ENDCASE.
ENDMODULE. " USER_COMMAND INPUT
Regards
Karthikeyan K
Hi Experts,
I have requirement to copy the image from HTML display.
The Third party sending the HTML files to SAP server. I want to execute the file from SAP.
I did this using CL_GUI_HTML_VIEWER. In that file output is QR barcode.
Its showing in preview correctly.
But requirement is I want to print that QR code in smartforms.
How to get the QR code image from preview to code level?
code below
*&---------------------------------------------------------------------*
*& Report zRSDEMO_HTML_VIEWER *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT zRSDEMO_HTML_VIEWER.
DATA OK_CODE TYPE SY-UCOMM.
DATA SAVE_OK TYPE SY-UCOMM.
DATA INIT.
DATA SHOW_URL(255).
DATA MY_URL(255).
DATA LIFETIME TYPE I.
DATA HTML_VIEWER TYPE REF TO CL_GUI_HTML_VIEWER.
* class definition for OO event handler
CLASS LCL_EVENT_RECEIVER DEFINITION." INHERITING FROM CL_GUI_HTML_VIEWER.
PUBLIC SECTION.
CLASS-METHODS NAVIGATECOMPLETE
FOR EVENT NAVIGATE_COMPLETE OF CL_GUI_HTML_VIEWER
IMPORTING URL
SENDER.
METHODS: GENERATE_HTML_BUTTON,
ON_SAPEVENT
FOR EVENT SAPEVENT OF CL_GUI_HTML_VIEWER
IMPORTING ACTION " Action from button
FRAME
GETDATA
POSTDATA
QUERY_TABLE. " Additional parameters
ENDCLASS. "lcl_event_receiver DEFINITION
DATA: LO_REPORT TYPE REF TO LCL_EVENT_RECEIVER.
* class implementation for OO event handler
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD NAVIGATECOMPLETE.
MESSAGE S300(EU) WITH URL. "#EC NOTEXT
MY_URL = URL. "evtl. zur Demonstration System-/Applikationsevent
ENDMETHOD. "navigatecomplete
METHOD ON_SAPEVENT.
DATA: LS_QUERY_TABLE LIKE LINE OF QUERY_TABLE.
DATA: LV_STRING TYPE STRING.
CASE ACTION.
WHEN 'MY_BUTTON_1'.
LV_STRING = 'HTML button says: '.
READ TABLE QUERY_TABLE INTO LS_QUERY_TABLE WITH KEY NAME = 'PARAM1'.
CONCATENATE LV_STRING LS_QUERY_TABLE-VALUE
INTO LV_STRING
SEPARATED BY SPACE.
READ TABLE QUERY_TABLE INTO LS_QUERY_TABLE WITH KEY NAME = 'PARAM2'.
CONCATENATE LV_STRING LS_QUERY_TABLE-VALUE
INTO LV_STRING
SEPARATED BY SPACE.
MESSAGE LV_STRING TYPE 'I'.
ENDCASE.
*
ENDMETHOD. "on_sapevent
METHOD GENERATE_HTML_BUTTON.
LIFETIME = CL_GUI_HTML_VIEWER=>LIFETIME_DYNPRO.
* create control container for html control
DATA CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
CREATE OBJECT CONTAINER
EXPORTING
CONTAINER_NAME = 'CUSTOM'
LIFETIME = LIFETIME.
* create html control
CREATE OBJECT HTML_VIEWER
EXPORTING
PARENT = CONTAINER
LIFETIME = LIFETIME
EXCEPTIONS
CNTL_ERROR = 1
CNTL_INSTALL_ERROR = 2
DP_INSTALL_ERROR = 3
DP_ERROR = 4.
IF SY-SUBRC NE 0.
* error handling only in debugging mode
ENDIF.
* load and show URL
* SHOW_URL = 'C:\Users\addcuser.MIN06100470LD01\Downloads\cross-browser-qrcode\index.html'. "#EC NOTEXT
SHOW_URL = 'http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=|1&chl=/chart.png''. "#EC NOTEXT
MY_URL = SHOW_URL.
CALL METHOD HTML_VIEWER->SHOW_URL
EXPORTING
URL = SHOW_URL
EXCEPTIONS
CNTL_ERROR = 1.
IF SY-SUBRC NE 0.
* error handling only in debugging mode
ENDIF.
ENDMETHOD. "generate_html_button
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
START-OF-SELECTION.
CALL SCREEN 100 STARTING AT 10 10 ENDING AT 40 25.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS'.
IF INIT IS INITIAL.
INIT = 'X'.
CREATE OBJECT LO_REPORT.
LO_REPORT->GENERATE_HTML_BUTTON( ).
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module EXIT INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE EXIT INPUT.
LEAVE PROGRAM.
ENDMODULE. " EXIT INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'REFRESH'.
CALL METHOD HTML_VIEWER->GET_CURRENT_URL
IMPORTING
URL = SHOW_URL
EXCEPTIONS
CNTL_ERROR = 1.
IF SY-SUBRC <> 0.
* error handling only in debugging mode
ENDIF.
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
IF SY-SUBRC <> 0.
* error handling only in debugging mode
ENDIF.
IF MY_URL <> SHOW_URL.
SHOW_URL = MY_URL.
CALL METHOD HTML_VIEWER->SHOW_URL
EXPORTING
URL = SHOW_URL
EXCEPTIONS
CNTL_ERROR = 1.
IF SY-SUBRC <> 0.
* error handling only in debugging mode
ENDIF.
ENDIF.
WHEN OTHERS.
CALL METHOD CL_GUI_CFW=>DISPATCH."for application events
ENDCASE.
ENDMODULE. " USER_COMMAND INPUT
Regards
Karthikeyan K
2015 Jul 09 7:39 PM
Hi,
That Google chart API is deprecated...
If you are on SAP Basis 702 or higher, ask your basis people to evaluate enabling QR Code via OSS Notes:
2029589 - Support for QR code and data matrix bar code (kernel part)
2029824 - Support for QR code and data matrix bar code (ABAP part)
The features and restrictions are found here:
2030263 - Support for QR Code 2005 Barcode in SAPscript and Smart Forms
As for working with the Google chart API - use http client, not the viewer to get the image.
Once you can retrieve image, you have two unattractive options:
1) convert it to bitmap and store it in BDS (not very performant process and fills BDS with junk temporary files);
2) convert it to bitmap, program own bitmap conversion to OTF format and cache the result somewhere in memory (using singleton for example); make an implicit enhancement at the beginning of Sapscript/Smartform runtime FM SAPSCRIPT_BITMAP_GET, to intercept calls for BDS bitmap loading and return your image where necessary. If any of the 2) sounds intimidating up to this point, just forget it and ask basis to enable QR code via Notes...
The toughest part in this is programming bitmap conversion to OTF format... CL_RSPO_OUTPUT_RENDERER_OTF has a method CONVERT_IMG_BMP2OTF, which does it, but it is unfinished SAP development (at least on SAP Basis 702), which has at least 2 bugs in it... That code is unfinished and therefore atrocious (it can also disappear, if SAP decides to do spring cleaning) - so it can only serve as basis for copying into Z namespace for further development. Btw, CL_RSPO_OUTPUT_RENDERER_OTF also has method to get image from url and other interesting stuff, like working with CL_FXS_IMAGE_PROCESSOR (which looks like another abandoned development).
cheers
Jānis
2015 Jul 10 11:37 AM
Hi,
QR code is not my objective. The third party sending the some output using HTML format.
I want to display the HTML in one part of my smartforms.
The HTML output may be QR code or Image or 1 D bar code or 2 D bar code or Our own Encrypted format images.
They sending those type of output in HTML format.
We should display the output in between our smartforms.
Also i am in ECC 6.0 lower level (Below EHP 7.0) I hope you got my point.
Regards
Karthikeyan.
2015 Jul 10 7:26 PM
Ok, I think I understand better now. As long as we are talking about "raw" images that reside on some kind of webserver (or even on SAP application server) the options 1) and 2) are viable. Use either the SAP http client or ABAP OPEN/READ DATASET for AS file to get picture into ABAP, then either store it in BDS or convert it to OTF and pull it into smartform via enhancement.
If we are in a realm of "freestyle" unrestricted html formatted content that needs to be integrated into SAP form output - I have not a slightest concrete idea how to approach that kind of task. HTML viewer has EXECWB( ) method that should enable printing (no idea if that printing can run without user interaction), but anything that involves SAP GUI is by definition not capable of being executed in background. Maybe third party HTML renderer can help, but I'd then use such tool to pre-process the HTML documents to images at application server/OS level, so that ABAP/Smartform solution has to deal with "finished" images only.
Edit in: or, if the html is simple enough and can remain relatively "static", so it's feasible to parse it to extract, for example, links to images and maybe some unformatted text, then it's worth programming ABAP logic for interpreting it, I feel.
cheers
Jānis
Message was edited by: Jānis B
2015 Jul 11 3:09 AM
Hi ,
Thanks for immediate reply.
Please check my above code.
The HTML output displayed in SAP screen using CL_GUI_HTML_VIEWER.
I want to convert that output to Image format.
If the image conversion is possible means, I can set the button to convert the image format.
In background mode i am going to use BDC to automatically click the button.
Is it possible to convert HTML output to Image format?
In level 7.0 having one method to take screenshot. But My server is below 7.0.
Thanks
Karthikeyan
2015 Jul 11 10:19 AM
Hi,
BDC is incapable of processing GUI controls (see OSS Note 311440 - Batch input and controls), which is where the Html viewer (default browser installed on your client) runs. That BDC restriction also applies to CL_GUI_FRONTEND_SERVICES like taking screenshot, which in addition (on my Windows Citrix client at least) also prompts the user, whether or not taking screenshot should be permitted.
I have checked your code and CL_GUI_HTML_VIEWER and I don't see a way to convert Html viewer contents to image (other than trying to print to file perhaps), but I'd avoid depending in any way on frontend functionality in (application server based) form processing.
I have also looked and am still continuing to look around to see what Html processing/rendering related Function modules or classes might be available in standard SAP, but I'm not very hopeful.
cheers
Jānis
2015 Jul 11 10:38 AM