Skip to Content

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.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Christian Jianelli

    Hi Amit,

    I think it would be nice to have an additional information in your blog regarding the use of Adobe Acrobat Reader command line parameters, that is exactly what your example does.

    Extract from Adobe Developers FAQ

    How Do I Use Command Lines with Acrobat and Adobe Reader on Windows?

    These are unsupported command lines, but have worked for some developers. There is no documentation for these commands other than what is listed below. You can display and print a PDF file with Acrobat and Adobe Reader from the command line.

    NOTE:All examples below use Adobe Reader, but apply to Acrobat as well. If you are using Acrobat, substitute Acrobat.exe in place of AcroRd32.exe on the command line.

    AcroRd32.exe pathname — Executes Adobe Reader and displays the file, whose full path must be provided.

    Other options for the command line are:

    Option – Meaning

    /n  – Launches a separate instance of Acrobat or Adobe Reader, even if one is currently open.

    /s  – Opens Acrobat or Adobe Reader, suppressing the splash screen.

    /o  – Opens Acrobat or Adobe Reader, suppressing the open file dialog.

    /h  – Opens Acrobat or Adobe Reader in a minimized window.

    AcroRd32.exe /p pathname — Executes Adobe Reader and displays the Print dialog box.

    AcroRd32.exe /t path “printername” “drivername” “portname” — Initiates Adobe Reader and prints a file, whose path must be fully specified, while suppressing the Print dialog box.

    The four parameters of the /t option evaluate to path, printername, drivername, and portname (all strings).

    printername — The name of your printer.

    drivername — Your printer driver’s name, as it appears in your printer’s properties.

    portname — The printer’s port. portname cannot contain any “/” characters; if it does, output is routed to the default port for that printer.

    References

    Adobe Developer FAQ

    http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/intro_to_sdk/DeveloperFAQ.pdf

    Best Regards,

    Christian

    (0) 

Leave a Reply