I'm new to Print Services

Hello all,
I'm having trouble getting Java to print something out.
I created this simple program to check the different available DocFlavors supported by my default print service. This program uses JOptionPane to report the name of the default printer and reports each DocFlavor supported.
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;
import javax.swing.JOptionPane;
public class PrinterInspector
     public static void main(String[] args) throws Exception
          PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
          DocFlavor[] flavors = defaultService.getSupportedDocFlavors();
          JOptionPane.showMessageDialog(null, defaultService.getName());
          if (flavors.length == 0) JOptionPane.showMessageDialog(null, "No Printer Support");
          for (int k = 0; k < flavors.length; k++){
               JOptionPane.showMessageDialog(null, "Supported flavor is "+flavors[k]);
                System.exit(0);
}This program works fine, and I chose to use the supported DocFlavor.INPUT_STREAM.AUTOSENSE. I then revised the program with the following code snippet.
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;
import javax.swing.JOptionPane;
public class PrinterInspector
     public static void main(String[] args) throws Exception
          String filename = "PrintPS.java";
               PrintRequestAttributeSet pras =
                 new HashPrintRequestAttributeSet();
                 PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
                DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
          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);
}This program runs and exits without any reported errors. However, the default printer only starts the warm up process without printing anything out. The printer seems to get the message from the print job, but the printer seems to be waiting for something.
Anyone have any suggestions?

You might want to attach a PrintJobListener to your job. That might give you an idea what is going on ...

