How to print PDF file content from ABAP in background?

Hi,
Is it possible to print PDF file content from ABAP in background?
I have some PDF content which I need to print it, these PDF files are generated outside the SAP.
Please have you any suggestions?
Thank you
Tomas

<b><u>Solution:</u></b><br>
<br>
The target output device must support PDF print, this is only one limitation.<br>
<br>
REPORT  z_print_pdf.
TYPE-POOLS: abap, srmgs.
PARAMETERS: p_prnds LIKE tsp01-rqdest OBLIGATORY DEFAULT 'LOCL',
            p_fname TYPE file_table-filename OBLIGATORY LOWER CASE,
            p_ncopi TYPE rspocopies OBLIGATORY DEFAULT '1',
            p_immed AS CHECKBOX.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
  DATA: lv_rc     TYPE i,
        lv_filter TYPE string.
  DATA: lt_files TYPE filetable.
  FIELD-SYMBOLS: <fs_file> LIKE LINE OF lt_files.
  CONCATENATE 'PDF (*.pdf)|*.pdf|' cl_gui_frontend_services=>filetype_all INTO lv_filter.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      file_filter             = lv_filter
    CHANGING
      file_table              = lt_files
      rc                      = lv_rc
    EXCEPTIONS
      OTHERS                  = 1.
  IF sy-subrc NE 0 AND lv_rc EQ 0.
    MESSAGE 'Error' TYPE 'E' DISPLAY LIKE 'S'.
  ENDIF.
  READ TABLE lt_files ASSIGNING <fs_file> INDEX 1.
  IF sy-subrc EQ 0.
    p_fname = <fs_file>-filename.
  ENDIF.
AT SELECTION-SCREEN.
  DATA: lv_name   TYPE string,
        lv_result TYPE boolean.
  lv_name = p_fname.
  CALL METHOD cl_gui_frontend_services=>file_exist
    EXPORTING
      file                 = lv_name
    RECEIVING
      result               = lv_result
    EXCEPTIONS
      OTHERS               = 1.
  IF sy-subrc NE 0.
    MESSAGE 'Bad file!' TYPE 'E' DISPLAY LIKE 'S'.
  ENDIF.
  IF lv_result NE abap_true.
    MESSAGE 'Bad file!' TYPE 'E' DISPLAY LIKE 'S'.
  ENDIF.
START-OF-SELECTION.
END-OF-SELECTION.
  PERFORM process.
FORM process.
  DATA: lv_name     TYPE string,
        lv_size     TYPE i,
        lv_data     TYPE xstring,
        lv_retcode  TYPE i.
  DATA: lt_file TYPE srmgs_bin_content.
  lv_name = p_fname.
  CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename                = lv_name
      filetype                = 'BIN'
    IMPORTING
      filelength              = lv_size
    CHANGING
      data_tab                = lt_file
    EXCEPTIONS
      OTHERS                  = 1.
  IF sy-subrc NE 0.
    MESSAGE 'Read file error!' TYPE 'E' DISPLAY LIKE 'S'.
  ENDIF.
  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
      input_length = lv_size
    IMPORTING
      buffer       = lv_data
    TABLES
      binary_tab   = lt_file
    EXCEPTIONS
      failed       = 1
      OTHERS       = 2.
  IF sy-subrc NE 0.
    MESSAGE 'Binary conversion error!' TYPE 'E' DISPLAY LIKE 'S'.
  ENDIF.
  PERFORM print USING p_prnds lv_data CHANGING lv_retcode.
  IF lv_retcode EQ 0.
    WRITE: / 'Print OK' COLOR COL_POSITIVE.
  ELSE.
    WRITE: / 'Print ERROR' COLOR COL_NEGATIVE.
  ENDIF.
