Connecting Printer by Printer Name

In my application I am using javax.print stubs to print a text file.But while running the appication I am getting error like ClassCastException.Anyone can you suggest me how to print the text file using javax.print
Below is my code:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.MediaSizeName;
import javax.print.attribute.standard.Sides;
public class PrintingService {
     * @param args
     public static void main(String[] args) {
          FileInputStream inStream = null;
          try {
          inStream = new FileInputStream("d:/cells.ps");
          } catch (FileNotFoundException ffne) {
          if (inStream == null) {
          return;
          DocFlavor psInFormat = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
          Doc myDoc = new SimpleDoc(inStream, psInFormat, null);
          PrintRequestAttributeSet aset =
               new HashPrintRequestAttributeSet();
          aset.add(new PrinterName("\\\\122.166.97.138//Canon iP1300", null));
          //aset.add(new Copies(5));
          aset.add( MediaSizeName.ISO_A4 );
          aset.add(Sides.DUPLEX);
          PrintService[] services =
          PrintServiceLookup.lookupPrintServices(psInFormat, aset);
          if (services.length > 0) {
          DocPrintJob job = services[0].createPrintJob();
          try {
               job.print(myDoc, aset);
          } catch (PrintException pe) {}
Edited by: user13656596 on Jan 11, 2011 1:39 AM

Thanks for reply.
This is the stack trace what I am getting.Please suggest me.
Exception in thread "main" java.lang.ClassCastException
at javax.print.attribute.AttributeSetUtilities.verifyAttributeValue(AttributeSetUtilities.java:534)
at javax.print.attribute.HashAttributeSet.add(HashAttributeSet.java:283)
at test.PrintingService.main(PrintingService.java:46)

Similar Messages

  • Cannot wirelessly connect printer- HP Photosmart C4780

    Hello everyone! I have scoured the internet and these forum pages for a solution, but could not find any. Anyways, I have a HP Photosmart C4780 and am unable to wirelessly print. My printer will not connect to the internet nor does it show a local network for my computer to print to. When I try to print off a Network Configuration Page, it will not let me. I click the "Ok" on the printer when that option is highlighted, however it takes my back to the wireless menu. I have an AT&T router that I believe does not have a WPS. I also have the latest software downloaded on my 2015 macbook pro. To make things more complicated, I do not have the set up wizard disk, and when I try to download the corresponding software to get the "HP Folder" on my computer, it goes through the installation process but does not show the folder once it is finished. Please help me!

    Hi , I see you have been looking for a way to reconnect your c4780 wirelessly with your Mac 10.10, I have actually helped with this before. Normally, it's an easy 3 step process to reconnect the printer but because you have Mac OS X 10.10 Yosemite which uses the driver from Apple, there is no software package from HP to configure the wireless. 
     So here's how you can do this;  Step 1:  Make sure your computer is connected to the correct network. Confirm your settings for your home network; HP Printers - Find Your Wireless WEP, WPA, WPA2 Password (Mac) Step 2:  Restore the Network Defaults on the printer so it's not holding onto any old information.* To do this you should be able to touch on Setup [Scan] front of the printer then choose Network and then Restore Network Defaults Note: If your wireless radio is not working correctly, let me know and I will send you a different reset in a private message.  Step 3:  This would normally be to use a USB cable and your printer software to configure the printer back onto the network but you will need to follow the directions from this similar post, copied here for you below; After you Restore Network Defaults, the radio will turn off (the blue LED will go out.) You may need to press the wireless button again to Enable Wireless (light should be flashing.) Put the computer on the printers network (temporary)1. Click on the Airport symbol on the top left side of the Mac screen
    2. Choose the network that look relative to the printer (might say HP setup or some variation of your printer name) - it may take a few minutes for it to appear Print the wireless network test - wait a few minutes to ensure the and computer have established an adhoc connection otherwise the report will not have an IP addressPress the Scan button (it also the Wireless menu button)Select Wireless SettingsNavigate to Wireless Test and select.The Wireless Network Test prints, look for and note the IP address. Open an Internet browser (Safari) and enter the IP address into the URL (address bar). Click on the network tab, on the left click on wireless or 802.11. At this point we are looking fore "start wizard" should be on the right hand side. Now just follow the on-screen prompts to configure your printer to the network.    Once we have successful configured the printer for your network you can put your computer back on your own network. Now you can add the printer to the System Preferences and print. (If you are unsure of how to do this see; Add or remove a printer.   Please let me know if these steps resolved your issue, or if there is anything else I can do to help.  I look forward to hearing from you!   Thanks, 

  • What are the icons next to the printer name in the print sheet?

    Ever since I upgraded to OS X Lion, I have noticed something different in the print dialogue.  First the technical info: I am using a 2009 Mac Mini (4 GB RAM, OS 10.7.3) and I have a couple of printers that I use - one is a Brother laser printer (shared from an iMac, running 10.6.8) and a Canon Pixma Pro 9000, connected via USB to a Time Capsule.
    When I hit Command-P to bring up the print sheet, I now get icons on the left hand side of some of the printer names in the printer list.  One looks like a road sign - diamond shaped with a walking person in it, and the other is a circle with a wavy line (tilde?) in it.  The other printer names have no icons next to them.  I gather that the circle-and-tilde means "printer not available" (or something similar) - even though the printer is there!!! And then I wonder why the other printer names have no icons, and I have no clue what the "walking person" sign means.
    I'm adding a couple of images so you all can see what I'm talking about:
    What do these icons mean?  I can find NO reference to them - even in Apple's knowledge base article http://support.apple.com/kb/HT4670 - this just looks like the screen shots from the 10.6 Snow Leopard page.  I looked in the OS X Lion Missing Manual, but it has the same screen shots with no explanation of the icons.
    This is pretty minor, but it's been bugging me for a while.   Any explanation or reference to these icons would be appreciated!
    Richard
    Message was edited by: Richard Williams Jr (had to correct the link!)

    Richard Williams Jr wrote:
    Wow, impressive, thank you!  Is there a listing or other resource available that can tell me what all these symbols mean?  Or are they the only ones?
    This Mac 101: Printing article mentions some of the icons you will see in 10.6. And there is also the Mac 101: Printing article for Lion that shows some symbols. Neither show the icon you are seeing for the Brother but this is icon has been around for a while and used for warnings/information alerts.

  • How to connect printer to wireless connection

    Hpdeskjet3050a all in one printer J611g How do you connect the printer to a wifi signal?

    Hi,
    Please read the following instructions:
       http://h10025.www1.hp.com/ewfrf/wc/document?docname=c02722113&cc=us&dlc=en&lc=en&product=5061082&tmp...
    If you already installed the software, you may find the wireless configuration as follows:
    Click Start, select All Programs, select HP,
    Select Your printer name,
    Select Printer Setup and Software Selection,
    Select eighter Convert a USB connected printer to wireless or Connect a new printer and Follow the onscreen instructions.
    Hope this helps.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • HELP: SP01: Printer Name is Invalid

    Hello SAP Friends/Gurus,
    I am getting "The printer name is invalid" error message in SP01, when trying to print in SAP:
    Windows/NT error 1801 [
    <my machine name>\<my printer name>]: "The printer name is invalid."
    The thing is, my machine and printer name are both correct. I even tried changing the settings of my printer (from its hostname to its IP address) in SPAD. My printer is directly connected to my computer.
    Also, I could not print using LOCL.
    Any suggestions on how to resolve this? Thank you very much in advance!
    Best Regards,
    Albert

    Hai,
    Are you using 'C' as your access method, check that.
    This message indicates that the printer name is invalid or otherwise incorrect.  Click on Start > Run, and enter the same UNC to see if the printer can be accessed manually.  If attempting to set the printer as default, the printer name and the share name must match exactly same (case sensitive also).
    Enter the UNC name of the printer (name and network path) as it is defined in the Microsoft Windows Print Manager.
    For example:
    P09330\P330
    http://help.sap.com/SAPHELP_NW70/helpdata/EN/26/ceea3b31aac554e10000000a114084/frameset.htm
    Regards,
    Yoganand.V

  • Invalid printer name error (-41002)

    While I use 'Print Report.vi with new HP Deskjet 5443 printer (connected to the computer by USB and configured as a deafault) I get Invalid printer name error (-41002). 
    The application is working properly with other printers.
    The "HP Deskjet 5400 Series" name appears in the printers list that was found by "Get Printers list.vi".
    The printer is printing properly with Word, Excel and other applications.
    I am working with Labview v8.00.

    Hi Alex,
    I have found a corrective action request in our R&D database that addresses this very error occurring, with HP-5940(USB) printers. I plan to add your feedback that it is happening for you as well with the HP 5443.
    Have you tried going to the printers entry in the control panel, getting the printer name there, and then entering that as a string constant into Print Report.vi ? Also, you can try leaving the input terminal empty and it should use the default printer.
    Let me know if either of these works for you.
    -Sam F, DAQ Marketing Manager
    Learn about measuring temperature
    Learn how to take voltage measurements
    Learn how to measure current

  • Unable to set printer name after latest update.

    I updated my airport extreme with the 7.4.1 updater and now am unable to configure a printer name for my USB connected Canon MP530 with the airport utility. The printer name field in Airport Utiliuty comes up blank, and the secondary device (FAX) has a name. The print queue ends up being named "Canon MP530 FAX - 1" If I set a name for the printer and reload, it is gone on startup. Looks like a bug in the new firmware. Anyone else see this problem?

    goodgrl125 wrote:
    It does not matter if I have WIFI or not the problem remains unchanged.
    Picture texts won't send/receive over wi-fi, you have to use your cellular connection.
    You might try sending yourself a picture text from your phone; that sometimes helps resolve the issue.

  • Connecting to USB connected printer via LPD

    Hi there,
    Does anyone know if you can access a USB attached printer using the LPD protocol? I cannot find this in the Time Capsule documentation.
    I'm helping a Yosemite user where Bonjour is not working and thus the USB connected printer is not being advertised in order to add it.
                     How to get Yosemite to see new printer driver for Canon via Bonjour            
    For other brands, the USB port has a name like Port1 or PR1. So I would like to know if the Time Capsule supports such a connection.
    Thanks
    PaHu

    Hello PAHU. I'm thrilled to have run across you on the Apple site. Your post (below) is exactly what I need help with:
    "Rather than use Bonjour, which seems to have a problem for some users who have updated to Yosemite, you can use one of the IP protocols included with OS X. To do so you will need to find the IP address the printer is using. If you need help with that, reply with the model of Canon you have.
    With the IP address noted, open Printers & Scanners and click the plus button to add. Select the IP icon and enter the Canon IP address in the Address field. Change the Protocol to LPD and leave the Queue blank. Change the Name to the model of Canon and then in the Use menu, select the appropriate Canon driver for your model. Click the Add button to complete the printer creation and then see if you can print."
    Kindly please tell me how to find my printer's IP address. I am desperately trying to reconnect to my Canon PIXMA MP500 since upgrading to Yosemite. I will be in your debt!
    Thank you most kindly!

  • Hp Deskjet 1010 Printer name change

    I tired to change the name of my printer. This is the message I keep getting, "Printer properties cannot be displayed. Double check the printer name and make sure that the printer is connected to the network". Someone please help. I think I messed something up.

    Welcome to the forums Tonya!
    I noticed your post about how you tried to rename the printer.
    Which operating system are you running and have you tried Uninstalling the Printer Software and reinstalling it? That should do the trick for you!
    If you are running Windows, you can also run the HP Print and Scan Doctor.
    Please let me know and I will certainly look into this some more for you!
    Have a great day
    R a i n b o w 7000I work on behalf of HP
    Click the “Kudos Thumbs Up" at the bottom of this post to say
    “Thanks” for helping!
    Click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution!

  • Error 0x00000709 operation could not be compleated Double check the printer name etc.

    After installing my new printer and removing all other printers from my computer I now can not make the only printer listed as my default printer. I get this error 0X00000709 operation could not be completed Double check the printer name and make sure it is connected. I have done all that over and over again. I also I have reinstalled the old printer software and tried to default to my new printer at that time and still the same error. I have checked my register and it has the old printer listed but does not allow me to change it. I now have removed all but the new printer from my computer but I still can not make it my default printer. Programs such as Adobe only recognizes the default printer (which is not there any more) and don't even list the new printer as an option. The printer works just fine accept with the programs that uses the default printer. The Windows Hardware and Device Troubleshooting finds the problem (printer not set as default)but can not fix it.
    I sure wish someone out there could help me get rid of the error and allow me to default my printer again. I have noticed other people have had this same issue with error 0X00000709 using other Windows versions as well. I have been trying to resolve this issue for the past three months and would appreciate any and all ideas.
    I have an HP Pavilion elite HPE 337C computer running with Window 7 and I installed my new HP LaserJet PRO CM1415fnw color MFP printer.  My old printer that I removed (but is still listed in my Regester) was an HP 6500 inkJet.

    After doing some research on the net:
    This link provided an answer:
    https://exploreb2b.com/articles/solving-error-0x00000709-cant-set-default-printer-problem
    Regedit -> HKEY_CURRENT_USER -> Software->Microsoft->Windows NT->Current Version->Windows
    One of the entries you should see in the right hand pane is“Device”. If the value for “Device” as noted under the “Data” area is anything other than the printer you are using, then highlight “Device” in the right hand pane with the mouse and press the delete key to remove it. (I edited it and put the name of the printer I wanted to be the default)
    VI.      Restart the computer so it starts with the altered Windows system registry. (Italics mine)

  • Printing from a WinXP PC to an iMacG5 USB connected printer

    My iP4000 is attached to my iMacG5 computer via USB and prints well when the print message is engaged from the iMacG5. The problem is that the printer refuses to print when the print request is made from my WinXP PC via home network. The WinXP PC is conneced to the iMacG5 via a Linksys wireless router. I followed the WinXP directions and used the "printers and fax" add printer wizard. It found the correct printer name and engaged file sharing. The canon printer utility says a print was being completed with no errors, however, no print has been made and nothing comes out of the printer. I have removed the print driver program and reinstalled it on my WinXP PC with the same results. How can I correct this problem?

    I have follwed the instructions provided in the html link but I still can not get my Lexmark 5470 to print. I even tried to add a printer using CUPS but that is not working either. Printer works great on the Mac and it will print if directly connected to the PC. I can not get it to print over my wireless network. Any suggestions are appreciated.

  • Saving file as PDF on Desktop I get notice "The Printer Name is invalid" How do I get a file to save as PDF?

    Trouble saving a large 93 page script Final Draft to a PDF file on Desktop. I get notice "The printer name is invalid"
    What to do?

    I don't think PDF Pack is connected to this in any way. It won't be part of the process.
    Take a look at After installing 7.1.3 on XP 64, trying to Save As PDF will return an Error Initializing Printer and a Printer Name Not …

  • Remove Printer Name from Crystal Report

    How can i remove the printer name from the Crystal Report so that the PrinterName property of the CRAXDRT.Report object in the RDC SDK is blank WITHOUT having the "No Printer" Option checkbox checked?
    Here's the scenerio.  When I first create a Report and don't go into Page Setup, PrinterName property is blank.  If I go into Page Setup and explicitly select a printer, PrinterName property equals the name of the printer selected.  If I check the "No Printer" checkbox in Page Setup, PrinterName property is blank.  But if i go back in and uncheck the "No Printer" checkbox in Page Setup, the PrinterName property equals the name of my Windows Default Printer.

    I'm still not sure what is unclear about my first question.  And I'm not sure how any of the info you are requesting is going to make any difference in answering my question.  And I'm not sure how your analogy fits here but ..
    Version of CR = 11.0.0.895
    CR Service Packs applied = None
    Web or Win app? = Win App
    OS? = Windows XP Service Pack 3
    Development language?  = Both Visual Basic 6 and C#.Net 2008
    Method of CR files deployment = email the .RPT file to a client
    Where were the runtime files downloaded from? = Runtimes are installed from Merge Modules donwload from SAP site
    What is the version of the craxdrt.dll on the deployed box? = 11.0.0.893
    So here are the exact steps so you can understand what is going on:
    I have the Crystal Reports Application open side-by-side with my Visual Basic development environment in debug mode so i can step through the code using the RDC SDK.
    1. I open the Crystal Reports Application and create a brand new report - "Test.RPT" and DO NOT go into Page Setup at all and save the report.
    2. In my Visual Basic development environment, i run the code that will generate the report, Here's the exact code
        Dim m_crApp As CRAXDRT.Application
        Dim m_crReport As CRAXDRT.Report
        Set m_crApp = New CRAXDRT.Application
        Set m_crReport = New CRAXDRT.Report
        Set m_crReport = m_crApp.OpenReport("Test.RPT")
    3. When i look at the PrinterName property in the CRAXDRT.Report object, it is blank.
        ie. crReport.PrinterName is equal to ""
    4. I reopen the Crystal Reports Application with report "Test.RPT" and go into Page Setup and check the "No Printer" option.
    5. I go back into my Visual Basic development environment and rerun the code that will generate the report.
    6. When i look at the PrinterName property in the CRAXDRT.Report object, it is still blank.
        ie.  crReport.PrinterName is equal to ""
    7. I reopen the Crystal Reports Application with report "Test.RPT" and go into Page Setup and uncheck the "No Printer" option. I have NOT specified any printer, nor have i clicked the "Printer..." button to setup a printer....i have just unchecked the "No Printer" option
    8. I go back into my Visual Basic development environment and rerun the code that will generate the report.
    9. When i look at the PrinterName property in the CRAXDRT.Report object, it is now set to my WINDOWS DEFAULT PRINTER, yet i had not specified any printer.
        ie.  crReport.PrinterName is equal to "
    MyNetwork\MyPrinter"
    PROBLEMS:
    1. The client needs the report to go to the default windows printer of their machine
    2. If the "No Printer" Option is checked, the Report does not print at all
    3. If the report is set to MY default windows printer and i give it to the client, at times it takes upwards of to a minute for the Print Dialog to disply.  As i've read on other forum posts, it appears Crystal is looking for MY printer on the clients machine and takes a minute before i realizes it can't find it and then sets it to the CLIENTS default windows printer.
    4. The client believes it is unreasonable to wait a minute for the print dialog to appear ...and i agree.
    5. I cannot change the code to use the Select Printer in the RDC SDK - it's a long explanation why but just suffice it to say that i cannot do this.
    All i want to do is either:
    1. Remove the Printer Name in the actual report from the Crystal Reports designer - basically undoing what Crystal did when i went into Page Setup.
    2. Via the RDC SDK, be able to detect the "No Printer" option is selected. Checkign CRAXDRT.PrinterName equal to "" is not an option.

  • I can not print a report from my quicken program because the printer name has the word on in it

    I recently purchased and installed a HP Officejet Mobile L411 printer. For all apps. on my computer (Window&) the printer name is as follows: HP officiate Noble L411. On my Quicken program the printer name is as follows: HP Officejet Mobile L411 on USB001. In checking Quickens help/troubleshooting guide, Ifound thirst statement, make sure the printers name doesn"t contain the word "on". My question is how do I get my printers name in Quicken changed so it doesn't contain the word "on"

    Try opening the PDF in Preview and see if it will print out of it.

  • How do I use AirPort Extreme to be able print from my MacBook Pro AND a PC. If I connect printer into AirPort, I can only print on laptop. If printer is connected to PC hard drive, I can only print on desk top. How do I configure this to make both print?

    How do I use AirPort Extreme to be able print from my MacBook Pro AND a PC. If I connect printer into AirPort, I can only print on laptop. If printer is connected to PC hard drive, I can only print on desk top. How do I configure this to make both print?

    If you have not already done so, your chances will really improve if you....
    1) Connect the printer to the USB port on the AirPort Extreme
    2) Download and install Bonjour Print Services for Windows on the PC

  • I recently replaced my dead airport router with a netgear91-5g router and synced it successfully to my Lexmark Pro 915 printer and my computer and yet when I try to print wirelessly I get the message: "printer not connected; printer offline".

    I recently replaced my dead airport router with a Netgear91-5g router and synced it successfully to my Lexmark Pro 915 printer and my computer; yet when I try to print wirelessly I get the message: "printer not connected; printer offline". Lexmark support verified that my printer was connected to the new router and the problem was with the computer's printer configuration and they could reconfigure it online if I paid for their "Premium Support" services ($119 for one year, 3 fixes). I declined, feeling sure that this is something I could do if I knew how. Could it be an incompatability issue with OS 10.8.3?

    You saved me $$$ that I can ill afford on my fixed income. I was very unhappy with the "support" from Lexmark... what a rip off!  Thank you dwb!

Maybe you are looking for

  • My 10.5.8 won't update adobe flash.

    I have a macbook 105.8 and have no idea what is wrong, all the sudden my adobe is out of date and I can't view any videos on any of my browsers. I attempted to download the updated versions of adobeflash many times, but it won't download/ work. I don

  • Web service task: Error when returning an empty array

    Hi, I've encountered an annoying error when using a Web Service Task from an SSIS package in SQL Server Data Tools. [Web Service Task] Error: An error occurred with the following error message: "Microsoft.SqlServer.Dts.Tasks.WebServiceTask.Webservice

  • Reg Sync key and selected measurement poit

    Hi all From the measure_point_list page when we click a particular measurement point it navigates to detail page. Actually the measure point is set in the MeasureCustomController.java with the help of "key". To my knowledge the key is the sync key. I

  • Storage Bin

    Hi Guru's Can we find storage bin while doing delivery, If we have Warehouse Configured in our system Thanks and Regards Srinivas Kapuganti

  • Customer Stock / Consignment Stock

    Hello, My customer wishes to handle stock for its customer. We don't want to generate any financial posting at all since the cost of good sold has already been triggered at the HQ level. We just want to use SBO as a stock management tool (stock in /