Similar Messages

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

  • Print service lookup, and permissions

    I have written up an application which prints out text to the printer, using the new java print services API. The problem I have is that the i don't get any retuurned services from the lookup, unless i enable all permissions in my java.policy file (it usually has some security settings in there). Does anyone know the kind of permissions that is required for printers to be visible to the application?

    Hi, i've the same problem and i allready use the security option RuntimePermission "queuePrintJob" into the java.policy file.
    The problem is : if i specify in the java.policy "AllPermision". i get a PrintService array from PrintServiceLookup.lookupPrintServices(null,null). But if i only specified "queuePrintJob" RuntimePermission option, the funtion return an array of length 0.
    i guess that i need specified more java policy options to gain access to the printer information, but i can found information about it ....

  • I have created a family recipe book in iBooks - can I print it using iPhoto's print service?

    I have created a family recipe book in iBooks - can I print it using iPhoto's print service? I don't want to print it on our home printer - I want to print multiple copies for family members through the Apple iPhoto book printing service.  Can anyone help me please?

    There is no Apple print service for iBooks, and iPhoto can also only print photo books created in iPhoto.
    Print your iBook to pdf. Then you have several option:
    Save the pdf to a thumbsdrive/stick  and take it to the nearest print shop close to your home.
    Search online for "self publishing" services available in your country.
    Recreate your book as an iPhoto Book. This will be a lot of work, since iPhoto's templates are more suitable for Picture books than books with lots of formatted text. To speed things up, you could use "Preview" to export the pages of your book as jpegs (high quality, at least 300 dpi) and add themas full-page photos to a new PhotoBook. This can be sent to apple for printing.
    But the first two options would be much less trouble and probably be less expensive.
    -- Léonie

  • In Printer Services box, i get the message "unable to perform the operation"

    HP Officejet H470wbt.  Using via bluetooth.  i have recently installed a new ink service module and a black toner cartridge. Now I get the following message when trying to view ink levels in the printer services area--"unable to perform the operation"

    "Clear the Cache": Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"<br />
    "Remove the Cookies" from sites that cause problems: Tools > Options > Privacy > Cookies: "Show Cookies"<br />
    <br />
    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).<br />
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]

  • I can't go further "waiting for Printer Services" on Mac OS X 10.3 can U?

    Evening, I'm a new user, and ocassionally use my iBook.I turned it on but it takes ONE HOUR to get to the prompt Waiting for Printing Services. I was advised to re boot but no success, I guess this all happened after i tried to update latest version.
    I appreciate if you can help!!!

    I am working on a friend's Ibook, I am a PC IT, and know very little about Mac's so please bare with me in helping (1st grade Mac user).
    In my Mac fixing journey, I have used:
    1. Repair Disk = no repairs found to fix
    2. Repair Permissions = stalls and gives a prompt disconnected quit and restart, did that same prompt
    3. Booted in safe mode, gets to the same point "waiting for Printing Services" and then fades out and shuts itself down after a long period.
    4. I have tried to holding down opt, apple, p & r keys to reset "pram" = no go.
    5. Removed the power source and batter to reset computer.
    6. Booted computer connected into the printer and not connected to the computer. Same freeze place.
    After all this being done,and reading alot in here, I purchased disk warrior, it corrected a few errors, rebuilt and rebooted...only to come back to "waiting for Printing Services" and then freeze.
    Anyone have anything else they can help me with, that might get me passed this problem??
    Thanks in Advance for any advice!!
    Sav
    Ibook G4   Mac OS X (10.0.x)  

  • Adding Printer as a scanner in print service role (Distributed scan server), would it be possible in windows server 2008 r2 !!

    Hello All 
    I have a sharp printer that support scanniing as well and my question is : 
    I want to getting use from manage scanner service role that is belonging to the print service role in windows server 2008 , which has the feature of passing the scanned document to users shared folders which are exist in the same server.
    but when i try to add my printer as a scanner it did not accept .. so i cant proceed with my objective, which is allowing users to pass their scanned docs to their shared folder
    Any idea ?

    Can i scan to network shared folder without adding the used credentials, i am looking for this distributed scan features for this issue.
    now each time new user will come i will create for him a shared folder with his username and password then i will go to the printer web base page and add this shared folder to the address book, but i need the user to come to add his password. how i can tell
    the printer to authenticate him and directt his scan to his shared folder without asking him to enter his password to be able to create an address book for him ?? any help
    Thanks in advance !

  • Export for online printing service question...

    Hi all...I am new to all this exporting business so please bear with me. In the past if i wanted prints made i just burnt them to a disk and took the disk to a local photo lab to have printed. So the question is when using an online printing service such as Mpix, would i just export versions as original sized jpegs and send them to the printing service and that's it or do i also have to mess with the dpi setting? I noticed the default dpi setting is 72 for all the export presets. Any help here would be appreciated. Thanks in advance...Dave

    hello, dave
    quote: "when using an online printing service such as Mpix, would i just export versions as original sized jpegs and send them to the printing service and that's it or do i also have to mess with the dpi setting?"
    when someone else is doing your printing always ask them how they want your Versions delivered first prior to burning the DVD, for example, 16bit TIFF, 8bit TIFF, colorsync (color mangement), dpi...there is an excellent tutorial/information on this in Aperture's help menu "Photography Fundamentals"
    what i do is edit the photograph by softproofing to the printer used. in Aperture select the Proofing Profile & then Onscreen Proofing
    victor

  • Print Service problem

    I'm trying to print using print service. I do the following:
    Doc getPrintDoc()
    Doc doc = null;
    DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8;
    StreamPrintServiceFactory[] psFactories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,flavor.BYTE_ARRAY.PCL.getMimeType());
    try
    File f=new File(GlobalVariables.REPORT_TMP_DIR+"\\"+GlobalVariables.REPORT_FILE_NAME);
    System.out.println("path: "+f.getPath());
    FileOutputStream fos = new FileOutputStream(f);
    // ByteArrayInputStream bis = new ByteArrayInputStream(pane.getText().getBytes());
    // StreamPrintService psService = psFactories[0].getPrintService(fos);
    doc = new SimpleDoc(fos, flavor, null);
    catch (FileNotFoundException fnfe) {fnfe.printStackTrace();}
    return doc;
    void printUsingPrintServices()
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();
    DocPrintJob printJob = service.createPrintJob();
    try {printJob.print(getPrintDoc(), aset);}
    catch (PrintException pe) {pe.printStackTrace();}
    All the time i get the same excaption:
    java.lang.IllegalArgumentException: data is not of declared type
         at javax.print.SimpleDoc.<init>(SimpleDoc.java:82)

    At a guess, your fos doesn't match your flavor (see the API for SimpleDoc). FileOutputStreams are used for writing data to a file. You want to read data from a file into the print service, so use a FileInputStream instead.

  • Print Services: servername.local is "busy"

    We will soon be getting some new Mac OS X 10.6 (Snow Leopard)-only Macs at work. Since AppleTalk is no longer available to these Macs, I thought I'd set-up some Bonjour queues using one of our Mac OS X 10.5.8 Servers. (Of the 20 printers we have only three have Bonjour available.) The Snow Leopard clients can find the new printer I set up (however they cannot automatically discover the printer driver), but printing fails. As soon as a Mac OS X 10.6.1 client tries to print to this queue an error dialog appears in the printer queue in the Dock that says, "Network host 'SERVERNAME.local' is busy, will retry in 30 seconds." I'm fairly certain the queue should be configured for "SERVERNAME.companyname.net" not ".local". The server is set-up correctly in DNS (it's also the Open Directory Server) but something in the print services configuration must be off. I can't find any way to see or manually configure the queue...
    -Doug

    Did you ever get this resolved? I'm having the same issue. I haven't had much time to troubleshoot it yet though...

  • Non standard format images from the iPhoto print service

    Can anyone tell me how to get the iPhoto print service to leave my images alone? They default to filling their 10 x 8 or 7 x 5 paper sizes. Nowhere on the order form do they tell you they're going to do this and I can't find anywhere to tell them not to.
    They also supplied the prints in neat card wallets with "Do not bend" in nice red boxes printed on them. These were then dispatched in a plain white envelope with no such notices on it. Not surprisingly the prints arrived bent!

    Welcome to the Apple Discussions. When you click on the Buy button the available print sizes that Apple provides are displayed and you have to fill in how many of each you want. There is no custom size available, at least here in the states. What size(s) did you select in the order window?
    Click to view full size
    Didn't you get a similar window over there?
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto (iPhoto.Library for iPhoto 5 and earlier versions) database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger or later), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. There are versions that are compatible with iPhoto 5, 6, 7 and 8 libraries and Tiger and Leopard. Just put the application in the Dock and click on it whenever you want to backup the dB file. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.
    NOTE: The new rebuild option in iPhoto 09 (v. 8.0.2), Rebuild the iPhoto Library Database from automatic backup" makes this tip obsolete.

  • IPhoto printing service not available in Australia?

    Has anyone heard any news as to why the iPhoto printing service is not available in Australia? It's very disappointing as this was a great selling point to me, I just presumed that it may take time to set up, but still nothing...
    I can still print calenders, cards & prints off my home printer of course, but it's not the same as professional printing. It seems a shame as the software costs the same for everyone, but we have features that we can't use.
    Does anyone know why this is?
    Cheers!
    emac 1.42GHz PPP G4   Mac OS X (10.4.7)  

    No comment on why Apple has not made this service available themselves in Australia, but there are a number of other options. For the ultimate in convenience and excellent quality, you can use digitaldavinci.com.au. They have an iPhoto plugin which will let you send books, cards and calendars to them. So this is pretty much the same as the Apple service anyway, although I think - but haven't checked myself - that the price is a bit higher.
    Alternatively, I have had very good results sending a PDF of a book to myreflections.com.au. This is obviously not quite as convenient, but the quality is still very good and the price even better.
    So there are definitely printing options available from iPhoto, especially for books, not so much for prints, and at least one option I know of for calendars and cards. I haven't used the calendar or card service though, just the book printing service from both DDV and MyReflections.
    Hope this helps.

  • Can't locate any printers (w/ Java Print Service)

    Hi all,
    I'm using the following code to locate print services on my Windows 2000 laptop:
    private PrintService[] drucker;
    private DocFlavor format = DocFlavor.INPUT_STREAM.TEXT_HTML_HOST;
    private Doc output;
    private PrintRequestAttributeSet printerAttributes;
    private FileInputStream stream;
    public PrintHandler() {
    printerAttributes = new HashPrintRequestAttributeSet();
    printerAttributes.add(OrientationRequested.LANDSCAPE);
    printerAttributes.add(MediaSizeName.ISO_A4);
    drucker = PrintServiceLookup.lookupPrintServices(format, printerAttributes);
    Although there are several printers installed my app can't find any. I'm pretty sure that they support the attributes.
    What am I doing wrong?
    Thanks for your help,
    Ulf Moehring

    try this:
    PrintService[] availableServices = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);That will give you a list of all printable printers.
    Then if you wish, you can do:
    javax.swing.DefaultComboBoxModel printerCM = new javax.swing.DefaultComboBoxModel();
    for(int i = 0; i < availableServices.length; i++) {
        printerCM.addElement(availableServices.getName());
    comboBoxPrinter.setModel(printerCM);
    Hope that helps,
    James.

  • Print Services won't quit

    Hi all,
    I have a OS X 10.3.9 Server that I attempted to share a printer on.
    The printer is an Epson connected to a usb port on the server.
    The printer was sharing just fine until I tried to share it to a Windows machine. After I tried to start Windows Services, this operation turned off the network interface I was using to access the net. After I fixed that problem in the Network System Pref. Pane, the printer can't be shared to any of the local network macs that it was working fine on before. Not only that, I can't get the server manager software to stop printing services, either by the Server Manager Program or the command line. The print log returns:
    2006-01-23 13:03:34 -0800 [20962] Stopping Print Service...
    2006-01-23 13:03:34 -0800 [20962] Stopping print sharing. Service: SMB.
    2006-01-23 13:03:34 -0800 [20962] Print Service Shutdown reported errors.
    What the heck does that mean?
    I can add and delete queues. But everytime I add a new queue it comes up with my old settings with "smb" printer sharing enabled and it won't let me change it. Everytime I click the check-box to turn "smb" or any other printer setting off or on, it won't let me!! And I as I stated in the beginning I can't get the print services to stop or restart! I don't want to restart the server quite yet. I am almost afraid that its gonna be even more messed up after the restart. I even tried to edit the config file by dragging it to the small icon in the corner of the settings window to the desktop and editing it in BBEDIT. When I drag the changed file back onto the window it won't take the changes.
    Anyway, I couldn't figure out where these config files for the Server Manager Program are to delete before I restart.
    Any help or suggestions would be greatlty appreciated.
    Thank you,
    Hassan
    PowerMac G4 Dual-500   Mac OS X (10.3.9)  

    Never got one answer, give up

  • Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

    Hello,
    I'm getting an error when trying to add Print Services role in Windows 2012 Standard. I'm getting the same error whether I use the GUI or from PowerShell.
    This is a new server install.
    The PowerShell error follows:
    add-windowsfeature : The request to add or remove features on the specified server failed.
    Installation of one or more roles, role services, or features failed.
    The referenced assembly could not be found. Error: 0x80073701
    At line:1 char:1
    + add-windowsfeature print-services
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (@{Vhd=; Credent...Name=localhost}:PSObject) [Install-WindowsFeature],
        Exception
        + FullyQualifiedErrorId : DISMAPI_Error__Failed_To_Enable_Updates,Microsoft.Windows.ServerManager.Commands.AddWind
       owsFeatureCommand
    Success Restart Needed Exit Code      Feature Result
    False   No             Failed         {}
    Any help with this issue will be greatly appreciated.

    Hi,
    I think you should start with chkdsk C: /F and sfc /scannow.
    Regards.
    Vivian Wang

Maybe you are looking for

  • Windows Vista Drivers for 1820 and 1616 - Lets have some drivers ple

    RePost from http://www.productionforums.com/view...?p=47643#47643<img alt="" src="http://www.productionforums.com/images/icons/icon8.gif[/img]?Lets have some drivers please <span class="postdetails">Windows Vista Drivers for 820 and 66 I hate to say

  • How to change the label of a link based on a condition in a report.

    Hi all, I have a report, in which i created a link. i want the the label of the link to change based on a column value. for eg. i created report based on emp table which has a link on empno . if the deptno of the employee is 10 i want the link to be

  • What is the program in SRM to convert a shopping cart to be a purchase req?

    SRM gurus, What is the program in SRM to convert a shopping cart to be a purchase requisition? I intented to put some break points in some related programs/BADIs and to see if those program will be called when a shopping cart is converted to a purcha

  • PS CS1 shuts down after initialization

    I have been using PSCS1 on this laptop for ove 8 months when suddenly one day, I open PS and it goes through initialization, screen comes up ready for work and 1-3 seconds later it closes.  I can see that PS is still running as a process, but the GUI

  • Oracle Standalone DB 11g installation with ASM on Windows 2008

    Hi Experts, I would like to install Oracle Database 11g R2 on Windows 2008 with ASM . Since I want to do it as a standalone database server , I did not confiugre any shared storage. I have a single disk on my machine with 1 TB space. There is a free