Printing of pdf document from java application

Hello,
I want to print out a pdf document which I get from a server as a byte-stream. I don't want to display or preview it on the client but print it out right away. Is there a way to do this?
Thank you very much!
Matthias

Hi Matthias,
If you have got solution for this can u suggest me.
I'm using following code
          PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
          DocFlavor flavor = javax.print.DocFlavor.INPUT_STREAM.AUTOSENSE;
          System.out.println("====================>"+flavor);
          PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
          PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
          PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);
          if (service != null)
               try
                    javax.print.attribute.standard.Copies obj=new javax.print.attribute.standard.Copies(1);
                    Attribute at=(Attribute)pras.get(obj.getClass());
                    int noOfCopies=1;
                    if(at!=null){
                         try{
                              noOfCopies=Integer.parseInt(at.toString());
                         }catch(Exception err){noOfCopies=1;}
                    for(int i=0;i<noOfCopies;i++)
                         URL url = null;
                         try{
                              url = new URL(urlToPDF);
                              url.openConnection();
                              fis = url.openStream();
                         }catch(Exception err){}
                         DocPrintJob job = service.createPrintJob();
                         job.addPrintJobListener(printjoblis);
                         DocAttributeSet das = new HashDocAttributeSet();
                         Doc doc = new SimpleDoc(fis, flavor, null);
                         pras.add(Sides.ONE_SIDED);
                         job.print(doc, pras);
               }catch(Exception err){System.out.println("=========>"+err);}
some times i'm getting garbage values in the printout.
Thanks & Regards,
Surya.