ENDFORM.                    " PROCESS
FORM print USING    iv_prndst  TYPE rspopname
                    iv_content TYPE xstring
           CHANGING ev_retcode TYPE i.
  DATA: lv_handle    TYPE sy-tabix,
        lv_spoolid   TYPE rspoid,
        lv_partname  TYPE adspart,
        lv_globaldir TYPE text1024,
        lv_dstfile   TYPE text1024,
        lv_filesize  TYPE i,
        lv_pages     TYPE i.
  CLEAR: ev_retcode.
  CALL FUNCTION 'ADS_SR_OPEN'
    EXPORTING
      dest            = iv_prndst
      doctype         = 'ADSP'
      copies          = p_ncopi
      immediate_print = p_immed
      auto_delete     = 'X'
    IMPORTING
      handle          = lv_handle
      spoolid         = lv_spoolid
      partname        = lv_partname
    EXCEPTIONS
      OTHERS          = 1.
  IF sy-subrc NE 0.
    ev_retcode = 4.
    RETURN.
  ENDIF.
  CALL FUNCTION 'ADS_GET_PATH'
    IMPORTING
      ads_path = lv_globaldir.
  CONCATENATE lv_globaldir '/' lv_partname '.pdf' INTO lv_dstfile.
  OPEN DATASET lv_dstfile FOR OUTPUT IN BINARY MODE.
  IF sy-subrc NE 0.
    ev_retcode = 4.
    RETURN.
  ENDIF.
  TRANSFER iv_content TO lv_dstfile.
  IF sy-subrc NE 0.
    ev_retcode = 4.
    RETURN.
  ENDIF.
  CLOSE DATASET lv_dstfile.
  IF sy-subrc NE 0.
    ev_retcode = 4.
    RETURN.
  ENDIF.
  CALL FUNCTION 'ZBAP_RM_PDF_GET_PAGES'
    EXPORTING
      iv_content = iv_content
    IMPORTING
      ev_pages   = lv_pages.
  lv_filesize = XSTRLEN( iv_content ).
  CALL FUNCTION 'ADS_SR_CONFIRM'
    EXPORTING
      handle   = lv_handle
      partname = lv_partname
      size     = lv_filesize
      pages    = lv_pages
      no_pdf   = ' '
    EXCEPTIONS
      OTHERS   = 1.
  IF sy-subrc NE 0.
    ev_retcode = 4.
    RETURN.
  ENDIF.
  CALL FUNCTION 'ADS_SR_CLOSE'
    EXPORTING
      handle = lv_handle
    EXCEPTIONS
      OTHERS = 1.
  IF sy-subrc NE 0.
    ev_retcode = 4.
    RETURN.
  ENDIF.
ENDFORM.                    " PRINT

