Java print DocAttributes not setting to printer.

Hi,
I have written below sample program to print document in landscape mode. But it is not setting the attributes to printer. Please verify the code and help me on this.
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.*;
public class printasn {
     public static void main(String args[]) {
          printasn ps = new printasn();
     public printasn() {
       try {
         String abc = "<html><body>sfsdafsdfsafds</body></html>";
         InputStream bs = new ByteArrayInputStream(abc.getBytes());
         DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
         PrintRequestAttributeSet aset1 = new HashPrintRequestAttributeSet();
         DocAttributeSet das = new HashDocAttributeSet();
         PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, aset1);
                   aset1.add(new Copies(12));
                   aset1.add(OrientationRequested.LANDSCAPE);
                   das.add(OrientationRequested.LANDSCAPE);
                    if (pservices.length > 0) {
           System.out.println("selected printer " + pservices[0].getName());
                    DocPrintJob pj = pservices[0].createPrintJob();
          try {
          Doc doc = new SimpleDoc(bs, flavor, null);
          pj.print(doc, aset1);
          bs.close();
           }  catch (Exception e) {
          System.err.println(e);
          } catch(Exception ex) {
            ex.printStackTrace();
}Thanks,
Rah

updating the drivers did not help at all. It cleared out the print queue, but adding another item did not print it off. I rechecked the printer itself and redid the wifi settings and password. All appears to be alive and kicking and seeing each other.
Any suggestions?

Similar Messages

  • ERROR "JAVA HOME not set"

    Hi,
    I have installed Hyperion V 11.1.2 on windows 2003 server in the D drive on my laptop.when i try to start configuration utility it says "JAVA HOME IS NOT SET".I have installed java in my laptop.
    can any one please help me how to set java home.

    Hi,
    The JAVA_HOME is set in a script which is called when the configuration utility is run.
    Check you have a JRE directory under D:\Hyperion\Common
    If you don't then the installation has gone wrong and you will need to install again.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Cannot print reports as PDF: Logger not set error

    Hi all,
    I'm trying to print some reports as PDF and I have the following problem:
    - I followed the step "5.Installing and Configuring Apache FOP" of http://www.oracle.com/technology/products/database/application_express/html/configure_printing.html
    - When I try to print my report I get this message on OC4J console:
    08/04/30 11:54:42 [ERROR] Logger not set
    08/04/30 11:54:42 [INFO] Using oracle.xml.parser.v2.SAXParser as SAX2 Par
    08/04/30 11:54:42 [INFO] building formatting object tree
    08/04/30 11:54:42 [INFO] setting up fonts
    08/04/30 11:54:42 [INFO] [1]
    08/04/30 11:54:42 [WARNING] table-layout=auto is not supported, using fix
    08/04/30 11:54:42 [WARNING] Sum of fixed column widths 720000 greater tha
    um specified IPD 658800
    08/04/30 11:54:42 [INFO] Parsing of document complete, stopping renderer
    My question is about the Logger error. What is exactly a Logger?
    May I define it in j2ee-logging.xml file of OC4J?
    I'm working with:
    - APEX 3.0.1
    - Java SDK 1.4.2
    - Oracle Containers for J2EE (10.1.3.2)
    Thanks!
    Roger

    Hi again,
    I still didn't found the solution to my problem. In the "ascontrol.log" file of OC4J there is this warning:
    2008-05-05 11:36:28,934 [OC4J Launcher] WARN jmx.SecureWalletManager _setPermission.161 - WARNING: Could not set file permissions administrators:F for wallet at E:\oc4j\j2ee\home\persistence\ascontrol\ascontrol\securestore\ewallet.p12
    Is it significant?
    Thanks

  • HP Solution Center Software ungrad to Windows 7, will not set up the printer in software

    After upgrading from Windows Vista to Windows 7.  This was a clean reinstall of Windows Vista and then the upgrade was in stalled.  I downloaded the new version of the HP Solution Center full and set it up in my computer. 
    The printer is HP Officejet Pro L7580 and I have set up the print in my control panel as wireless connection and my wireless software for has been upgraded for Windows 7 and the printer is properly connected and printing.
    However when I try to set up my printer in the HP Solution Software it will not set up as a wireless connection for my computer.
    Does anyone know how to solve this problem?

    I get printer c8100 series will not work scanner at hp solution center. Please help me out?

  • The only working print-related function in BioBench1.2 on my PC is the "Print Report", all the other "Print" functions gave me "Error, the printer is not set up correctly".

    I used to print all my BioBench data by first exporting them to Excel and then print from there. Recently I need to print some of the screen shots and some data directly from array analysis, but when I click on the "print" buttons, the "Error, the printer is not set up correctly" message occurs. The only thing I can print from BB without this error is the report printing function. I have a postcript printer and I have set the postscript option to be "true"... Thanks !

    This problem is a result of a limitation in Windows 9x regarding the size of an image that you can send to the printer. The problem does not occur on Windows 2000/NT. This problem appeared with the increased color options of LabVIEW 6.0 on which the BB1.2 is based.Although it is not immediately obvious, your video driver and settings play a role in printing.
    1. Try adjusting the color palette your driver uses (i.e., 256 color, high olor, true color). The error may occur only in one of these modes. Also, change the resolution (number of pixels) to represent the Screen Area; e.g., change from a 1024 x 768 display to an 800 x 600 pixel display.
    2.Certain video drivers also support "acceleration" modes. Using a non-accelerated mode often eliminates the error. For
    Windows 95/98, right-click on your My Computer icon and select "Properties" from the pop-up
    menu. On the Performance tab, click the Graphics button and change the Hardware Acceleration (e.g., if it is set to "Full", lower the setting a notch or two); for Windows 2000/NT, right-click on your Desktop and select "Properties" from the pop-up menu. On the Settings tab, click the Advanced button and go to
    Troubleshooting.
    3.In Windows, the standard VGA driver provided by the operating system is very stable. Try using this driver in place of the specific one written for your video hardware. If the error is eliminated, there is likely a problem with your vendor-provided video driver.
    4.These errors are most often fixed with the latest
    video/printer driver. Be sure to contact your hardware manufacturer and install the latest driver. An easy way to determine if your error is "driver-related" is to move your code to another machine (and hopefully a different set of drivers) and see if th
    e error persists. If the problem is printer related, try another printer.
    5.Make sure there are at least 100M avalible space in your C: drive. If not, set the virtual memory to the other drive which has larger available space.

  • Can not set the default printer

    Hello,
    we have HP LaserJet Pro MFP M125-M126 PCLmS network all in one printer, as the installation in every user was successful, and was working fine on installation day, after a day all user facing issue like can not set default pritner , can not print, all user are facing  issue at a time, 
    prompt reply is appreciated,
    This question was solved.
    View Solution.

    Hi @darshan9 ,
    I see that you are experiencing issues setting the default printer for users and you are unable to print over the network.
    I would be happy to help you.
    Do you mean individual computers setup with the printer over the network users or one computer with multiple users?
    Do you have Admin Rights on the computer to make changes?
    What is the full name and product number of your printer? How Do I Find My Model Number or Product Number?
    Download and run the Print and Scan Doctor. It will diagnose the issue and might automatically resolve it. http://www.hp.com/go/tools>Using HP Diagnostic Tools for HP Printers in Windows.
    I would suggest you to check if you have a different user account or from an administration account.
    I would also suggest you to create a new user account and check if you are able to set the printer as default.
    Create a user account. Create a user account.
    If you are still having issues run the Fixit Tool. Diagnose and fix printer and printing problems automatically.
    What were the results when you ran the Print and Scan Doctor? (did it print or scan, any error messages)
    If there is anything else I can help you with, just let me know.
    Have a nice day!
    Thank You.
    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" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • HT4847 all i want to do is scan a document and store in iCloud but printer says not set up for iCloud. do i have to link them in some way? am on wi fi and connected to my mac ok.

    all i want to do is scan a document and store in iCloud but printer says not set up for iCloud. do i have to link them in some way? am on wi fi and connected to my mac ok.

    iCloud doesn't store documents from your Mac (or scanner).  It will only sync documents and data from applications designed for iCloud syncing, such as Pages, Keynote, Numbers, etc.

  • We just  bought an iMac.  We have a new HP printer that we've been using wirelessly with our windows based computers with no problem.  the iMac can find the printer, but it will not set up.  Any ideas?

    Our iMac can find the wireless printer, but it will not set it up.  Any ideas?

    I have to disagree with BGreg about downloading the driver from HP.com. I would recommend using Apple's instructions in
    http://support.apple.com/kb/HT4670?viewlocale=en_US&locale=en_US
    specifically the section on How to Add a Printer then check for the section on Wi-Fi printers.

  • PB60 - Print Word Documents - Error: TEMP viariable is not set??

    Hi to all,
    I got the following problem with transaction PB60.
    If I want to print or edit word documents, it works all fine in SAP GUI. If I use this transaction over SAP WebGui (Internet Transaction Server), I got an error that the TEMP Windows variable is not set.
    Well, I don't understand that error. First, the variable TEMP is set and secondly it works in SAP GUI, so why is it not working with SAP Transaction Server?
    We are working on SAP ERP 2004.
    Help would be rewarded!
    Regards,
    Frank
    Edited by: Frank Wendel on Feb 16, 2010 1:25 PM

    I have done that and can also see this parameter in windows (and have restart my client). Although the error is still there.
    By the way, I have read in customizing help, that you have to set a environment variable called "Path_to_codepage" which should normally be there when installing SAP Gui. In my case, it is not there so I will proove this...
    Any other ideas?

  • Printing HTML with Java Printing Service(JDK1.4 beta)

    Hi there!
    I'm currently checking out the new Java Printing Service (JPS) in the new JDK1.4 beta. This looks like a very promising printing API, with amongst others printer discovery and support for MIME types - but I have some problems with printing HTML displayed in a JEditorPane.
    I'm developing an application that should let the user edit a (HTML)document displayed in a JEditorPane and the print this document to a printer. I have understood that this should be peace-of-cake using the JPS which has pre-defined HTML DocFlavor amongst others, in fact here is what Eric Armstrong says on Javaworld (http://www.javaworld.com/javaone01/j1-01-coolapis.html):
    "With JPS, data formats are specified using MIME types, for example: image/jpeg, text/plain, and text/html. Even better, the API includes a formatting engine that understands HTML, and an engine that, given a document that implements the Printable or Pageable interface, generates PostScript. The HTML formatting engine looks particularly valuable given the prevalence of XML data storage. You only need to set up an XSLT (eXtensible Stylesheet Language Transformation) stylesheet, use it to convert the XML data to HTML, and send the result to the printer."
    After one week of reasearch I have not been able to do what Armstrong describes; print a String that contains text of MIME type text/html.
    I have checked the supported MIMI types of the Print Service returned by PrintServiceLookup.lookupDefaultPrintService(). This is the result:
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    aset.add(new Copies(2));
    PrintService[] service = PrintServiceLookup.lookupPrintServices(flavor,aset);
    if (service.length > 0) {
    System.out.println("Selected printer " + service[0].getName());
    DocFlavor[] flavors = service[0].getSupportedDocFlavors();
    for (int i = 0;i<flavors.length;i++) {
    System.out.println("Flavor "+i+": "+flavors.toString());
    Selected printer \\MUNIN-SERVER\HP LaserJet 2100 Series PCL 6
    Flavor 0: image/gif; class="[B"
    Flavor 1: image/gif; class="java.io.InputStream"
    Flavor 2: image/gif; class="java.net.URL"
    Flavor 3: image/jpeg; class="[B"
    Flavor 4: image/jpeg; class="java.io.InputStream"
    Flavor 5: image/jpeg; class="java.net.URL"
    Flavor 6: image/png; class="[B"
    Flavor 7: image/png; class="java.io.InputStream"
    Flavor 8: image/png; class="java.net.URL"
    Flavor 9: application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
    Flavor 10: application/x-java-jvm-local-objectref; class="java.awt.print.Printable"
    As you can see there is no support for text/html here.
    If anyone has a clue to what I'm missing here or any other (elegant, simple) way to print the contents of a JEditorPane, please speak up!
    Reply to: [email protected] or [email protected] or here in this forum

    Since you have 'printable' as one of your flavors, try this using a JTextPane (assuming you can dump your HTML into a JTextPane, which shouldn't be a big problem)...
    1. Have your JTextPane implement Printable
    ie. something like this:
    public class FormattedDocument extends JTextPane implements Printable 2. Read your HTML into the associated doc in the text pane.
    3. Implement the printable interface, since you have it as one of your available flavors (I'd imagine everybody has printable in their available flavors). Something like this:
    public int print(Graphics g, PageFormat pf, int pageIndex) {
            Graphics2D g2 = (Graphics2D) g;
            g2.translate((int)pf.getImageableX(), (int)pf.getImageableY());
            g2.setClip(0, 0, (int)pf.getImageableWidth(), (int)pf.getImageableHeight()); 
            if (pageIndex == 0)
                setupPrintView(pf);
            if (!pv.paintPage(g2, pageIndex))
                return NO_SUCH_PAGE;
            return PAGE_EXISTS;
        }Here's my setupPrintView function, which is executed once on page 0 (which still needs some polishing in case I want to start from page 5). It sets up a 'print view' class based on the root view of the document. PrintView class follows...
    public void setupPrintView(PageFormat pf) {
    View root = this.getUI().getRootView(this);
            pv = new PrintView(this.getStyledDocument().getDefaultRootElement(), root,
                               (int)pf.getImageableWidth(), (int)pf.getImageableHeight());Note of obvious: 'pv' is of type PrintView.
    Here's my PrintView class that paints your text pane line by line, a page at a time, until there is no more.
    class PrintView extends BoxView
        public PrintView(Element elem, View root, int w, int h) {
            super(elem, Y_AXIS);
            setParent(root);
            setSize(w, h);
            layout(w, h);
        public boolean paintPage(Graphics2D g2, int pageIndex) {
            int viewIndex = getTopOfViewIndex(pageIndex);
            if (viewIndex == -1) return false;
            int maxY = getHeight();
            Rectangle rc = new Rectangle();
            int fillCounter = 0;
            int Ytotal = 0;
            for (int k = viewIndex; k < getViewCount(); k++) {
                rc.x = 0;
                rc.y = Ytotal;
                rc.width = getSpan(X_AXIS, k);
                rc.height = getSpan(Y_AXIS, k);
                if (Ytotal + getSpan(Y_AXIS, k) > maxY) break;
                paintChild(g2, rc, k);
                Ytotal += getSpan(Y_AXIS, k);
            return true;
    // find top of page for a given page number
        private int getTopOfViewIndex(int pageNumber) {
            int pageHeight = getHeight() * pageNumber;
            for (int k = 0; k < getViewCount(); k++)
                if (getOffset(Y_AXIS, k) >= pageHeight) return k;
            return -1;
    }That's my 2 cents. Any questions?

  • How to use java print API???  very very urgent

    Hi
    I fed up with the JAVA print API. If anybody knows how to print a file .txt, please let me know.
    cheers
    shyam

    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.sql.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import utility.*;
    import java.awt.print.*;
    public class remRunPrint extends JFrame implements ActionListener, Printable {
         static JButton j = new JButton("Print");
         String printer = "IT";
         java.util.Date pDate;
         public void setCopies(int i) {
              copies = i;
         public void setPrinter(String s) {
              if (s.length() > 0) {
                   printer = s;
         public void getInfo(int vid) {
              ResultSet verRS;
              try {
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection conn = DriverManager.getConnection("jdbc:odbc:SOMEdbnAME");
                   Statement stmt = conn.createStatement();
                   verRS = stmt.executeQuery("SOME SQL QUERY HERE");
                   verRS.next();
                   //SET SOME VARIABLES HERE..
              } catch (Exception e) {
                   System.out.println("getinfo: " + e);
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() instanceof JButton) {  
                   wookie();
         public void wookie() {
              PrinterJob printJob = PrinterJob.getPrinterJob();
              Paper paper = new Paper();
              PageFormat page = new PageFormat();
              paper.setImageableArea(0, 0, 600, 800);     
              page.setPaper(paper);
              printJob.setPrintable(this, page);
              PrintService[] services = PrintServiceLookup.lookupPrintServices(null, new HashPrintRequestAttributeSet());
              PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
              for (int i=0; i<services.length;i++) {
                   if (services.toString().indexOf(printer) > 0) {
                        ps = services[i];     
              try{
                   printJob.setCopies(copies);
                   //printJob.pageDialog(page);
                   printJob.setPrintService(ps);
                   //if (printJob.printDialog()) {
                        printJob.print();
              } catch (Exception e) {
                   System.out.println("wookie1run1" + e);
         public static void main(String[] args) {
              remRunPrint at = new remRunPrint();
              at.getInfo((new Integer(args[0])).intValue());
              at.drawShapes();
              at.wookie();
         public void drawShapes() {
              setBounds(0, 0, 670, 550);
              addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});
              JLabel l = new JLabel("<html><body><table><tr bgcolor=blue><td><font color=red>Hello EVERYONE</font></td></tr></table></body></html>");
              l.setBounds(20, 20, 120, 20);
              j.setBounds(10, 10, 10, 10);
              j.addActionListener(this);
              getContentPane().setLayout(null);
              getContentPane().add(l);
              getContentPane().add(j);
              show();
         public remRunPrint(){}
         public void paint(Graphics g) {
              g.setFont(new Font("SansSerif", Font.PLAIN, 6));
              g.drawString("PrintDate:", 520, 20);
              g.setFont(new Font("SansSerif", Font.BOLD, 9));
              g.drawString(pDateSTR, 550, 20);
              g.drawString("JOB: ", 23, 37);
              g.drawString("VERSION:", 310, 37);
              g.drawString("#" + vID, 310, 28);
              g.setFont(new Font("SansSerif", Font.BOLD, 18));
              g.drawString(jName, 48, 37);
              g.drawString(vName, 355, 37);
              //HERE ARE A COUPLE LINES OF AWT DRAWING TO A SCREEN THAT WORK ... IF YOU LAUNCH THIS APP FROM THE COMMAND LINE
              //IT WILL SHOW YOU WHAT YOU ARE GOING TO PRINT.. SO YOU CAN FORMAT IT AND BUILD IT FIRST THEN PRINT IT WITH THE
              //BUTTON...
         public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
    if (pi >= 1) {
    return Printable.NO_SUCH_PAGE;
              paint(g);
    return Printable.PAGE_EXISTS;

  • Java Print Service API in Java Stored Procedure (Linux)

    Hi
    We are running an Oracle 10g database on Linux and I am in the proces of developing a java stored procedure which should utilize the Java Print Service API.
    I have made a simple stored procedure to list all available printers and the DocFlavors they support (se the code below).
    My problem is that no printers are listed. I have made a standalone java app. with the same code and executed it directly on the OS level of the Linux box through the Sun JDK 1.4.2 and here I get two printers.
    Is there any specific configuration I need to do to make it work?
    I am wondering if I need to grant specific authorisations through dbms_java for it to work...?
    Any help is greatlyh appreciated.
    ************************************** CODE BEGIN *************************************
    import javax.print.DocFlavor;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    public class TestPrintService {
    public TestPrintService() {
    public static void listPrinters() {
    // Get all available printers and their supported DocFlavors
    PrintService[] pservices =
    PrintServiceLookup.lookupPrintServices(null, null);
    System.out.println("Printer services: " + pservices.length);
    for (int i = 0; i < pservices.length; i++) {
    PrintService pservice = pservices;
    System.err.println("Printer: " + pservice);
    DocFlavor[] docFlavors = pservice.getSupportedDocFlavors();
    for (int j = 0; j < docFlavors.length; j++) {
    DocFlavor docFlavor = docFlavors[j];
    System.err.println("DocFlavor " + docFlavor.toString());
    System.err.println();
    ************************************** CODE END *************************************
    Cheers,
    Jacob Vennervald

    Found this on Oracle support:
    Cannot List Available Printers From The Database Using A Java Stored Procedure [ID 372694.1]
    Applies to:
    Oracle Server - Enterprise Edition - Version: 10.1.0.4.0
    This problem can occur on any platform.
    Symptoms
    Able to list available printers on a machine when running Java code outside the Database.
    When running the same Java code inside the Database as a Java Stored Procedure, no printers are found.
    Cause
    Due to security restrictions, this is expected results.
    The Java Docs state:
    "Services which are registered by registerService(PrintService) will not be included in lookup
    results if a security manager is installed and its CheckPrintJobAccess() method denies access."
    Also from the documentation it states:
    "A PrintServiceLookup implementor is recommended to check for the SecurityManager.checkPrintJobAccess() to deny access to untrusted code. Following this recommended policy means that untrusted code may not be able to locate any print services. Downloaded applets are the most common example of untrusted code."
    Using the checkPrintJobAccess(); call, it does produce a Security Exception when run inside the Database but not when run outside. The exception can be viewed within the log file found in the UDUMP directory.
    Solution
    Run the following code to confirm obtaining available __printers can not be done...__
    This is the code to create the Java Stored Procedure
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "ListPrinters" AS
    import javax.print.*;
    public class ListPrinters {
    public static String AvailablePrinters(){
    String strList;
    PrintService[] pservices =PrintServiceLookup.lookupPrintServices(null,null);
    if (pservices.length > 0 )
    strList = pservices[0].getName();
    else
    strList = "No printers found";
    return strList;
    public static String listprinters() throws Exception {
    String listofprinters;
    try {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) sm.checkPrintJobAccess();
    catch (SecurityException ex) {
    System.err.println("Sorry. Printing is not allowed.");
    listofprinters = AvailablePrinters();
    return listofprinters;
    This is the PL/SQL Wrapper
    CREATE OR REPLACE FUNCTION Get_Printer_Test RETURN VARCHAR2 IS
    LANGUAGE JAVA
    NAME 'ListPrinters.listprinters() return String';
    This executes the code
    SQL> SELECT Get_Printer_Test FROM DUAL;
    GET_PRINTER_TEST
    No printers found
    This is the output found in the trace file in the UDUMP directory
    *** SESSION ID:(144.28) 2006-07-08 09:02:25.518
    Sorry. Printing is not allowed.

  • Problem with java print

    Hi, I'm have problems with java print (g2d). For example i want to print a String "ABC**************************DEF" on paper size 80mm width (invoice paper). I can print all that string with paper A4 size, but with paper size 80mm i have problem with that String, the result is "C*****************D" lost AB and EF. I think i had problem with paper size, pls help me. Thank you so much.
    My code is below:
    package app.util;
    To change this template, choose Tools | Templates
    and open the template in the editor.
    @author HUU NGHIA
    // Printing Sample code
    // This code demonstrates the Java 2 print mechanism
    import com.connection.Product;
    import java.awt.;
    import java.awt.print.;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Vector;
    // Define a class that is called per page that needs printing. It implements
    // the one and only method in the Printable interface : print. Note that
    // this is quite separate from the PrinterJob class print() method.
    // This method does not actually do any printing. All it does is write text
    // and/or graphics onto the passed page (graphics context). The calling
    // printer job object will then pass this page to the printer.
    public class PrinterController {
    public static void print(Vector<Product> products) {
    // Create an object that will hold all print parameters, such as
    // page size, printer resolution. In addition, it manages the print
    // process (job).
    PrinterJob job = PrinterJob.getPrinterJob();
    // It is first called to tell it what object will print each page.
    job.setPrintable(new PrintObject(products));
    // Then it is called to display the standard print options dialog.
    if (job.printDialog()) {
    // If the user has pressed OK (printDialog returns true), then go
    // ahead with the printing. This is started by the simple call to
    // the job print() method. When it runs, it calls the page print
    // object for page index 0. Then page index 1, 2, and so on
    // until NO_SUCH_PAGE is returned.
    try {
    job.print();
    } catch (PrinterException e) {
    e.printStackTrace();
    class PrintObject implements Printable {
    Vector<Product> products;
    public PrintObject(Vector<Product> products) {
    this.products = products;
    public int print(Graphics g, PageFormat f, int pageIndex) {
    Graphics2D g2 = (Graphics2D) g; // Allow use of Java 2 graphics on
    // the print pages :
    System.out.println("f.getImageableX(): " f.getImageableX());
    // A simple circle to go on the second page (index = 1).
    switch (pageIndex) {
    case 0:
    printInvoiceTemplate(g2, products);
    return PAGE_EXISTS;
    // case 1 : g2.setColor(Color.red); // Page 2 : print a circle
    // g2.draw(circle);
    // return PAGE_EXISTS;
    default:
    return NO_SUCH_PAGE; // No other pages
    public String getDate(){
    Date d = new Date();
    SimpleDateFormat sp = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    return sp.format(d);
    private void printInvoiceTemplate(Graphics2D g2, Vector<Product> products) {
    //System.out.println("#######" cardInfo.getTranType());
    int alignY = 40;
    int alignXCenter = 60;
    int enterSpace = 15;
    int xProductName = 10;
    int xUnit = 85;
    int xAmt = 110;
    int xTotal = 155;
    int yEndData = 0;
    int totalAll = 0;
    g2.setColor(Color.black); // Page 1 : print a rectangle
    g2.setFont(new Font("Verdana", 0, 8));
    g2.drawString("ABC", alignXCenter, alignY);
    g2.drawString("123WWW", alignXCenter, alignY enterSpace *1);
    g2.drawString("Phone: (08)62891633", alignXCenter, alignY enterSpace*2);
    g2.setFont(new Font("Verdana", 1, 12));
    g2.drawString("Invoice", alignXCenter - 10, alignY enterSpace*4);
    products = new Vector<Product>();
    for (int i = 0; i < 10; i+) {
    Product product = new Product();
    product.setProductName("ZESTORETIC TAB 20MG B/28" i);
    product.setUnit("v"+i);
    product.setAmt(5+i);
    product.setPrice(50000+i);
    products.add(product);
    for (int i = 0; i < products.size(); i+) {
    System.err.println(i);
    int total = products.get(i).getAmt()*products.get(i).getPrice();
    g2.drawString(i+1+"."products.get(i).getProductName(), xProductName+2, alignY enterSpace(8+(i*2)));
    g2.drawString(products.get(i).getUnit(), xUnit+5, alignY enterSpace*(9(i*2)));
    g2.drawString(products.get(i).getAmt()"x"+AppUtils.formatPrice(products.get(i).getPrice())"", xAmt+5, alignY enterSpace*(9(i*2)));
    g2.drawString(AppUtils.formatPrice(total), xTotal+15, alignY enterSpace*(9(i*2)));
    yEndData = 9+(i*2);
    totalAll = totalAll total;
    System.out.println(yEndData);
    g2.drawLine(xProductName, alignY enterSpace*(yEndData 1), 210, alignY enterSpace*(yEndData 1));
    g2.drawString(AppUtils.formatPrice(totalAll)" VND", xAmt, alignY enterSpace*(yEndData 2));
    g2.drawString("Thank you", alignXCenter, alignY enterSpace*(yEndData 4));
    g2.drawString("***", alignXCenter 30, alignY enterSpace*(yEndData + 5));
    public static void main(String[] args) {
    PrinterController.print(null);
    }

    When you posted you didn't use code tags, as a result the forum software has interpreted some of your characters in your program as screen formatting codes and has corrupted your post--the most easily observable change is the bolded characters in you post. Please repost your code using code tags so people will be helping with uncorrupted code.

  • Java Print Service - PDF

    I want to use the Java Print Service(JPS) API to programatically send
    PDF files to a printer. I need to send these files to the printer
    without any user intervention.
    At present i am trying to print on HP Laserjet 5100 series.
    I am able to print text files,Images (Jpeg) but have not been successfull in printing
    PDF files.
    DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
    DocFlavor flavor =new DocFlavor("application/pdf", "java.io.InputStream");
    The error I recieve is "Invalid Flavor". I have tried sending the PDF to the
    printer using a Document Flavor of INPUT_STREAM.AUTOSENSE.
    I also tried with
    DocFlavor flavor =new DocFlavor("application/octet-stream", "java.io.InputStream");
    When I do
    this the PDF file gets sent to the printer but what actually gets
    printed is garbage (control characters, overtyping, etc...).
    It appears the printer does not directly support PDF printing. The
    interesting thing is that I if I bring up a PDF file using Adobe Reader
    and press the Print button the file does get printed successfully!
    Can someone help me explain why Adobe Reader can print the file
    successfully but I am unable to do it programattically? Can someone
    suggest a different approach to take?.
    Regards,
    Raghu

    I suspect that it is because Adobe Reader isn't trying to print using the printer's non-existent PDF support. It is probably just sending generic image data to the printer as you would if you were printing Java 2D graphics using JPS.
    - Tomas

  • Where's the Java Print Preview Option?

    I've tested v13 for a few weeks now, and the only apparent problem I'm having surrounds the pdf printer. We have Adobe Pro-9 installed on our clients.
    When selecting Print Preview or Advanced Print, I can't get past the "Contract Manager pdf Printer" error.
    Previous versions provided a configuration option between Java and pdf... where'd that option go? I can't seem to locate it.
    Thanks in advance...

    There is no option anymore for Java printing vs ActiveX vs anything else. PDF printing is the only choice. What is the exact error message? Log in to the CM13 web server as the account used to start the service and verify the CM PDF Printer is available. If not, I believe you can install the PDF printer directly from the amyuni folder on the CD, then you may need to rename the printer to Contract Manager PDF Printer.

Maybe you are looking for