Similar Messages

  • How to print a PDF document from Labview?

    I am looking to create a paper copy of a PDF document.  Note: I do NOT want to create a PDF document.
    In other words I want to print a PDF document from Lab View or Visual Basic or C#.  The application is used in a production environment so I want a clean solution.
    The requirements are:
    1) Be able to specify the output printer.
    2) Set the quantity to print.
    3) Specify the file to print.
    4) Function returns when printing is complete
    5) Silent operation, that means no popup boxes.
    Any help is appreciated.

    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnmngr.mspx?mfr=true
    http://forums.ni.com/ni/board/message?board.id=170&message.id=183895&requireLogin=False
    you might be able to use system exec to print files.

  • PDF document in Java application

    Hi All,
    Is it possible to show a PDF document in Java application, Using JEditorPane or.....?
    Regards,
    Byju

    What makes you think so? There's a screenshot on that page presenting a Metal GUI, so it's compatible with Swing. Also, there are lots of other solutions ...

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

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

  • Problem printing scanned PDF document from iPad to HP Photosmart Plus B209a

    Hi,
    I'd like to report a problem printing a scanned PDF document from iPad via HP ePrint application to my HP Photosmart Plus B209a printer. The document was sent to the printer without any issue. However, the printer only prints out the
     screenshot image in the center of the PDF page, and the image is enlarged and rotated to fit in an A4 paper. The rest of the document is simply ignored by the printer. The document with the problem can be downloaded in the link below:
    Download PDF document with the problem
    What could be wrong? Thank you in advance!

    Thanks for the reply.
    I received the document from my teacher, so I don't know what program she used to scan it.
    I tried to print the document directly from my PC which works fine though, so I guess the document is OK.
    My HP printer is an old model which doesn't support eprint or air print, so I used the eprint application on iOS to print the document. I tried both color and black/white which gave me the same result: only the center screenshot image is printed out, and the image is enlarged and rotated to fit an A4 paper, the rest of the document is just ignored.
    What do you mean by saving it as a document?

  • Print a PDF document from flash

    Hi,
    I need to create a flash button that when I click on him its
    print a PDF document.
    Is it possibility to do that in flash
    Thanks
    Pini

    For offline/CD-Rom work yes you can using JStart read this
    http://www.flashjester.com/index.php?section=faq&cPath=28_41#352
    and download the example file
    Regards
    FlashJester Support Team
    e. - [email protected]
    w. -
    http://www.flashjester.com
    There is a very fine line between "hobby" and
    "mental illness."

  • 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

  • Getting and Printing A PDF Document From R/3 Using Web Dynpro

    I would like specific information on getting and printing a document residing R/3 using web dynpro.  My environment is Netweaver 04s SR2, an it will not include ITS or the ABAP stack. It connects to remote R/3.  I will not be using Adobe Interactive Forms.       I only need get/render/print the doc.  My question is in 3 parts.
    1) Getting the PDF from R/3
         a) In terms of the RFC ABAP module, how should it return the pdf (a table?)
         b) How should the document be stored within the Component Controller context
             for display.
    2) Converting the R/3 returned binary into a form that is renderable within
        Web Dynpro.  (Does the Form UI Element Require it to be converting and if so
                              what is the best way to do this)
    3) Printing the PDF from the corresponding iView in the portal. (If I am using the
        form ui element to display it, how can printing be initiated in the portal)
    Thanks

    Hi,
    In webdynpro there s a fecility to convert the general data to PDF by uisng th InterativeForm UI Element.
    This for u need to do the following things.
    1. Need to configure the ADS(Adobe document services) in your VA(Visual Admin).
    2. Once ADS is configured we  can utilize the UI element Interactiveform It has contain the Adobedesigner by using this we can design the PDF and binding with the model nodes.
    3. Develop the Function module in the r/3 side and import into WD side and those are created as Model nodes and we canutilize in the 2 step.
    4.When u run the application u can display the pdf with how u design ur PDF form.
    This is generally doing the PDF by using PDF.
    Or do u think any other way post ur issues.
    Thanks,
    Lohi.

  • How to open an PDF file from Java Application

    Hi
    I am developing a GUI application in java swing.
    on clicking one button, I want to open PDF file from my swing application.
    Is there any API through which I can achieve this?
    Tapan Maru
    Sun Certified Java Programmer

    Here's a way to do it (if I understand you
    correctly). Just let explorer.exe do it for you.
    import java.awt.*;
    public class openPDF
         Desktop desktop = Desktop.getDesktop();
         public openPDF()
              open("test.pdf");
         public void open(String path)
              try
                   Runtime.getRuntime().exec("explorer.exe "+path);
    } catch(Exception e) { System.out.println("NAI!
    I! ERROR!\n"+e); }
         public static void main(String[] args)
              openPDF myApplication = new openPDF();
    Why do you have a Desktop object as a member but instead of using it, you execute a command with Runtime (which is not platform independent!)???
    -Puce

  • Is impossible to know when you print a PDF document from Workflow? how?

    Hi
    I am creating a workflow that prints a PDF form and send it in a WorkItem to the user's inbox, once you run the WorkItem a PDF is opened the user ... I wonder if you can capture an event if the user prints the document or cancels ... I do not speak English and translated into the google translator excuse any errors.

    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnmngr.mspx?mfr=true
    http://forums.ni.com/ni/board/message?board.id=170&message.id=183895&requireLogin=False
    you might be able to use system exec to print files.

  • Printing a PDF document from a network printer hosted on Windows Print Server

    Hi
    We have a use case where a XFA form needs to be merged with the XML file and later be printed on a printer hosted on Windows Print Server.
    While I know the first part of merging the template with the data file, I am stuggling to get my document printed.
    Here are the options that I have already tried -
    1) Used the generatePrintedOutput to render a flat PDF and convert it into a PS format.
    2) The output of the above service was input to the "sendToPrinter" service with following configuration settings
        Input document     : <Document variable referencing to the output of the GeneratePrintedOutput service>
        Printer Protocol     : DirectIP
        Server URI            : \\ <IP address of the Print Server>     NOTE: The Print Server is hosted on a different domain & is a Windows Server
        Printer Name        : \\ <IP address of the Print Server>\<name of the printer>
    Some more information about our LC servers -
    OS -> Unix
    Application Server -> JBoss
    When I used these settings and invoked the process, I got the following exception -
    2011-03-07 11:13:39,047 ERROR [com.adobe.livecycle.output.exception.OutputException] ALC-OUT-001-403: Could not connect to the DirectIP Server: \\<IP Address of the Printer Server>.
    2011-03-07 11:13:39,067 ERROR [com.adobe.workflow.AWS] An exception was thrown with name com.adobe.livecycle.output.exception.OutputException message:com.adobe.livecycle.output.exception.OutputException: ALC-OUT-001-403: Could not connect to the DirectIP Server: \\<IP Address of the Printer Server>. while invoking service OutputService and operation sendToPrinter and no fault routes were found to be configured.
    2011-03-07 11:13:39,069 ERROR [com.adobe.idp.workflow.dsc.invoker.WorkflowDSCInvoker] An exception was thrown with name com.adobe.livecycle.output.exception.OutputException message:com.adobe.livecycle.output.exception.OutputException: ALC-OUT-001-403: Could not connect to the DirectIP Server: \\<IP Address of the Printer Server>. while invoking service OutputService and operation sendToPrinter and no fault routes were found to be configured.
    2011-03-07 11:13:39,079 ERROR [com.adobe.workflow.AWS] An exception was thrown with name com.adobe.livecycle.output.exception.OutputException message:com.adobe.livecycle.output.exception.OutputException: ALC-OUT-001-403: Could not connect to the DirectIP Server: \\<IP Address of the Printer Server>. while invoking service OutputService and operation sendToPrinter and no fault routes were found to be configured.
    Therefore I tried to check if I am able to Ping the Printer Server from my Livecycle Server and found that the ping was successful.
    Next - I changed the Printer Protocol from DirectIP to SharedPrinter keeping the rest of the settings same. In this case - when I invoke the process, it did not throw any error , but it did not print any document as well.
    Any suggestion where I have gone wrong? Pls let me know if you would need more information to help me resolve this issue.
    Thanks & Regards,
    Priyank

    Well I found the answer......
    I had to do the two steps below -
    1) Go to Admin UI, "Trust Store Management -> User & Password Credentials" and add a profile for my Printer server with login ID and password which can access the printer.
    So in the "User & Password Crendentails" page, I click on "add" and fill the following values
    Profile : \\ <IP address of the print server> ....... (It is important that you write the name correctly..for example " \\10.10.234.212"
    USername : <user id who has access to the printer>
    Password  : <password for that user Id>
    2) In the sendToPrinter service, I used CIFS as the protocol and I have the proper Server URI as below
      \\10.10.234.212\<printername>
    And it worked ! .....

  • I am trying to print a pdf document from an electronic journal at my school, and i can only get it to print what is on the screen at the time i hit print.  How do i get it to print the whole document?

    how do i get it to print the whole article?  i don't seem to have a problem printing from my old windows laptop

    melbaby_3 wrote:
    when I clicked on your link and hit print, all pages were there!
    That suggests there's no problem with Safari or Quartz, the PDF rendering engine used by Safari, Preview, and other Mac applications.
    When I'm in the database and have the article open that I want to print, I click on the "full text in pdf" link and it opens in another safari window.
    Does the PDF in this other Safari window have all the pages? If yes, why don't you print from this window?
    It's very difficult to tell what might be going on if you don't give very specific details.
    For instance, in many reference databases, full-text articles are not free. You have to pay to view them, either article by article, or by subscription. Your school may have such a subscription, but, if it does, you probably need to access the database through the portal, web site, or facility provided by your school (your school's librarian should be able to help you with that). If you don't, the database has no way of knowing you have a right to view the full text, and may give you just a preview or the article's first page.
    Another possibility is that the database provides full-text PDFs in a format not compatible with Quartz, which may be able to render only the first page. But, in such a case, I'd expect Safari to print blank pages. If that's the case, you need to save the PDF on your hard disk and open it with Adobe Reader (Preview wouldn't work).
    There are other possibilities, but these two seem to me the most likely.
    Would I have to save it in preview first
    You should save the PDF on your hard disk from Safari. (I think you should do this anyway, just in case you need to refer to the article again later.) Instead of just clicking the  "'full text in pdf' link", press and hold Control, then click. This should give you a contextual menu; if the link points to a PDF file, you should see the commans "Save Linked File to 'Downloads'" and "Save Linked File As…". Use either, save the file, then, in Finder, double-click on it. Preview should open it.
    It is possible that the link is not to a PDF file, but to a script which fetches that PDF file for you. In that case, it's pointless to download it. Click on it, and then, if the PDF viewing window opens in Safari, move the cursor towards the centre of the bottom of the window. A bar with commands should appear; one of them will download the file to your Downloads folder.

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

  • 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

Maybe you are looking for

  • X randomly crashing, cannot ctrl-alt-bksp

    The first crash was a couple of months ago, and I will admit I just ignored it, especially since it didn't crash again for about a month. Then I was starting to think I might have a problem and did a bit of research. I thought turning off compositing

  • Whats a simple way to repeat a line ?

    i have this program where the user inputs a number and accordingly the question repeats .........any help i want to make it really simple.....i have to teach this to a bunch of students i got this so far import java.awt.*; import hsa.Console; public

  • IPad Stuck in Recovery Mode - Help!!!!!

    Problem 1:  My iPad apps and movies are on an external drive because the space on my iMac internal SSD is only 256GB.  My iTunes Media Folder [500GB of apps and movies] is a lot larger than the internal SSD can hold.  When I plugged in my iPad and tr

  • Using External USB-based MIDI Interface as a synthesizer in QuickTime

    The QuickTime 7 says it's possible. Any wonders?

  • Restricting People Picker of "Person or Group" column to Site Groups only

    Hi, I am working on SharePoint Online 2013 and I have created a column - DocOwner with "Person or Group" type in document library. In the site collection there are 4 groups lets say - A,B,C,D. When user creates a new item (document set), in newform.a