I can't send a text to a printer

Hi! That's my code:
PrintService printer = PrintServiceLookup.lookupDefaultPrintService();
   InputStream is = new ByteArrayInputStream(getParameter().getBytes("UTF8"));
Doc doc = new SimpleDoc(is, DocFlavor.INPUT_STREAM.PNG, null);
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
DocPrintJob job = printer.createPrintJob();
job.print(doc, attrs);
getParamer() - is String
After that I look at the Printer's document and see my document 'Java Printing'. Its Status is 'In turn'. And that's all. Nothing's to be printed. The printer is alive. All documents are printed successfuly besides mine.
Studio Edition Version 11.1.2.4.0

Hi ,
    Can you check the below code.
Selecting available printers
I start with a way to show all printers available to the session. For that I simply use the PrinterServiceLookup.
1
PrintService[] printers = PrintServiceLookup.lookupPrintServices(null, null); 
The result I can now use to create an Array of SelectItems in order to make the list available in the application.
1
2
3
4
5
6
7
8
9
10
11
12
public SelectItem[] getAllPrinters() { 
   if (allPrinters == null) {
       PrintService[] printers =  PrintServiceLookup.lookupPrintServices(null, null);
       allPrinters = new SelectItem[printers.length];
       for (int i = 0; i < printers.length; i++) {
                 SelectItem printer =
                 new SelectItem(printers[i].getName(), printers[i].getName());
                 allPrinters[i] = printer;
return allPrinters;
On the pagefragment I use a selectOneChoice component getting the values from the list created above. The code for the pagefragment is like this:
1
2
3
4
5
6
<af:selectOneChoice label="Available Printers" partialTriggers="cb1" 
                                 value="#{pageFlowScope.applicationPrinterBean.selectedPrinter}"
                                 id="soc1"
                                autoSubmit="true">
                                <f:selectItems value="#{pageFlowScope.applicationPrinterBean.allPrinters}" id="si1"/>
</af:selectOneChoice>
When I run the application I see a list of all printers defined om my local machine and I can select any printer I like …
What is the default printer ?
Usually every there is a default printer defined. That is the one I want to use by default in this application. For that to work I need to get hold of the default printer defined. This can be found by invoking lookupDefaultPrintService().
1
2
3
4
5
public String getDefaultPrinter() { 
   PrintService defaultPrinter =
   PrintServiceLookup.lookupDefaultPrintService();
   return defaultPrinter.getName();
If no printer is selected yet in the ADF Application, I use the default printer. I need to make an adjustment to the getter of the selected printer to return the default printer.
1
2
3
4
5
6
7
public String getSelectedPrinter() { 
  if (selectedPrinter == null) {
     return getDefaultPrinter();
   } else {
      return selectedPrinter;
Final requirement for the print startup form is to be able to reset the selected printer to the default if another printer was selected previously. For that I use a CommandButton that invokes an actionListener where I simply set the currently selected printer to be the default printer.
1
2
3
4
public void resetToDefault(ActionEvent actionEvent) { 
    // Add event code here...
    setSelectedPrinter(getDefaultPrinter());
By using this button, the default printer will be selected again.
Now what about the actual printing ?
Printing can be done by using the DocPrintJob, FileInputStream and Doc objects. First is to create a FileInputStream based on the file that I want to print. Next step is to create a Doc object based on the FileInputStream. Finally create a PrintJob based on the Doc object. I also show the user a message when something goes wrong. All this functionality is implemented in an actionListener behind a command button.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public void invokePrintJob(ActionEvent actionEvent) { 
   // Add event code here...
    PrintService[] printers =
    PrintServiceLookup.lookupPrintServices(null, null);
    Boolean printerFound = false;
    for (int i = 0; i < printers.length && !printerFound; i++) {
       if (printers[i].getName().equalsIgnoreCase(getSelectedPrinter())) {
          printerFound=true;
          PrintService printer = printers[i];
          FileInputStream input;
          try {
             input = new FileInputStream(theFile);
             Doc doc = new SimpleDoc(input, DocFlavor.INPUT_STREAM.PNG, null);
             PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
             DocPrintJob job = printer.createPrintJob();
             job.print(doc, attrs);
         } catch (PrintException e) {
                    System.out.println(e.getMessage());
                    addFacesErrorMessage(e.getMessage());
         } catch (FileNotFoundException e) {
                    System.out.println(e.getMessage());
                    addFacesErrorMessage(e.getMessage());
The code for the page fragment is simple.
1
2
3
4
5
6
7
<af:toolbar> 
   <af:commandToolbarButton text="Reset to Default"
                                               actionListener="#{pageFlowScope.applicationPrinterBean.resetToDefault}"
                                               partialSubmit="true" id="cb1"/>
   <af:commandToolbarButton text="Print" id="ctb1"
                                                actionListener="#{pageFlowScope.applicationPrinterBean.invokePrintJob}"/>
</af:toolbar>
And the page now has a print button.
When the print button is pushed, the document is sent directly to the printer.
When the print button is pushed, the document is sent directly to the printer.
It is also possible to set job properties such as number of copies, the orientation of the print, and many other properties.
1
2
attrs.add(new Copies(2)); 
attrs.add(OrientationRequested.LANDSCAPE);
I can check the result of this in the print properties of the printjob.
Now one last thing to do is to give the printjob a decent name. As you can see, by default, all jobs have the same name, and that has no relation whatsoever with the document name, neither can it be related to a user or client.
I want to use a jobname that is more descriptive. I can do that by adding the JobName to the PrintRequestAttributeSet.
1
2
3
4
5
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet(); 
attrs.add(new Copies(2));
attrs.add(OrientationRequested.LANDSCAPE);
JobName name = new JobName(file ,null);
attrs.add(name);
The result is obvious.
Conclusion
Printing can be done directly from within the ADF Application. You can use almost any of the properties that can be used in the printer dialog of your browser or operating system. This example can be extended and I will probably create an ADF taskflow library to deploy this functionality.
Resources
Documentation can be found here : Javax.print javadoc
This post was originally published on lucbors.blogspot.com
Zipfile with the project can be found here.
Thanks,
Pramila

Similar Messages

  • Can I send a text to a "group" contact without selecting each individual member?

    Can I send a text to a "group" contact without selecting each individual member?  I have a group formed in my contacts, but I still have to select each member in that group to send a text or email from my phone.

    There are apps that allow you to address sms messages to groups (such as Speed Names: https://itunes.apple.com/us/app/speed-names-contacts-groups/id285124918?mt=8), but not iMessages.  Perhaps this will change with a future iOS update.
    The only point of having them at the moment is to allow you to limit the view to only contacts belonging to a group, so that you can more easily add the individual members of the group.  But at the present time, you still have to add them individually.

  • How can I send a text with a picture attachment on my new iPhone5c?

    How can I send a text with a picture attachment on my new iPhone5c? It won't send or recieve!!.

    Does your carrier support it?
    Follow the steps in this guide.
    http://www.imore.com/how-send-photo-using-imessage

  • HT4061 I recently switched from my iphone to a samsung Galaxy S4, trading in my iphone. I now can not send/receive text messages from any iphones to my galaxy S4. Since I traded the iphone in, I can't access it to make any changes. Any ideas?

    I recently switched from my iphone to a samsung Galaxy S4, trading in my iphone. I now can not send/receive text messages from any iphones to my galaxy S4. Since I traded the iphone in, I can't access it to make any changes. Any ideas?

    http://support.apple.com/kb/TS5185

  • I can  not send a text to one of my contacts!!! HELP!!!

    I can not send any text messages to one of my contacts, I can receive them from her and also I can receive and make phone calls to this person, but I can not send a text??? any suggestions???

    i can send a text them just not iMessage

  • I have iphone 5 and can not send a text to one person who has iphone 4s and on same family plan

    I have an iphone 5... and also a family plan.  I can not send a text to my daughter on the same plan. She has an iphone 4s.  I have tried mulitiple things to get this to work.... It started about 10 days ago... I have delete text stream for her and any group messages. Also her contact in contacts.  Also readded her contact with area code....then with 1 ...then just with 1... All rebooting in between each new thing i did... Checked to see if sms is turned on ..yes and turned it off... turned of imessages and back on... rebooting in between.  Also signed out of and back into apple id. Also with reboots... did a soft reset.  Upgraded to ios 8 about 2 days ago... And a few times in last 10 days i could send for a few hours then it was gone again...... VERY frustrated at this point....Also i can text many others including iphones and so can she....
    Lee-Ann

        Thank you for reaching out to us, labrylao4. Regarding the issues with messaging, is this affecting only SMS, iMessages, or both? When you or her try to send each other messages, do you receive any error messages while it is sending? If it is for iMessages, have you tried to send while connected to WiFi?
    NicandroN_VZW
    Follow us on twitter @VZWSupport

  • Can't send photo text from iphone 4s to non iPhone

    I have a 4s iPhone but can't send photo text message to husband who doesn't have iPhone.  Can send to people with iphone though.  Need some help...

    I've been having problems with texting pictures since I updated to iOS 7 too but have yet to find a solution that actually works.  I have also tried to reset my phone numerours times, have MMS turned on, etc.  It doesn't matter if I'm trying to send the picture to another Apple user or not. 
    It usually takes about 3 or 4 tries to get the picture to go through, but in many cases I have to turn my phone off then back on for it to work.
    PS - I am in Canada & my service provider is Bell. However I don't believe it is a Bell issue as I didn't have any problems until AFTER the update.  Had hoped the latest update this week would've fixed it but if anything it seems worse.

  • Can I send a text from my ipad to a droid?

    Can I send a text from my ipad to a droid?

    IF YOU ONLY HAVE WIFI: you can download a texting app (which gives you your own #) and then YES, you can text anyone's cell phone or device as long as they have a phone # as well.
    IF YOU HAVE 3G (INTERNET EVERYWHERE) OR A TEXTING PLAN: YES you can, if you have 3G, then follow the instructions for wifi
    if you have 3g, then you should be able to enter the messaging application on your iPad and send a message to anyone with a valid phone #!
    I hope I was able to help you converse with whoever you are trying to converse with...
    Maniac

  • I have a iPad 2 and I can't send a text messege please help?

    I have a iPad 2 and I can't send a text messege please help?

    See Here  >  Troubleshooting Messages
    http://support.apple.com/kb/TS2755

  • HT3529 How can I send a text thread from my iphone to my email?

    How can i send a text message thread from iphone to gmail?

    You can send a text message from your iPhone to Gmail by addressing the text to the email address.
    You can also Copy/Paste the a message from text to an email.
    See the iPhone User Guide for more info about copying and pasting.

  • Can i send a text from my ipad

    Can i send a text from my i pad to any phone? How do you do it!
    Thankyou!

    There may be some apps that will allow sending a text to other non Apple phones. Search the App Store.
    The Messages app that comes on an iPad can send iMessages to other iOS devices only.

  • Why can i send imessage texts but not sms texts ?

    why can i send imessage texts but not sms texts ?
    When i try to send an sms text ..i get a 'not delivered' message...no error code...imessage works fine...

        Very strange, [email protected] Let's get this figured out. Make sure that SMS messages are turned on. Go to Settings>Messages>Send as SMS. Please let me know if this works.
    ChaunceyM_VZW
    Follow us on twitter @VZWSupport

  • If I have cellular capabilities turned on, can I send a text message to any type of cell phone thu iMessage?

    If I have cellular capabilities turned on, can I send a text message to any type of cell phone using iMessage? Or do I need a app such as Text Plus to do this.  I have a New iPad.  Thanks for any info.

    iMessagel is basically an online chat kinda service. It does not use a carrier service to send text message. It only does instant messages. At least on the iPad side. iPhones are given to choise of sending via iMessage and text depending on the receiver.

  • Can not send SMS text message.

    Hi, I'm a BlackBerry user for 4 years now and this is the first time that I have a problem with SMS text messaging. My precious BB is a Q10.
    The problem is that I can receive SMS messages but I can not answer and I can not send messages. When I tap the 'send' icon or press Enter nothing happens. My message dissapears and i can not see in the upper window, below the message that I've previously receive and I wanted to aswer for.
    Also, I can compose SMS message, but when I press Enter or tap send, nothing happens. No message in the hub, or in the text messages folder.
    I've rebooted the device, reloaded the OS, but didn't help.

    Hi and Welcome to the Community!
    With a strong carrier network signal (e.g., not merely WiFi), I suggest the following steps, in order, even if they seem redundant to what you have already tried (step 1 should result in a message coming to your BB...please wait for that before proceeding to the next step):
    1) Register HRT
    KB00510 How to register a BlackBerry smartphone with the wireless network
    Please wait for one "registration" message to arrive
    2) Reboot
    Pre-BB10 Devices ONLY. With power ON, remove the back cover and pull out the battery. Wait about a minute then replace the battery and cover. Power up and wait patiently through the long reboot -- ~5 minutes.
    BB10 Devices. Hold the top button down until the counter reaches zero. Wait for the device to be fully shut down (e.g., nothing at all displayed on the screen, no LED lights, etc.). Hold the top button until the red LED is lit. Wait through the full boot-up process. IF this fails, you can attempt the battery-pull method above, but it is normally NOT recommended unless nothing else works.
    See if things have returned to good operation. Like all computing devices, BB's suffer from memory leaks and such...with a hard reboot being the best cure.
    Hopefully that will get things going again for you! If not, then you should contact your mobile service provider for formal support.
    Good luck!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Can't send long texts to one number

    Hi.
    I have a Nokia 6500c locked to Orange with up to date software. I'm on the Orange network with a new number which I signed up for just a month ago.
    My girlfriend has a Motorola K1 Krzr on O2.
    I've been having issues with sending her texts since day one, in that texts one page long always deliver but anything over one page long never arrives. I get a delivery report, but she doesn't get the text.
    I don't have this problem with anyone else, including anyone on O2. It's just this one person. Similarly she doesn't have a problem recieving texts from anyone else. She is able to send me texts of any length. I never had this problem when I was with Vodaphone.
    We've both contacted our networks and as you'd expect both are blaming the other.
    O2 has cleared out their system on several occasions, I've even had them on the phone whilst I send a text to my girlfriends phone and they have no record of it arriving.
    I've done the same with Orange who claim that my text leaves their network and they get a response from the O2 network saying it's been delivered.
    She's tried putting her sim in a different phone, the problem persisted.
    I put my sim in a different phone not locked to Orange, that fixed the problem.
    I went abroad a couple of weeks ago, my Nokia 6500c connected to several foriegn networks, that fixed the problem.
    I come back to the UK with my handset on Orange, problem persisted.
    I'm getting sick of calling Orange who drip feed me ideas for fixing the issue spaced out over several days, and their last response has me thinking they have no idea.
    They claim that the software the Orange network uses means that our two handsets are incompatible when it comes to sending a text more than one page long.
    I've trawled the net for such compatibility issues and not surprisingly can't find anything. Nokia tech support have never heard of such an issue, the guy I talked to even chuckled at the idea. Several of the Orange call center staff haven't heard of the issue.
    So the issue was either made up by the lying technical support of Orange, or I'm the first person in the country to discover the bizzare compatibility problems between the two phones using the Orange network software.
    I've asked that my Nokia be unlocked free of charge to see if that resolves the issue, also try a new sim, new handset, and even a new number. I can't think of anything else.
    Does anyone else have any ideas what is going on because I'm at a loss.
    Thanks,
    Adam

    A locked phone(provider) firmware is somwhat modified with that of an open one, the reason why one can't upgrade one's locked phone even if an upgrade released by Nokia is already available.
    From what I understand, it really not the sim card that is at fault nor the phone in particular for it does not have this issue when used in other phone model, the most likely cause is bug in modification of the firmware in phone model(6500c).
    You have the right to have it unlocked & have also the firmware updated(Nokia standard) if it is available.
    Message Edited by android on 05-Apr-2008 01:22 PM
    Knowledge not shared is knowledge wasted!
    If you find it helpfull, it's not hard to click the STAR..

Maybe you are looking for