Printing PDF's in Java

Hi,
I am in the process of trying to silently print PDFs via java in a Windows NT 4.0 environment. The solution so far has been to convert then into postscript files using pdftops (co/ xpdf) and then simply send the postscript file to the printer using the java PrintService.
Which would work fine except for the fact that I need to print envelopes (DL and C4) (not a problem but for the fact that some of the printers only have Postscript Level 2 Emulation and don�t recognize the fact that an envelope is being printed).
And I need to be able to print to a specific (i.e. default) tray on a network printer, and using the java PrintService uses the wrong tray.
Tried using JPedal and JPrint, and the get past the tray problem but haven�t tried them with the envelopes yet � can�t see that being a problem though.
Big question is does anybody have experience with print files from java to a specific tray on a network printer.
Thanks
Richard Peters

duffymo
Acrobat 5.0 when I open a pdf on my system.
This is exactly the code currently in my program.
I just ran it again to test it and it works.
1) The application has an ugly square gray box on the screen while printing.
2) The Acrobat reader starts on the task bar.
3) For the application to continue I have to expand the reader and close it myself.
public void actionPerformed(ActionEvent e) {
  String selectedDocument = SelectedDocument();
  if (selectedDocument != null) {
    try {
      String command = "C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /t "+selectedDocument+" \\\\CONTROL\\HP LaserJet 4L";
      Runtime rn = Runtime.getRuntime();
      Process process = rn.exec(command);
      process.waitFor();
    catch (Exception pEX) {showSystemError("Unable to print document.", selectedDocument, pEX, false);}
}It is not what I wanted to do - I wanted to do the print
internally in the program.
rykk

Similar Messages

  • 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 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

  • Problem in printing pdf document with java code

    Hi All
    I want to print a pdf document with java code i have used PDFRenderer.jar to compile my code.
    Code:
    File f = new File("C:/Documents and Settings/123/Desktop/1241422767.pdf");
    FileInputStream fis = new FileInputStream(f);
    FileChannel fc = fis.getChannel();
    ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
    PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page
    PDFPrintPage pages = new PDFPrintPage(pdfFile);
    // Create Print Job
    PrinterJob pjob = PrinterJob.getPrinterJob();
    PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
    pjob.setJobName(f.getName());
    Book book = new Book();
    book.append(pages, pf, pdfFile.getNumPages());
    pjob.setPageable(book);
    // System.out.println(pjob.getPrintService());
    // Send print job to default printer
    pjob.print();
    but when i am running my program i am getting error
    Exception in thread "main" java.awt.print.PrinterException: Invalid name of PrintService.
    Please anybody, knows the solution for this error?
    Thanks In Advance
    Indira

    It seems that either there is no default printer setup or you have too many printers or no printer setup at all. Try running the following code. It should print the list of available print services.
    import java.awt.print.*;
    import javax.print.*;
    public class PrintServiceNames{
         public static void main(String args[]) throws Exception {
              PrintService[] printServices = PrinterJob.lookupPrintServices();
              int i;
              for (i = 0; i < printServices.length; i++) {
                   System.out.println("P: " + printServices);
    }From the list pick one of the print service names and set it explicitly like "printerJob.setPrintService(printServices);" and then try running the program.

  • Print pdf from WD JAVA

    Hi All
    I have a requirement to print PDF form from  WD
    without to see the PDF form
    i'll be glad to see your suggestions
    Yossi

    iText creates PDFs, but it doesn't print PDFs. I'll look at gsprint; hopefully, it'll do what I need it to do. I do have the luxury of knowing that all users will have a version of Acrobat Reader, so it's too bad I can't kick off a process. The best I could do is kick the process off using Acrobat Reader to open the file and then print from the menu. This won't work since I need a way to ask for type pdf and have windows use the version registered, not the version hardcoded.
    For example,
    Process pr=null;
    String arr[] = {"C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe",tmpf.getPath()};
    try {
    pr = Runtime.getRuntime().exec(arr);
    } catch (Exception e) {
    e.printStackTrace();
    //Handle the exception
    I tried using AcroRd32.exe, but it failed in finding it. Anyway, this would be last resort, since the user wants to press a Print button and grab it from the printer. I looked at the Java Print API (we are still on 1.2.2.008, so it'll be end of year before making the leap to 1.4) and it's worse than getting a root canal without novacaine.

  • Printing PDF documents in Java

    Hello All,
    I will be very gratefull if someone points me to resources on the web which show how to print a pdf document in java.
    If you are aware of any tutorials and examples, then please let me know.
    regards,
    Abhishek.

    duffymo
    Acrobat 5.0 when I open a pdf on my system.
    This is exactly the code currently in my program.
    I just ran it again to test it and it works.
    1) The application has an ugly square gray box on the screen while printing.
    2) The Acrobat reader starts on the task bar.
    3) For the application to continue I have to expand the reader and close it myself.
    public void actionPerformed(ActionEvent e) {
      String selectedDocument = SelectedDocument();
      if (selectedDocument != null) {
        try {
          String command = "C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /t "+selectedDocument+" \\\\CONTROL\\HP LaserJet 4L";
          Runtime rn = Runtime.getRuntime();
          Process process = rn.exec(command);
          process.waitFor();
        catch (Exception pEX) {showSystemError("Unable to print document.", selectedDocument, pEX, false);}
    }It is not what I wanted to do - I wanted to do the print
    internally in the program.
    rykk

  • Printing PDF files using java

    Is there a class or utility that already does this?
    Thx in advance.

    Do you want to create PDF files using Java? If so, there is a library available at http://www.lowagie.com/iText/docs.html Check out this site. There are many more similar PDFGEnerator tools that you can use..

  • Why can't I print pdfs since installing Java for Mac OS X 10.6 update 12?

    Two days ago I installed the software update 12 for Java for Mac OS X 10.6 now pdfs I try to print come out blank or with data, only the company's logo

    I read the article.  This problem of mine occurs when I try to print from an email attachment not from a website. 
    I am in Mail not Safari.  I click the little triangle to show the attachment then double click the icon of the attachment, the pdf opens in adobe reader but when I try to print it the page that comes out of my printer is blank or shows only the masthead of the company but no content. 
    I tried a two month old email attachment and got the same results.
    I looked for the plug-ins mentioned in the article but coul not find them on my Mac in the applications file.
    Does anyone know how to uninstall the "Java for Mac OS X 10.6 update 12" ??

  • Viewing and printing a PDF file from Java Swing Application

    Hello,
    I need to view and print PDF files from Java Swing Application.How do I do that?I appreciate your help.
    Thank you
    Sumana Somareddy

    If you have a link to the URL pointing to the PDF file, you can allow the browser to open it. Then use the print function of the browser to print the PDF document.
    Regards,
    Tak.

  • How to print PDF under Java control

    Hi, all - thank you for reading this message.
    I'm working with Java 1.4.2_12 and Tomcat but planning to migrate upward Real Soon Now. We are running on Windows Server 2003 (customer's choice).
    My application, using iText, creates a PDF, which comprises a new coversheet plus some existing PDFs appended. The new PDF is needed for archival. This part works OK.
    Now, still in my Java app, I would like to print the new PDF, to a printer chosen in my code. At present I have only PCL and basic PS (2?) capable laser printers, mostly HPs, available and these are all networked - not local - printers.
    I have tried some things using PrintService and this cannot find any PDF printers from the server, though for comparison it did correctly find some PostScript capable devices. Attempts to actually print have resulted in garbage, with the printer obviously mangling the PDF over several trees-worth of paper, if not stopped.
    Has anyone else managed to 'filter' a PDF (under program control) and send it to a regular, networked printer, such as I have described?
    Can anyone confirm that a PS 3 capable printer would handle a PDF direct and if so what DocFlavor would be appropriate?
    Sorry if this is a trivial issue but I have spent quite some time on it and would appreciate any input.
    Thanks - Edwin
    Message was edited by:
    EdwinBolton

    jPDFPrint by Qoppa Software. It's a 100% java library to print PDF documents.

  • 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

  • Printing a PDF document using Java 1.4 Printing API

    Hi,
    When I tried to print a PDF document using JAVA 1.4 Printing API, I got the following exception.
    Exception in thread "main" sun.print.PrintJobFlavorException: invalid flavor
    at sun.print.Win32PrintJob.print(Win32PrintJob.java:290)
    at Printing.main(Printing.java:40)
    I am able to print the same PDF document using Acrobat reader.
    Is PDF format not supported in JAVA 1.4 printing API? or is something wrong in my code?
    here is the sample JAVA program that I was using
    import javax.print.*;
    import javax.print.attribute.*;
    import java.io.*;
    public class Printing {
    public static void main(String args[]) throws Exception {
    String filename = args[0];
    PrintRequestAttributeSet pras =
    new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
    PrintService defaultService =
    PrintServiceLookup.lookupDefaultPrintService();
    DocPrintJob job = defaultService.createPrintJob();
    FileInputStream fis = new FileInputStream(filename);
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(fis, flavor, das);
    job.print(doc, pras);
    Thread.sleep(10000);
    System.exit(0);
    Thank you
    Sumana

    Here's a pure Java solution (that works!):
    http://www.mycgiserver.com/~zhouwu/pdf/readme.html
    The caveats are:
    - prints only to the default printer
    - requires a properties file located in the home directory
    my workaround for the last:
         * Print a PDF file to the default printer (might consume lots of memory!).
         * <p>
         * <b>Required:</b>
         * <ul>
         * <li>a file "acrobat.properties" needs to be in the working directory. The content is:
    <table align="center" bgcolor="#E0E0E0" border=1 cellpadding="10" cellspacing="0"><tr><td><pre style="margin-top:0; margin-bottom:0">
    #com.adobe.acrobat.Viewer Properties
    #Wed Oct 29 20:34:05 PST 2003
    com.adobe.acrobat.AcceptedLicAgreement=true
    com.adobe.acrobat.Fax_Fine_Mode=true
    com.adobe.acrobat.Find\:FindAll=false
    com.adobe.acrobat.Find\:FindBackwards=false
    com.adobe.acrobat.Find\:FindWholeWord=false
    com.adobe.acrobat.Find\:MatchCase=false
    com.adobe.acrobat.Open_Dialog_Directory=C\:\\temp\\
    com.adobe.acrobat.Open_Dialog_File=itext.pdf
    com.adobe.acrobat.Print_Method_Known=true
    com.adobe.acrobat.Shrink_To_Fit=false
    com.adobe.acrobat.SitePreferencesURL=file\://localhost/C\:/pdf/acrobat-site.properties
    com.adobe.acrobat.Use_Print_Server=false
    com.adobe.acrobat.util.fontDirectories=C\:\\Winnt\\Fonts
    com.adobe.acrobat.util.fontIgnoreExtensions=.fon;.pfm;.ini;.lst;.txt;.doc;.ttmap;.z;.enc;.dir;.afm;.f3b;.pfa;.spd;.ps;.bepf;.map;.alias;.scale;.all;.upr
    </pre></td></tr></table>
         * <li>The JAR files PDFPrinter.jar, acrobat.jar and MRJToolkitStubs.zip in the CLASSPATH.
         * </ul>
         * <p>
         * Note: the file "acrobat.properties" is expected to be in the user's home directory. As this is not always feasible,
         * the system property "user.home" is mapped to "user.dir" for the time of execution.
         * @param fileName Name of PDF file to print.
         * @throws Exception on error.
         * @see <a href="http://www.mycgiserver.com/~zhouwu/pdf/readme.html">PDF Server (Silent) Printing</a>
        public void printPDF(String fileName) throws Exception {
            String oldHome = System.getProperty("user.home");
            System.setProperty("user.home", System.getProperty("user.dir"));
            PDFPrinter vi = new PDFPrinter();
            vi.activate();
            vi.setDocumentInputStream(new FileInputStream(fileName));
            vi.printAll();
            System.setProperty("user.home", oldHome);
        }//printPDF()I just need the following additional files in my CLASSPATH: PDFPrinter.jar, acrobat.jar and MRJToolkitStubs.zip. Despite the note at the site above that "printing quality is not very good", i can't agree: the print quality is quite good. Not perfect, but acceptable for most uses.
    (Tested on Windows 2000 SP4, J2SE 1.4.2_03, hp laserjet 2300dn)

  • Printing PDF by using ActiveX in java application

    Hi All,
    I'm working on an application that creates pdf documents. The aim is to make a silent printing of these documents so without any user action.
    I tried several solution. I tried PrintJob from javax.print and Desktop from java.awt. I'm not satisfy by these both solution.
    So now I would like to use Acrobat through the COM interface.
    Could you indicate to me where I can find a documentation or some examples of implementtion about this interface and its usage into java. I googled but I found not example of implementaiton ?
    Thanks
    S.

    Ok .... .
    I tried in java by using jacob the following code to use Acrobat but I found no information regarding the call of the Acrobat functions (open file, print file, ...)
    My exemple is :  
    ComThread.InitSTA();
    ActiveXComponent oAcroPDF = new ActiveXComponent("AcroPDF.PDF");
      try {
       oAcroPDF.invoke("LoadFile", fileName);
       oAcroPDF.invoke("PrintAll");

  • Java Applet - Printing Pdf Files

    Hi
    Can anyone suggest me some libraries to print pdfs using Java Applets. I have tried using the SmartJPrint library but its giving me error when I try printing pdfs using applets.
    Thanks
    nikhil

    SmartJPrint web applets have changed recently and works to be fine every time. You might try these links for printing of existing pdf, pdf viewing, pdf print, pdf silent printing from a command line or silently printing a pdf from a browser page.
    http://www.activetree.com
    Demo that print a PDF from a browser page silently.
    [This demo printing control parameters as part of the PDF url. Interestingly this pdf print demo from browser works for a remote PDF URL that dynamically generate a PDF and then prints to the printer. In this demo you have the option to enter your URL that is either a PDF or a PDF generating URL that eventually generates a PDF and then prints.]
    http://www.activetree.com/silent_print_from_browser1/start.jsp
    [PDF print silently or using user choice dialog from the applet. PDF printing parameters such as printer name, auto page size detection, paper size selection, fit to page etc. are made as choice. This demo too print a PDF or more than one PDF as a batch pdf print. You have chice to submit the pdf print job as a separate print job or as one pdf print job.]
    http://www.activetree.com/silent_print_from_browser2/start.jsp
    These two links are opening their PDF viewer applet for viewing your local or remote PDF files.
    http://www.activetree.com/demo/pdfapplet/pdfviewer.jsp [Open the PDF viewer inside the browser frame itself. When browser resize the applet resize too.]
    http://www.activetree.com/demo/pdfapplet/pdf_viewer_no_frame.jsp [Opens the PDF viewer in a new Java frame window]
    Edited by: jatima123 on Nov 20, 2007 10:19 AM

  • Printing PDF report directly to printer, not using orarrp utility

    The orarrp utility works only with Windows machines and it
    requires installation on both the client machines and servers to
    support. We need a more general solution.
    Adobe has a java application/applet/javabean (and support
    classes) to view PDF, and it is easy to write a java driver
    which can be used in place of the orarrp utility. However,
    Adobe's Java Viewer is extremely slow, does not produce quality
    output, and is explicitly not supported by Adobe.
    My question then relates to Reports. When the Report server
    returns a PDF in the Previewer, I'm expecting the JINITIATOR,
    used by Forms, is also used to support the Report frame and
    functionality, including eventual printing. If this is the case,
    is there not a set of classes, downloaded with Jinitiator, which
    support the fonts, and printing of PDF to locally attached
    printers?
    And if so, shouldn't we, in Java, be able to make use of these
    classes and their APIs to print PDF files directly to locally
    attached printers without the need for Previewing first?

    within a forms trigger:
    1. generate the report
    2. copy from iAS to local
    like: webutil_file_transfer.url_to_client()
    3. print.exe /d:printer filename (for windows OS)

Maybe you are looking for

  • Waiting for Apple to deliver your Genius results

    For the past couple of days I've noticed that the display area of my iTunes has said, "Waiting for Apple to deliver your Genius results-" And it just keeps saying that for hours on end. Anybody know why? And/or what I can do about it?

  • How to reverse material ledger closing entries beyond  previous period?

    In a test system, the system does not permit reverse material ledger closing entries. The current period is 04/2008. Getting a message C+716 message You want to cancel closing entries in valuation area XXXX for period 008 in fiscal year 2007. You are

  • Submitting a Form produces error

    We have created a form for a work order system that an end user would fill out and Submit to the Help Desk for work to be completed. The Form itself and the Submit button (via e-mail) works ONLY if the user has Adobe 7 Pro. We have tested this on a m

  • Servlet to Desktop App

    I have a speecific question... I have a mobile device connecting to a servlet, when the mobile device does some action, the action is sent to the servlet. I then want the servlet to do some action to the desktop application. I want to know is it poss

  • Time Capsule not working - need help

    Hi guys, I just bought a Time Capsule to replace my Linksys E2000. The E2000 was running fine but I wanted a wireless external HD, which the Time Capsule provided. So I've set the Time Capsule up with all the same settings for my ISP, which are as fo