Text Printing in Java

How can i print characters with different styles in a dotmatrix printer using print api

Well, getting the text from your JTextField should be rather easy: myJTextField.getText().
To print it, you'll have to create an Graphics object and draw the text using the drawString method on a Graphics objects: myGraphics.drawString(myText, x, y). You will need to set the right font on the graphics before that (using the setFont() method).
You can then use this Graphics object to print.
See the java tutorial on printing for more info about printing: http://java.sun.com/docs/books/tutorial/2d/printing/overview.html

Similar Messages

  • How to print a text file using Java

    How can I print a text file using Java without converting the output to an image format. Is there anyway I can send the characters in the text file as it is for a print job? I did get a listing doing this ... but that converted the text to an image format before printing....
    THanks,.

    Hi I had to write a print api from scratch, and I did not convert the output to image. Go and read up on the following code. I know there is a Tutorial on Sun about the differant sections of the snippet.
    private void printReport()
         Frame tempFrame = new Frame(getName());
         PrintJob printerJob = Toolkit.getDefaultToolkit().getPrintJob(tempFrame, "Liesltext", null);
         Graphics g = printerJob.getGraphics();
                    //I wrote the method below for calculations
         printBasics(g);
         g.dispose();
         printerJob.end();
    }This alone wont print it you have to do all the calculations in the printBasics method. And as I said I wrote this from scratch and all I did was research first the tutorial and the white papers
    Ciao

  • Printing in java - text positioning

    Hi there, I need some pointers in the right direction please.
    I need to print a page out to fill in a pre-printed sheet. The data to go onto the sheet is purely numbers, but the pre-printed sheet is not in a table format (the boxes where the data goes are in seemingly random positions.)
    I am currently completing the task by laying out a panel in the way I want it and using the printComponent method, but this obviously isnt the best way to do it as all I need to print out is text.
    How is the best way to go about this? Is it possible to define the position of each line of text?
    Cheers. :)

    Well, getting the text from your JTextField should be rather easy: myJTextField.getText().
    To print it, you'll have to create an Graphics object and draw the text using the drawString method on a Graphics objects: myGraphics.drawString(myText, x, y). You will need to set the right font on the graphics before that (using the setFont() method).
    You can then use this Graphics object to print.
    See the java tutorial on printing for more info about printing: http://java.sun.com/docs/books/tutorial/2d/printing/overview.html

  • Using printer with java

    Hi all,
    I want to take print out of a text file from java. Do we hava any class or any way through which we can do this.
    Thanks in advance
    Regards,
    Arunkumar

    Look at the javax.print package.
    Here's a tutorial link you'll want, too:
    http://www-106.ibm.com/developerworks/java/library/j-mer0322/
    MOD

  • Send a txt file to the printer with java

    Hello,
    I want to sent a txt file to the printer in java. I' am using the USB port. I can try to setup a dos command (print c:\test.txt), but I don't know the exactly command.
    There is also another solution in java I thing but I don't know the code!
    Can somebody give me the exact command for DOS and/or the code I have to write in java?
    THANX!!!!

    in dos imo you are not able to use usb-port. if your printer would be on lpt you could use javacomm ( http://java.sun.com/products/javacomm/index.html ). there is also another thread talking about this (print text to lpt). for your usb-problem i don't have a solution. but you could use JNI (java native interface). write code in c, compile to dll and use it in java.
    tobias
    ps: the other thread ( http://forum.java.sun.com/thread.jsp?forum=31&thread=224460 )

  • Printing in java? Does anyone know how?

    Um ......cant seem to find any tuorials on printing in java.
    Does anyone know how. I have a bit of text in a JTextArea that i just wanna print directly to the printer. No hassles.

    If you're trying to print in JDK 1.2 or 1.3 there is an online tutorial here:
    http://java.sun.com/products/java-media/2D/forDevelopers/sdk12print.html
    Things have drastically changed for Java 2, JDK 1.4, and the new printing API/User guide can be found here:
    http://java.sun.com/j2se/1.4/docs/guide/jps/
    I have been having trouble with the locating printservices with the jdk 1.4, but it is still in BETA, so that could be the problem.

  • Configure client printer in java.awt.print

    I have number of records in database.
    If User clicks on PRINT button (ON A JSP PAGE)each record should be printed(ON CLIENT PRINTER) on a separate sheet.
    I can only able to access printer connected to server not to client.
    I am using javax.print and java.awt.print packages

    I am not sure this..
    Instead of if pls give while and check:
    try{
    while(rsValue.next()) {
    g.setFont(fntHeading);
    g.setColor(Color.red);
    g.drawString("Main Report",200,100);

  • How to read some records from a text file into java(not all records)

    hello,
    how to read text files into java. i need only few records from the text file not all records at a time.
    If any one knows plz reply me
    my id is [email protected]

    this snipet reads a text file line by line from line 1 to 3
    try {
                  FileReader fr = new FileReader(directory);
                  BufferedReader br = new BufferedReader(fr);
                  int counter = 0;
                  while ((dbconn = br.readLine()) != null) {
                      switch(counter){
                          case 0:
                            status = dbconn;
                          break;
                          case 1:
                            userName = dbconn;
                          break;
                          case 2:
                            apword = dbconn;
                          break;
                      counter++;
                  br.close();
        }catch(IOException e){
        }

  • XML Printing from Java

    I have an urgent request from my company's client to implement a feature of printing in our application.
    Actually the application is basically an XML Builder which generates XML code at the backend, something like Dreamweaver.
    I have no clue about printing in Java, and have not much time to research on this topic. If anybody have a program to send an XML file to print (Color printing if possible), please post here or email me at [email protected]
    Any help in this regard is highly appreciated (Dukes Dollars also available).
    Thanks
    Raheel

    I realize you're under time pressure, but this link may be of assistance: Printing in Java, Part 1: Acquaint yourself with the Java printing model

  • PL/SQL log messages are not printing from Java concurrent program

    Hi,
    I have a strange issue while submitting the Java concurrent program through PL/SQL.
    I have a PL/SQL concurrent program which will invoke the Java concurrent program inside the package by use of "FND_GLOBAL.SUBMIT_REQUEST". It worked and submitted successfully. From that Java concurrent program we are calling some other PL/SQL packages and printing some log messages over there. But problem here is the request is only printing the Java log messages in view log but not the PL/SQL log messages.  But if I submit the Java concurrent program directly from SRS form at that it is printing both Java and PL/SQL log messages.
    I am just wondering how the log messages has not printed. Please provide your inputs to solve this problem.
    Thanks
    Suriya

    I'm adding log messages in the package body , but these messages are not printing after completion of concurrent prog.
    Any suggestions.
    FND_FILE.PUT_LINE(FND_FILE.LOG,'Data Test :');Do you have COMMIT in your code?
    https://forums.oracle.com/forums/search.jspa?threadID=&q=%27FND_FILE.PUT_LINE%27+AND+commit&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • Help needed in printing in java

    hello everyone, i m in grave need of a solution of printing a java page. I have a page designed in Java swings which contains mainly labels and textareas. And i need to print this page. The problem is that I have no clue how to go ahead. Cud neone arnd pls help me on this matter asap as this is very urgent. I shall be highly obliged to all the takers on this issue. Please email me at [email protected]
    Thanks and kind regards,
    Rahul.

    http://java.sun.com/docs/books/tutorial/2d/printing/index.html

  • Text Prints as Black Instead of Assigned Swatch

    Hi, I have been having problems with text printing to a HP laser 5500dn printing as black in
    stead of the assigned swatch color.
    I am using CS3 on a Mac.
    It will print fine exported to PDF or printed on an inkjet.
    I have reset preferences.
    In the print dialogue box I have the following settings.
    I DO NOT have "Text as Black" selected.
    Color Management is: US Web Coated SWOP v2
    Color Handling is Let InDesign determine Colors
    Printer Profile is Document CMYK US Web Coated SWOP v2
    Output color is Composite CMYK (Unable to change in this configuration)
    Lastly, after printing and then closing the document,ID asks to save changes, When I cancel and review what edits were done, the last edit comes up as
    "Undo Change Ink"
    I don't know what that means.
    Suggestions?
    Thanks

    Thanks for your help.
    I haven't deleted the swatch or converted to another color.
    Not sure what you mean by aliasing the swatch.
    I did as suggested and looked in the printer setup in the print dialog and did not see anything to print text as black.
    So I ended up changing the text to several different colors and now it prints those colors fine.
    I think the color is so dark as to appear to be black when printing even though it is very apparent on the monitor that it is much different than black.
    I know that monitor colors and printer colors won't match, but this had me very baffled.
    Especially as the PDF printed much differently.
    So I guess I am going to print from the PDF to make sure the colors are as I want them to be.
    I work predominantly on a PC with CS3 that does not have Indesign; the Mac has CS3 with InDesign. The Mac routinely prints all documents much darker than the PC and what is displayed on the screen.
    Thanks, again.

  • How to get the source code of an HTML page in Text file Through java?

    How to get the source code of an HTML page in Text file Through java?
    I am coding an application.one module of that application is given below:
    The first part of the application is to connect our application to the existing HTML form.
    This module would make a connection with the HTML page. The HTML page contains the coding for the Form with various elements. The form may be a simple form with one or two fields or a complex one like the form for registering for a new Bank Account or new email account.
    The module will first connect through the HTML page and will fetch the HTML code into a Text File so that the code can be further processed.
    Could any body provide coding hint for that

    You're welcome. How about awarding them duke stars?
    edit: cheers!

  • How to replace a line ina text file using java?

    Hi ALL,
    Does anybody know how to replace a line in a text file uisng java.

    use this thing:
    http://doesthatevencompile.com/current-projects/code-sniplets/ASCIIFile.htm
    open the file,
    read its contents, replace the text you need in the contents, set the contents back into the file.
    it takes care of the IO for you.

  • How to convert a HTML files into a text file using Java

    Hi guys...!
    I was wondering if there is a way to convert a HTML file into a text file using java programing language. Likewise I would also like to know if there is a way to convert any type of file (excel, power point, and word) into text using java.
    By the way, I really appreciated the help that you guys gave me on my previous topic on how to extract tests from a pdf file.
    Thank you....

    HTML files are already text files. What do you mean you want to convert them?
    I think if you search the web, you can find things for converting those MS Office files to text (or extracting text from them, as I assume you mean).

Maybe you are looking for

  • Snow Leopard - No Output devices found - (Audio)  Help?

    Folks I just installed Snow Leopard on my Mac Mini which I use as my home media centre. It upgraded fine except for the lack of audio devices it now reports. Ive been combing forum threads but to no avail. Appreciate any help or suggestions Model Nam

  • I invited someone to share a calendar on ical and it didn't go through -

    Hi. I invited my business partner to share a calendar on ical and was successful.  I then invited my husband, who has an older mac and older OS but my invitation didn't even get through to him.  Does anyone have advice?  Thanks, Julie

  • Can you still renew a 2 year contract for AT&T at BestBuy?

    I was told that i wouldnt be able to renew my contract with best buy anymore. i planned on using my best buy credit card when i went in.

  • Mac Book Pro Kernel Panic

    Hi all I am new to the discussion board as a poster (though I have used the board much during my time as a MBP owner). I have recently (past 2 weeks) started having fairly regular kernel panics. I have my MBP since August 2009 and have upgraded the r

  • Dreamweaver Discussion Board

    I'm a newbie to Flash and Dreamweaver and I am currently attemtping to build a Website for a class Project. The DW discussion board seems to offer little help here. I published a flash movie to Dreamweaver 8. Video plays fine on my PC and when I uplo