My Program Won't Print when its supposed to

I've been trying to get a program that will automatically print txt files just by running it. Here's what I've come up with so far:
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.*;
import java.awt.print.*;
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.*;
import javax.*;
public class PrintTests8
public static void main(String[] args)
try
// Open the text file
InputStream is = new BufferedInputStream(new FileInputStream("test.txt"));
// Find the default service
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
// Create the print job
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);
// Print it
job.print(doc, null);
// It is now safe to close the input stream
is.close();
catch (PrintException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
}This will print out the file, but the problem is that it will only print it when another job, printed using in the normal, Ctrl+P type way, is printed. I hope that I can get help from you guys on this.

This error comes up:
sun.print.PrintJobFlavorException: invalid flavor
at sun.print.Win32PrintJob.print(Win32PrintJob.java:327)
at PrintTests8.main(PrintTests8.java:42)
And sorry for being impatient.

Similar Messages

  • The cyan color won't print when using our HP Pro 6500 Officejet printer

    the cyan color won't print when using our HP Pro 6500 Officejet printer.  Can I get help with this?

    This doesn't make sense. The printer is exhibiting behavior noticed when a network printer is connected to a laptop while the laptop is connected to a VPN. But in this case, neither the printer is connected on a network, not is the laptop connected to a VPN per se.
    Are you sure all the latest drivers for your laptop have been installed? That's pretty much the only thing I can think of right now.
    Make it easier for other people to find solutions, by marking my answer with \'Accept as Solution\' if it solves your problem.
    Click on the BLUE KUDOS button on the left to say "Thanks"
    I am an ex-HP Employee.

  • Adobe Reader X won't print all pages supposed to; Why Not?

    Adobe Reader X won't print all pages supposed to; Why Not?

    Similar situation here.  Have multiple users getting hung up after the progress bar for printing appears.
    If forced to quit, prints do eventually appear sometimes.  Here's my app event error:
    (System is XP 32bit, direct connect via USB printer)

  • Program won't exit when reading in gif?!?

    Hi,
    I have written a class (see code below) that has a single method to read in two gifs, superimpose them, add text and then write the result to a jpeg file.
    I test this in a simple main method (again see below). javac test.java, java test
    The problem is that the program will not terminate. The final System.out.println() command is displayed in the terminal. It has to be halted with ctrl+c.
    I have traced the problem to the image being read in! If I comment out the images being read in - in the MapMaker constructor (also commenting out where the images are used) - the program terminates correctly.
    There are no exceptions flying around either!
    Any ideas? I guess some system resource isn't being cleared, but don't know how to do this!
    I can't use System.exit() because this class will be used in a .jsp page that will use the jpeg created!
    Thanks in advance
    Matt
    MapMaker.java:
    import java.awt.*;
    import java.awt.event.*;
    import com.sun.image.codec.jpeg.*;
    import java.awt.image.BufferedImage;
    import java.awt.image.DataBuffer;
    import java.awt.geom.AffineTransform;
    import java.io.*;
    import javax.swing.*;
    import java.awt.MediaTracker;
    import java.awt.Canvas;
    public class MapMaker extends Canvas implements java.io.Serializable{
    private Image arrow;
    // Read in the 2 .gif files of the arrow and the map
    public MapMaker() {
    // When commenting out these lines, the program works fine
    arrow = Toolkit.getDefaultToolkit().getImage ("arrow2.gif");
    try {
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(arrow, 0);
    tracker.waitForID(0);
    } catch (InterruptedException e) {
    System.out.println("Interrupted exception caught ");
    e.printStackTrace();
    // createMap generates a .jpg file fo the map with an
    // arrow and wind direction
    public void createMap() {
    // Create a new Buffered image and associated Graphics 2D object
    // Draw to the Graphics 2D object
    BufferedImage bi = new BufferedImage(200,200,BufferedImage.TYPE_INT_RGB);
    Graphics2D big = bi.createGraphics();
    // Set the rendering hints
    big.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    big.setRenderingHint(RenderingHints.KEY_RENDERING,
    RenderingHints.VALUE_RENDER_QUALITY);
    big.setBackground(Color.white);
    big.clearRect(0, 0, 200, 200);
    // Here I would add the images to big
    // Add text
    big.setFont(new Font("Dialog", Font.BOLD, 12));
    big.setColor(Color.green);
    big.drawString("12", 138, 128);
    try {
    // write the buffered image to a jpg file
    File file = new File("test.jpg");
    FileOutputStream out = new FileOutputStream(file);
         // encodes bi as a JPEG data stream
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
    param.setQuality(1.0f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(bi);
    out.close();
    } catch (Exception ex) {
    System.out.println("Failure to write JPEG file");
    return;
    } // createMap
    // This tests the above class
    import MapMaker;
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.math.BigDecimal;
    public class test {
    public static final void main( String args[] ) {
    try{
    System.out.println("Making new MapMaker object");
    MapMaker mapMaker = new MapMaker();
    System.out.println("Making new map");
    mapMaker.createMap();
    System.out.println("Finished making the new map");
    catch (Exception e){
    System.out.println("Top level exceptions\n");
    e.printStackTrace();
    System.out.println("All the way");
    return;
    }

    If anyones interested. It turns out that this is a feature!
    When windows resources (i.e. reading in an image) are used. Java programs won't exit automatically.
    They have to be closed with System.exit()

  • LaserJet 1320tn Pausing When Trying To Print - Won't Print When Resumed

    Hello Everyone,
    Until about a week ago users in my office who print to a networked LaserJet 1320tn were able to print to it. Now, when trying to print a document, the printer pauses itself, and continues to pause itself when I try to resume printing. Here is the log file from the printer when trying to un-pause the printer.
    Wednesday, October 1, 2008 5:27:55 PM US/Pacific
    I [01/Oct/2008:17:28:01 -0700] [Job ???] Request file type is application/postscript.
    I [01/Oct/2008:17:28:01 -0700] [Job 6070] Adding start banner page "none".
    I [01/Oct/2008:17:28:01 -0700] [Job 6070] Adding end banner page "none".
    I [01/Oct/2008:17:28:01 -0700] [Job 6070] File of type application/postscript queued by "kristianmartin".
    I [01/Oct/2008:17:28:06 -0700] Saving printers.conf...
    I [01/Oct/2008:17:28:06 -0700] Printer "Spanky" started by "root".
    I [01/Oct/2008:17:28:06 -0700] [Job 6070] Started filter /usr/libexec/cups/filter/pstops (PID 455)
    I [01/Oct/2008:17:28:06 -0700] [Job 6070] Started filter /Library/Printers/hp/filter/hpPostProcessing.bundle/Contents/MacOS/hpPostProces sing (PID 456)
    I [01/Oct/2008:17:28:06 -0700] [Job 6070] Started backend /usr/libexec/cups/backend/mdns (PID 457)
    E [01/Oct/2008:17:28:09 -0700] PID 457 (/usr/libexec/cups/backend/mdns) stopped with status 1!
    I [01/Oct/2008:17:28:09 -0700] Hint: Try setting the LogLevel to "debug" to find out more.
    I [01/Oct/2008:17:28:09 -0700] [Job 6070] Backend returned status 1 (failed)
    I [01/Oct/2008:17:28:09 -0700] Saving printers.conf...
    If you have any suggestions please let me know. I am willing to try anything.

    Can you show us the new error_log?
    I'm starting to think you may need to reinstall OS X using the Archive and Install option.
    Before that, try these:
    http://support.apple.com/kb/HT1341
    http://support.apple.com/kb/TS1417 (go to try disk utility)

  • Page created with iWeb won't print in its entirety.

    I created pages in iWeb but when I go to my browser and try and print the pages, only part of the page prints. The whole page is shown, but only part prints. Furthermore, there are several blank pages that print, but not all the content. Is there a limit on how much text/content to put on each page?

    Paper size is Letter (not surprising there!) But I am not clear why paper size should matter. That is what multiple pages are for. If something won't fit on one page, should it not print on page 2, 3, and so on? I'm not sure what you mean by "changing the scaling in the print setup". When I go to Preferences (I'm on a Mac) and select Printer Setup, I only have a few choices, like printer, paper, and scale. Scale is a percentage, like 100%.
    All this said, users should not be expected to make any such changes to print off a page I create for them. I am looking for changes I need to make at my end to make it work for users without extra effort at their end.
    It sounds like a limitation of iWeb. I am not an HTML developer, so I am looking for an "easy way out" in developing a web page. Maybe I just have to confine my content to about a printed page's worth.

  • Program won't print: "Error Prop Res DLL Not Loaded"

    Mine is a fully legitimate copy of InDesign, but this error message appears when I try to print to my printer. If I swat the message a dozen times, the printer then prints a blank page.

    Try following the guide from the Microsoft Support page: http://support.microsoft.com/kb/918730. Just update the path environment variable to point to the folder where the printer drivers are installed, restart Indesign and test if it workes.
    Here's the exact text from that page:
    Let me fix it myself
    To update the Path environment variable, follow these steps:
    Click Start, click Control Panel, click Performance and Maintenance, and then click System.
    Click the Advanced tab.
    Click Environment Variables.
    Under System variables, click the Path variable, and then click Edit.
    Press END to move the pointer to the end of the path.
    Type a semicolon (;), and then type the path of the printer driver file.
    On a computer that is running a 32-bit version of Microsoft Windows, type the following default path: C:\Windows\System32\Spool\Drivers\W32X86\3
    On a computer that is running a 64-bit version of Windows, type the following default path: C:\Windows\System32\Spool\Drivers\X64\3
    For example, after you update the Path variable on a computer that is running a 32-bit version of Windows,  the path would resemble the following: %SystemRoot%\System32;%systemroot%;C:\Windows\System32\Spool\Drivers\W32X86\3
    Click OK to close the Edit System Variable dialog box.
    Click OK to close the Environment Variables dialog box.
    Click OK to close the System Properties dialog box.
    If this doesn't work try method 1 in the guide.
    Good luck.

  • Windows 7 Backup and Restore Program won't respond when I click on Back up Now or Change Settings.

    The system rebooted when I was doing a backup to NAS. After it came back up it said I had 'canceled' the backup but now it won't respond to Back up Now or Change settings. It does respond to other options.

    Hi,
    You can attempt to run "sdclt.exe /configure" to start windows backup.
    Thanks :)
    Andy Altmann
    TechNet Community Support

  • Officejet 6500 won't print when Laptop is on the network.

    We have a HP Officejet 6500 that connects to a laptop vis USB plug. It worked fine for a few weeks, but now anytime the laptop is connected to the office network by ethernet is will not print. Once you unplug the network cable from the laptop it prints fine. The laptop is running windows 7 and we installed the printer using the Windows 7 drivers from here. Please help!

    This doesn't make sense. The printer is exhibiting behavior noticed when a network printer is connected to a laptop while the laptop is connected to a VPN. But in this case, neither the printer is connected on a network, not is the laptop connected to a VPN per se.
    Are you sure all the latest drivers for your laptop have been installed? That's pretty much the only thing I can think of right now.
    Make it easier for other people to find solutions, by marking my answer with \'Accept as Solution\' if it solves your problem.
    Click on the BLUE KUDOS button on the left to say "Thanks"
    I am an ex-HP Employee.

  • Printer won't print when I try to copy

    I have the photosmart all in one c410 series. Cartridges are hp and full. All of a sudden I am having trouble printing. I can scan image into computer and it will print. But when I try to just copy the sheet comes is blank. What is wrong?

    Hi @Maknmony 
    From what you have described, it sounds to me like the black ink is not working. Any black you may see on the pages that are printing is likely a composite black made up of the 3 colors. I can help you with this.
    Please begin with the steps in the following document; Fixing Print Quality Problems for the HP Photosmart Premium Fax All-in-One Printer Series (C410a, C4...
    If you complete all of the steps in the document above and the issue continues, my own personal recommendation, not one of HPs, is to use the solution offered in the following video.  I only suggest doing this if he printer and printhead are out of warranty.  Hot Water Printhead Flush - HP Ink Series Printers with removable Printhead.
    I have recommended this solution to others and have seen success, but I can not guarantee this will resolve the issue, it is an end of the line kind of effort. I hope it helps.
    PaganC wrote:
    flushing it worked, Yeah!!!!!!! thanks for your help.
    Although the printer might be out of warranty, if the issue persists, HP may be able to offer you something. Maybe they can offer you a discount on a newer model, or discuss the option of replacing the printhead!  If after all of our efforts the issue remains, I suggest calling HP. If you are in Canada or US call 800 474 6836, or you can Contact HP Worldwide.
    Thanks for reaching out to the HP Forums. I hope one of my recommendations resolves the issue.
    Please click the Thumbs up icon below to thank me for responding.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Please click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution.
    Sunshyn2005 - I work on behalf of HP

  • Canon MF4150 won't print when connecting through AP Extreme

    I have a MacBook 2.16 about 2 weeks old. I've bought an Airport Extreme and am trying to connect my Canon MF4150 into it but whenever I print it just won't happen. The print queue just shows the jobs as "stopped" and I cannot restart them.
    The printer log shows the following error
    I [12/Nov/2007:13:49:41 +1000] [Job 4] Adding start banner page "none".
    I [12/Nov/2007:13:49:41 +1000] [Job 4] Adding job file of type application/pdf.
    I [12/Nov/2007:13:49:41 +1000] [Job 4] Queued on "CanonMF4100Series" by "john".
    I [12/Nov/2007:13:49:41 +1000] [Job 4] Started filter /System/Library/Printers/Libraries/PrintJobMgr/Contents/MacOS/PrintJobMgr (PID 1358)
    E [12/Nov/2007:13:49:41 +1000] PID 1358 (/System/Library/Printers/Libraries/PrintJobMgr/Contents/MacOS/PrintJobMgr) stopped with status 144!
    I [12/Nov/2007:13:49:41 +1000] Hint: Try setting the LogLevel to "debug" to find out more.
    E [12/Nov/2007:13:49:41 +1000] [Job 4] Job stopped due to filter errors.
    The one other user on the network is using Vista and is printing fine to the printer. I'm using print driver 1.5 from the Canon website.
    Any thoughts or help you can give would be appreciated.

    You won't be able to get this combination working. There is something about the Canon UFR2 driver that doesn't 'see' the AEBS USB connected printer. Have a read of my posting on the Airport forum.
    http://discussions.apple.com/thread.jspa?threadID=1057102&tstart=30

  • Mac Book Pro won't wake when its been charging.

    I have had this problem for some time now. When I charge my Mac Book Pro over night. The next time I use it, It won't wake up for sleep mode and I have to restart the computer. Was wondering if there has been problems with this too. If so is thier a fix for this. I'm running MacBook Pro (mid 2012) with Retina display, OS X Mavericks (10.9).

    This is a BUG in Mavericks and or the Mac hardware. It goes into Standby mode after an extended period of inactivity and then Crashes when trying to come out of Standby mode completely Hanging the system and making you have to Restart it.
    There is quit a long thread on this subject.

  • MAIL PROGRAM WON'T OPEN when click on email link

    When I click on an email address when on the web, nothing happens.
    Something trys to open, the general "mail" icon pops up briefly in the dock, but fails.
    I would ideally like my gmail to open, but cannot find a way to set this up in Safari.
    Anyone know what to do?
    Thanks!

    From the Safari menu bar, select
              Safari ▹ Preferences... ▹ Extensions
    Turn all extensions OFF and test. If the problem is resolved, turn extensions back ON and then disable them one or a few at a time until you find the culprit.

  • Mail program won't open when clicking link in safari

    When I click on a "contact us" mail to link in safari, a new tab opens with top sites.Mail application never opens. In mail preferences , Mail is set to default. I am using maverick 10.9.2 and safari 7.0.3. It used to work.
    Thanks!!!!
    Shelley

    From the Safari menu bar, select
              Safari ▹ Preferences... ▹ Extensions
    Turn all extensions OFF and test. If the problem is resolved, turn extensions back ON and then disable them one or a few at a time until you find the culprit.

  • Printer won't print when sent a document

    Printer will print from my computer but not from another computer

    Hey Marill!
    Have you installed the software on the second computer? If not, you may be able to use ePrint to send to it if you have an ePrint compatible printer and have already setup the service, but if not you would need to download and install the software on the second computer (or do it from the disk). If you already have installed the software and it still isn't working, try our Print Diagnostic utility which can be found here.
    Hope this helps!
    If I have solved your issue, please feel free to provide kudos and make sure you mark this thread as solution provided!
    Although I work for HP, my posts and replies are my own opinion and not those of HP.

Maybe you are looking for