Similar Messages

  • How to print PDF files directly from SAP?

    We have created output that is being saved in a PDF format. We can store it on any drive or send it through email. However, we would like to be able to print a PDF file directIy without any manual intervention. Now users still have to open the file and hit the print button and we want to avoid this. So basically we want to be able to create e.g. a sales order, generate an order confirmation in PDF format and send it directly to the output device that we stored in output master data. I have a feeling it is not possible to print directly because output device has to be like a PDF1 to create the PDF file itself and there is no space left somewhere to store the physical output device. We use ECC 5.
    kind regards
    Angelique Heutinck

    You can use this custom FM -:)
      FUNCTION Z_PDF_DOWNLOAD.
    *"*"Interfase local
    *"  IMPORTING
    *"     REFERENCE(FILENAME) TYPE  STRING
        SELECT RQIDENT
        INTO (T_TSP01-RQIDENT)
        FROM TSP01
        WHERE RQOWNER EQ SY-UNAME
          AND RQCLIENT EQ SY-MANDT.
        APPEND T_TSP01.
        ENDSELECT.
        SORT T_TSP01 DESCENDING.
        CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
             EXPORTING
                  SRC_SPOOLID              = T_TSP01-RQIDENT
                  NO_DIALOG                = ''
             IMPORTING
                  PDF_BYTECOUNT            = NUMBYTES
                  PDF_SPOOLID              = PDFSPOOLID
                  BTC_JOBNAME              = JOBNAME
                  BTC_JOBCOUNT             = JOBCOUNT
             TABLES
                  PDF                      = PDF
             EXCEPTIONS
                  ERR_NO_OTF_SPOOLJOB      = 1
                  ERR_NO_SPOOLJOB          = 2
                  ERR_NO_PERMISSION        = 3
                  ERR_CONV_NOT_POSSIBLE    = 4
                  ERR_BAD_DSTDEVICE        = 5
                  USER_CANCELLED           = 6
                  ERR_SPOOLERROR           = 7
                  ERR_TEMSEERROR           = 8
                  ERR_BTCJOB_OPEN_FAILED   = 9
                  ERR_BTCJOB_SUBMIT_FAILED = 10
                  ERR_BTCJOB_CLOSE_FAILED  = 11
                  OTHERS                   = 12.
        IF SY-SUBRC EQ 0.
          CALL FUNCTION 'GUI_DOWNLOAD'
               EXPORTING
                    BIN_FILESIZE            = NUMBYTES
                    FILENAME                = FILENAME
                    FILETYPE                = 'BIN'
               TABLES
                    DATA_TAB                = PDF
               EXCEPTIONS
                    FILE_WRITE_ERROR        = 1
                    NO_BATCH                = 2
                    GUI_REFUSE_FILETRANSFER = 3
                    INVALID_TYPE            = 4
                    NO_AUTHORITY            = 5
                    UNKNOWN_ERROR           = 6.
          IF SY-SUBRC EQ 0.
            DELETE FROM TSP01 WHERE RQIDENT EQ T_TSP01-RQIDENT.
          ENDIF.
        ENDIF.
      ENDFUNCTION.
    Greetings,
    Blag.

  • How to print PDF files

    How to print PDF files????

    Please see FAQ: How to print a PDF file from Adobe Reader Touch.
    If you don't see the Print button in the toolbar, please update to the latest version of Adobe Reader Touch.
    FAQ: How to update Adobe Reader Touch to the latest version
    The latest version (1.2) also includes newly supported features such as Commenting (adding Sticky Notes, Highlight, Strikeout, and Underline), Save/Save As, and Go to Page.
    Here's the blog post by Dennis Griffin (Product Manager for Adobe Reader for Tablets and Smartphones).
    Adobe Reader Touch for Windows 8 adds Comments and More

  • How to print PDF files using java print API

    Hi,
    I was goign throw lot of discusion and reading lot of forums related to print pdf files using java api. but nothing seems to be working for me. Can any one tell me how to print pdf files using java api.
    Thanks in advance

    Mike,
    Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
    My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
    boolean showPrintDialog=true;
    PrinterJob printJob = PrinterJob.getPrinterJob ();
    printJob.setJobName ("Contract.pdf");
    try {
    if (showPrintDialog) {
    if (printJob.printDialog()) {
    printJob.print();
    else
    printJob.print ();
    } catch (Exception PrintException) {
                   PrintException.printStackTrace();
    Thank you and a happy new year.
    Cheers,
    Chris

  • How to print Pdf files using Adobe Reader

    How to print Pdf files using Adobe Reader

    Open the PDF file with File > Open... in Adobe Reader and print it with File > Print

  • How to print PDF file from java application?

    Hi,
    I have a java application that needs to print an PDF files. Could any one provide me links to tutorial/sample codes for doing this?

    http://onesearch.sun.com/search/onesearch/index.jsp?qt=print+pdf+files&subCat=&site=dev&qp=&chooseCat=javaall&col=developer-forums

  • How to print PDF file with hp-ux 11.31 on itanium

    We finished upgrade from 11.5.7 to 12.1.1.
    With 11.5.7 ( pa-risc hp-ux 11.23 ) we print our pdf file in using acroread to convert them in postscript and print them to printer.
    In our 12.1.1 environment ( itanium hp-ux 11.31 ) ; acroread is not available on itanium.
    Which tool can we use to be able to print PDF file on itanium ( itanium pdf to postscript tool ) free
    Thanks
    Marc

    Pl see MOS Doc 778970.1 (How to Print PDF/UTF8 in R12?)
    HTH
    Srini

  • How to print pdf file to my Designjet 500+HPGL2 (C7769B)

    Hi,
    We have HP Designjet 500+GL2 plotter in the office, used to print A1 & A3 drawings. Last time someone from HP install HP eprint & share to my computer for me to print PDF files to the plotter. But my CPU brokedown, so now I'm using a new PC. But now I can't print PDF files to our plotter. Even when I install the eprint & share software from you website.
    I already check the possibility that I'm not connected to the printer but no because when I print test page, it is working. Please help. Thanks.

    Hello lean1025,
    Welcome to the HP Support Forums!
    To get your issue more exposure I would suggest posting it in the commercial forums since this is a commercial product. You can do this at Printers - Designjet & Large Format.
    The support page for your product may be helpful in the meantime: Product Support & Troubleshooting (Select your model)
    I hope this helps!
    JERENDS
    I work on behalf of HP
    Please click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to the left of the reply button to say “Thanks” for helping!

  • Print pdf file directly from a folder, Adobe Reader X in  Windows Server 2003

    In previous versions of Adobe Reader we were able to print pdf files groupwise directly when selected in a folder.
    Now I've installed Reader X on the Windows Server 2003 environment. Logged in as administrator I can still select <Print> by selecting the right mouse button in a folder. Logged in as a user, this is not available.
    I checked user-rights and permissions and made sure they have full control.
    Someone who can help us in this matter?
    Thanks

    Thanks for your reply.
    The file menu doesn't show the print option either. We used to work this way, after installing the 9.0 and Reader X version, this option has disappeared from both the File menu and the right mouse button. For other filetypes, for example Excel the Print option is still available and works properly. Logged in as administrator on the serverconsole, there is no problem. So it seams to be something specific to pdf-formats in a server 2003 environment. The userrights are all set on full control (same as administrator).
    Thanks again

  • How to print pdf files not using acrobat product?

    i just want to print pdf files,but not want to use the adobe acrobat or acrobat reader,just want to write a tools print pdf files directly.

    > no i just want to print it,not need to read it.can you help me?
    Well, the problem is to print it you need to be able to read it. Something needs to convert it into a format the printer can understand (most printers are PostScript or PCL).
    I'm not sure you entirely understand what a PDF file is. It's not a fancy text file. It's a binary format. Saying "I want to print a PDF without a PDF interpreter" is like saying "I want to run an EXE without Windows". You need software to interpret the format.
    You certainly can write your own software to interpret the PDF format, convert it to a print language and output that to a printer, but as Aandi said you will need to start by reading the PDF Reference so you know how the inside of a PDF file works, and it will most likely take several years of development even for a seasoned, expert programmer. It's just not as simple as "Printer, meet PDF. PDF, meet printer."

  • How to extract original file contents from content server

    Hi,
    1)How can we extract original file contents from the content server (which in our case is SAP database itself)...
    2)What exactly is PHIO_ID and LOIO_ID?
    Thanks and regards,
    Santhosh Kumar U.P

    Hi,
    concerning your first question - please decribe, what you are trying to do.
    Question 2:
    LOIO_ID is the ID of the Logical Information Object. A LOIO is not a real document, but kind of a virtual document, a containerfor all "real" versions of a document. A PHIO (physical info object) is a real document.
    you can read more at http://sercie.sap.com/Kpro
    Kind regards,
    Carl

  • How to  print pdf file by using java print API ? I am trying with this code

    import java.io.FileInputStream;
    import java.io.InputStream;
    import javax.print.Doc;
    import javax.print.DocFlavor;
    import javax.print.DocPrintJob;
    import javax.print.PrintException;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.SimpleDoc;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.print.attribute.standard.Copies;
    import javax.print.attribute.standard.MediaSizeName;
    public class PDFPrint {
    static public void print(InputStream inputStream, PrintService printService) throws PrintException {
    Doc doc = new SimpleDoc(inputStream, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    attributes.add(MediaSizeName.ISO_A4);
    attributes.add(new Copies(1));
    print(doc, attributes, printService);
    }//print()
    static public void print(Doc doc, PrintRequestAttributeSet attributes, PrintService printService) throws PrintException {
    if (printService == null) {
    printService = PrintServiceLookup.lookupDefaultPrintService();
    System.out.println("The Printer Name is :"+printService.getName());
    DocPrintJob docPrintJob = printService.createPrintJob();
    System.out.println("Before Print Start()");
    docPrintJob.print(doc, attributes);
    }//print()
    public static void main(String args[])
    PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
    String file="c:/BackUp/file.pdf";
    FileInputStream fis=new FileInputStream(file);
    System.out.println("Before Print() called ..");
    print(fis,defaultPrintService);
    System.out.println("After Printing....");
    I am using this code to print pdf file. But when I try this one automatically the printer starting with print ascii codes with infinite loop.
    I am using jdk1.4,Acrobat 8.0, Windows environment.
    Can u help me in this regard'
    Thank u
    grani

    import java.io.FileInputStream;
    import java.io.InputStream;
    import javax.print.Doc;
    import javax.print.DocFlavor;
    import javax.print.DocPrintJob;
    import javax.print.PrintException;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.SimpleDoc;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.print.attribute.standard.Copies;
    import javax.print.attribute.standard.MediaSizeName;
    public class PDFPrint {
    static public void print(InputStream inputStream, PrintService printService) throws PrintException {
    Doc doc = new SimpleDoc(inputStream, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    attributes.add(MediaSizeName.ISO_A4);
    attributes.add(new Copies(1));
    print(doc, attributes, printService);
    }//print()
    static public void print(Doc doc, PrintRequestAttributeSet attributes, PrintService printService) throws PrintException {
    if (printService == null) {
    printService = PrintServiceLookup.lookupDefaultPrintService();
    System.out.println("The Printer Name is :"+printService.getName());
    DocPrintJob docPrintJob = printService.createPrintJob();
    System.out.println("Before Print Start()");
    docPrintJob.print(doc, attributes);
    }//print()
    public static void main(String args[])
    PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
    String file="c:/BackUp/file.pdf";
    FileInputStream fis=new FileInputStream(file);
    System.out.println("Before Print() called ..");
    print(fis,defaultPrintService);
    System.out.println("After Printing....");
    I am using this code to print pdf file. But when I try this one automatically the printer starting with print ascii codes with infinite loop.
    I am using jdk1.4,Acrobat 8.0, Windows environment.
    Can u help me in this regard'
    Thank u
    grani

  • How to print PDF files on E90?

    Hello all, my E90 prints fine with hp printer via bluetooth but has no options to print PDF files, I'm in need of printing PDF files cause all of my documents & forms are in PDF formats. Can an upgrade to Adobe PDF LE 2.0 be able to print files with improved functions & features? Why is it Adobe on PC could print with PDF format documents & not on handsets?

    Have you tried FOXIT? I think there is a trialversion. I tried Adobereader 2.5 but there is still no option to print.
    ‡Thank you for hitting the Blue/Green Star button‡
    N8-00 RM 596 V:111.030.0609; E71-1(05) RM 346 V: 500.21.009

  • Printing pdf or pcl from abap

    Hi experts,
    may be my problem is to simple, but I can't find an answer in the forum.
    I want to print a pdf or pcl (either format will work) on a printer. This printing should happen in an ABAP
    program. In this program I get the file via a web service as XSTRING. I also have the destination from the printer in a table from type NAST.
    So the question is, what command, program, BAPI, class or whatever can I use to print this file on the
    designated printer?
    Regards
    Torsten

    hi
    check this
    http://help.sap.com/saphelp_nw04/helpdata/en/90/78f081030211d399b90000e83dd9fc/frameset.htm
    hope this helps
    regards
    Aakash Banga

  • How to print pdf file not using the the adobe reader ?

    hello,
    i used the adobe sdk to open a pdf file in read and modify it serveral times and each time save it to another directory,and now i need to write a program to print the pdf file in this directory.when print the file,i want to continue my work also,so who i tell me how to solve this problem?
    thanks.

    The SDK is only a collection of documentation and headers that show you how to interact with and automate Adobe Acrobat and to some extent Adobe Reader. You need a copy of Acrobat or Reader installed on the system in order to use any of the SDK functions. You cannot "print not using the Adobe Reader", unless you have Adobe Acrobat installed on the system instead of Reader.

Maybe you are looking for