Results 1 to 3 of 3

Thread: Print A Pdf

  1. #1
    Jack is offline Senior Member
    Join Date
    Jun 2007
    Posts
    130
    Rep Power
    0

    Default Print A Pdf

    I'm trying to print pfd from java application
    this is the code:
    Java Code:
    DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    aset.add(new Copies(1));
    
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();
    
    DocPrintJob printJob = service.createPrintJob();
    Doc doc = new SimpleDoc(filePDF,flavor,null)
    
    try {
    printJob.print(doc, aset);
    } catch (PrintException e) {
    e.printStackTrace();
    }
    but it doesn't work, can you help me?

  2. #2
    Peter is offline Senior Member
    Join Date
    Jun 2007
    Posts
    119
    Rep Power
    0

    Default

    I think that the api of sun isn't possible to print a pdf document directly.
    (only txt)
    If you have the openoffice installed, you can invoke to the print order directly from runtime

  3. #3
    Ed
    Ed is offline Senior Member
    Join Date
    Jun 2007
    Posts
    110
    Rep Power
    0

    Default

    Hi jack, try this:
    Java Code:
    import java.awt.print.*;
    import java.util.*;
    import javax.print.*;
    import javax.print.attribute.*;
     
    
                 DocFlavor flavor =  DocFlavor.INPUT_STREAM.AUTOSENSE;             
                           PrintService service = PrintServiceLookup.lookupDefaultPrintService(); 
                               
                 if (service != null) {
              try {
              
           DocPrintJob job = service.createPrintJob(); 
            
          
           DocAttributeSet das = new HashDocAttributeSet();
           
     
          FileInputStream fis = new FileInputStream(destFileNamePdf);
          
    
          Doc doc = new SimpleDoc(fis,flavor,das); 
         try {
      
       job.print(doc,null);

Similar Threads

  1. print line
    By kazitula in forum Java Applets
    Replies: 2
    Last Post: 01-26-2008, 03:05 PM
  2. Print Area
    By Riftwalker in forum Advanced Java
    Replies: 0
    Last Post: 11-28-2007, 08:28 PM
  3. Print XML tag
    By DonCash in forum XML
    Replies: 2
    Last Post: 08-07-2007, 07:02 PM
  4. doubt about PRINT API
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 10:51 PM
  5. print .doc in java
    By Alan in forum Advanced Java
    Replies: 1
    Last Post: 05-17-2007, 05:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •