Through many Blog posts and SAP help sites I found it as a challenge to print the PDF in SAP.
Part of below code can be used in many ways:
1. To save the PDF file from any URL link on some shared drive.
2. To print the PDF file from your shared drive at default printer configured at your machine.
3. To print the PDF file at the printer of your choice.
To save the PDF file from any URL link at shared drive you can use FM HTTP_FILE_GET.
Please look into the attached file here for more information on how to use this FM in this scenario.
Things to note before you use this FM:
URL link should not be blocked from your network.
Check your network connection settings on HTTP sites in Tcode: SICF.
While passing name of your shared drive make sure that it would contain path + <filename.pdf> and not only path.
<filename> can be any name you want to give to your file.
Once your file get saved on shared drive you can pick it up to get printed.
FYI we are using here ADS i.e Adobe document services to print file through Sap ABAP Coding
To get this functionality you should use method Execute of Cl_Gui_Frontend_services.
Deatils on how to use the method can be found in attached file here.
Just to tell you what we are doing here:
We are using Adobe document services command through this method to print the file.
We need to pass the command parameters in parameter field of method.
Also we need to pass application name as Adobe.Exe or Acrord32.Exe depending on what is installed at our system in application parameter of method.
For details Kindly refer the full coding attached here for your reference.
Code is FM created for this purpose:
*” REFERENCE(URL) TYPE C
*” REFERENCE(PATH) TYPE C
*” REFERENCE(PRINTER) TYPE C
*” REFERENCE(STATUS) TYPE I
TYPES: BEGIN OF text,
END OF text.
DATA: response TYPE TABLE OF text WITH HEADER LINE,
response_headers TYPE TABLE OF text WITH HEADER LINE.
DATA: p_application TYPE string.
*first save the file from URL
*at shared drive
CALL FUNCTION ‘HTTP_GET_FILE’
absolute_uri = url
document_path = path
request_headers = response
response_headers = response_headers
connect_failed = 1
timeout = 2
internal_error = 3
document_error = 4
tcpip_error = 5
system_failure = 6
communication_failure = 7
OTHERS = 8.
status = sy-subrc.
IF status <> 0.
*if file saved succesfully at shared path
*pick the file and print it on printer
CONCATENATE ‘/t’ url printer INTO p_application SEPARATED BY space.
CALL METHOD cl_gui_frontend_services=>execute
application = ‘ACRORD32.EXE’
parameter = p_application
minimized = ‘X’
cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
synchronous_failed = 8
not_supported_by_gui = 9
OTHERS = 10.
IF sy-subrc NE 0.
status = sy-subrc.
status = 0.