Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Hi ,

Recently I've come across this development where we need to print a PDF file on windows default printer.

Seems pretty simple but challenge here is the file is at some server and you are having the path to file in the form of URL and not the file with you.

To summarize there is a URL link to PDF file i.e. if you copy paste this URL in explorer window you will get some PDF open.

Now you have to print this PDF .

The development can be broken into steps:

1. Identify the URL

2. Fetch the file from URL on your machine.

3. Fetch file from your machine and print it.

Now Identify the URL means:

You have authentication to access the URL link .It might happens with you that you are able to open the URL in browser but not able to fetch file in sap.

For that try running report RSHTTP20 in your GUI and if succesfull than proceed with second step.

To fetch the file from URL use FM HTTP_FILE_GET. For your understanding refer the code below.

Tables explanation is out of scope of this document.

P_URL is the URL link to PDF file.

P_FILE is the path of your system folder to save the file.

Tables response and response_headers not required here in our development.

CALL FUNCTION 'HTTP_GET_FILE'

  EXPORTING

    absolute_uri                = p_url

    document_path            = p_file

TABLES

   REQUEST_HEADERS             = response

   RESPONSE_HEADERS           = response_headers

EXCEPTIONS

   CONNECT_FAILED             = 1

   TIMEOUT                            = 2

   INTERNAL_ERROR             = 3

   DOCUMENT_ERROR          = 4

   TCPIP_ERROR                   = 5

   SYSTEM_FAILURE               = 6

   COMMUNICATION_FAILURE  = 7

   OTHERS                                = 8

          .

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

Now once file is fetched use suitable method to print it at windows printer.

Call below method with parameters as shown here to print the PDF file at your windows default printer.

NOTE: But remember p_url here is your file path from your machine and not URL link.

PARAMETER p_url type string.

concatenate '/p' '/h ' p_url INTO url SEPARATED BY space.

.

CALL METHOD cl_gui_frontend_services=>execute

  EXPORTING

    application            = 'ACRORD32.EXE'

    parameter              = url

    minimized              = 'X'

  EXCEPTIONS

    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.

Now go and check you have the print outs waiting to be picked at your windows printer.

To add your printer instead of default printer here just add printer details in parameter: url now contains /t command with printer full name as seen in pop-up window if printed manually using adobe services. See below string as example:

 

CONCATENATE '/t' p_url p_print p_driver p_port INTO p_application SEPARATED BY

space.

Disclaimer: All coding is executed successfully at my SAP GUI ECC 6.0.

2 Comments