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

Similar Messages

  • How to compare two files in Java & uncommon text should print in Diff text

    Hi All,
    can any one help me to write a java program..
    How to compare two files in Java & uncommon text should print in Diff text file..
    Thanks
    Sam

    Hi All,
    i m comparing two HTML file.. thats why i am getting problem..
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class textmatch{
    public static void main(String[] argv)
    throws Exception{
    BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
    BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
    String s;
    String y;
    while ((s=fh.readLine())!=null)
    if ( s.equals(y=sh.readLine()) ){    
    System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
    sh.close();
    fh.close(); }
    thanks
    Sam

  • 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

  • Horizontal text positioning of DrawString method

    I am trying to reproduce the below XPS XAML using the GDI+:
    <FixedPage xmlns="http://schemas.microsoft.com/xps/2005/06" xmlns:x="http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key"
    xml:lang="und" Width="816" Height="1056">
    <Path Fill="#FFFFFFFF" Data="M0,0L816,0 816,1056 0,1056Z" />
    <Canvas Clip="M0,0L816,0 816,1056 0,1056Z">
    <Path Fill="#FFFFFFFF" Data="M0,0L816,0 816,1056 0,1056Z" />
    <Path Fill="#FF008000" Data="M0,0L816,0 816,1056 0,1056Z" />
    <Canvas RenderTransform="1,0,0,1,10,10">
    <Path Fill="#FFFFFF00" Data="M0,0L796,0 796,120 0,120Z" />
    <Canvas Clip="M0,0L796,0 796,120 0,120Z">
    <Glyphs OriginX="0" OriginY="87.5866666666667" FontRenderingEmSize="96" FontUri="/Resources/1057478c-ad6c-46da-af29-3e00c349c111.ODTTF" UnicodeString="Rutger
    Koperdraad" Fill="#FF000000" xml:lang="en-us" />
    </Canvas>
    </Canvas>
    </Canvas>
    </FixedPage>
    I manage to get the rectangles and the vertical text position correctly printed to the XPS document writer using the code below:
    Private Sub OnPrintPageEx(sender
    As Object, e
    As PrintPageEventArgs)
    If m_intPageNumber < m_objPaginator.PageCount
    Then
    Using objGraphics
    As System.Drawing.Graphics = e.Graphics
    ' Correction factor between WPF and printer units
    Dim f As
    Single = 100 / 96
    ' Set the graphics quality
    objGraphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.None
    objGraphics.InterpolationMode = Drawing.Drawing2D.InterpolationMode.NearestNeighbor
    ' Draw the green background
    Dim stcRect1 As
    New Drawing.RectangleF(0, 0, 816 * f, 1056 * f)
    Call objGraphics.FillRectangle(Drawing.Brushes.DarkGreen, stcRect1)
    ' Draw the yellow rectangle
    Dim stcRect2 As
    New Drawing.RectangleF(0, 0, 796 * f, 120 * f)
    Call objGraphics.TranslateTransform(10 * f, 10 * f)
    Call objGraphics.FillRectangle(Drawing.Brushes.Yellow, stcRect2)
    ' Draw the text
    Dim objFont As
    New Drawing.Font("Times New Roman", 72)
    Dim intEmHeight As
    Integer = objFont.FontFamily.GetEmHeight(objFont.Style)
    Dim intCellAscent
    As Integer = objFont.FontFamily.GetCellAscent(objFont.Style)
    Dim sngOffset As
    Single = 87.58667F - 96.0F / intEmHeight * intCellAscent
    Dim stcRect3 As
    New Drawing.RectangleF(0, sngOffset * f, 796 * f, 120 * f)
    Call stcRect3.Inflate(100 / 96, 100 / 96)
    Call objGraphics.DrawString("Rutger Koperdraad", objFont, Drawing.Brushes.Black, stcRect3)
    End Using
    m_intPageNumber += 1
    e.HasMorePages = (m_intPageNumber < m_objPaginator.PageCount)
    End If
    End Sub
    However, the horizontal text positioning is still different. The first letter starts too far to the right and the overall text is wider. How can I reproduce the XAML correctly in the GDI+?
    To give some background: I have a WPF application that can print using WPF/XPS technology. Since this print path gives quality problems on many legacy printer driver (bad image resolution due to a bug in the XPS to GDI+ conversion), I am building an
    alternative print engine based on the GDI+. So effectively, I need to convert my WPF graphics to the GDI+.
    Rutger Koperdraad.

    OK, I found the answer myself. By adding the string format as below, I get the correct result.
    ' Draw the text
    Dim objFont As
    New Drawing.Font("Times New Roman", 72)
    Dim intEmHeight As
    Integer = objFont.FontFamily.GetEmHeight(objFont.Style)
    Dim intCellAscent
    As Integer = objFont.FontFamily.GetCellAscent(objFont.Style)
    Dim sngOffset As
    Single = 87.58667F - 96.0F / intEmHeight * intCellAscent
    Dim stcRect3 As
    New Drawing.RectangleF(0, sngOffset * f, 796 * f, 120 * f)
    Dim objFormat As
    New Drawing.StringFormat(Drawing.StringFormat.GenericTypographic)
    Call objGraphics.DrawString("Rutger Koperdraad", objFont, Drawing.Brushes.Black, stcRect3, objFormat)
    Rutger Koperdraad.
    Thank you for sharing your solutions and experience here. It will be very beneficial for other community members who have similar questions.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

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

  • How do I print just the text in a power point opened in preview

    How do I print just the text in a power point opened in preview

    In the front panel, right click on the listbox object and select create>attribute node.
    In the diagram click on the attribute node and select "Item Names".
    Connect the desired array of string to the attribute node.
    BigBen

  • 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);

  • Print/Save Selected Text to PDF

    I want to use Mozilla Firefox very much for a long time. I like it because the UI is very clean, easy to use, the icon vey pretty. When I use in my Android Mobile, it is very easy and intelligent to select content of page site. Very good!
    But I had to install Chrome instead so I've always been using "Print a selected content to PDF" but I couldn't find ways to do that with Firefox. Chrome is doing very good.
    I searched all add-ons, pdf printer software but they are only saving or printing all the page (website) to PDF.
    Please help me the ways to save a selected content to PDF. Thanks very much.

    Hii hanh01001..
    I think i know one solution to the problem
    https://addons.mozilla.org/en-US/firefox/addon/print-selected-text/?src=api
    this is an add on that is used to print the selected text only..
    have a nice day :) :)
    ---Thanks tracy :)

  • I filled in a fillable pdf form and when i print it, the text in the fillable section gets cut off.

    I filled in a fillable pdf form and when i print it, the text in the fillable section gets cut off. What do I need to do to get the entire text to be printed. Any help is appreciated.
    Thanks

    What has this to do with Pages? You probably did this in Preview.
    Peter

  • How can I print off a text message conversation?

    I have to print off a text message conversation and I was wondering if there is any other way to print them off instead of using screen shots?

    An alternate utility you may want to look into is DigiDNA's Disk Aid. You install it on a computer, Mac or PC, connect you phone to it and are able to back up everything on the phone and have access to all the stuff in there. Not free but really worth every penny. Free if you work or study in higher ed.

  • How can i print out old text messages?

    how can i print out old text messages?

    As Ann said, it does depend on your phone.  One third party app that works on many phones (especially older models, but not all phones) is BitPim ( http://www.bitpim.org/ ) but it can potentially harm/brick your phone if you don't know what you are doing - use it with caution.  I have used it successfully to get texts and photos off an old flip phone that was deactivated and had no sd card.
    Newer smartphones can download apps that will give you the ability to print out texts.

  • How do I print only the text on the monitor screen?

    I would like to be able to print only that portion of a text that is on the monitor screen. How do I do that?
    I have an Epson Workforce 325 printer, and an HP desktop computer PC

    Please see the following to print only the text portion of the web page. I am assuming you wish to print just the text & not the ads or additional irrelevant items to avoid wasting ink.
    See:
    [[Printing a web page]]
    '''If this solved your issue, please select ''solved ''& chose the appropriate ''solution'' to close this ticket/question posting'''.

  • How to get text position in a pdf?

    I need to get text position such has width, height, x, y and base position in a pdf.
    Can one help me to work further.

    i solved PDEForm issue thank you. Now i need to get the text from PDEElement.
    Can you help for this?
      PDEElement pdeElement;
        ASInt32 numElems = PDEContentGetNumElems (pdeContent);
        ASFixedRect bBox;
        for (ASInt32 i = 0; i < numElems; i++) {
            pdeElement = PDEContentGetElem (pdeContent, i);
            if (PDEObjectGetType((PDEObject)pdeElement) == kPDEForm)
                PDEForm form = (PDEForm)pdeElement;
                PDEContent content = PDEFormGetContent(form);
                GetCoOrdinate(content);
            else if(PDEObjectGetType((PDEObject)pdeElement) == kPDEText)
                PDETextState objPDETextState;
                PDEText aotextObject;
                memset(&objPDETextState, 0,sizeof(PDETextState));
                aotextObject = (PDEText)pdeElement;
                PDETextGetTextState(aotextObject,kPDETextRun,0,&objPDETextState,sizeof (PDETextState));
                if(objPDETextState.renderMode == kPDETextInvisible)
                    AVAlertNote("Invisible");
                else
                    PDEElementGetBBox (pdeElement, &bBox);
                    os.str("");
                    os << ASFixedRoundToInt32 (bBox.top) <<":" << ASFixedRoundToInt32 (bBox.bottom) << ":" << ASFixedRoundToInt32 (bBox.left) << ":" << ASFixedRoundToInt32 (bBox.right);
                    AVAlertNote(os.str().c_str());
            else
                os.str("");
                os << "Type: "<< PDEObjectGetType((PDEObject)pdeElement);
               // AVAlertNote(os.str().c_str());
                // Get the bounding box of the PDEElement and fill out the
                // selection structure to highlight the image.
                PDEElementGetBBox (pdeElement, &bBox);
                os.str("");
                os << ASFixedRoundToInt32 (bBox.top) <<":" << ASFixedRoundToInt32 (bBox.bottom) << ":" << ASFixedRoundToInt32 (bBox.left) << ":" << ASFixedRoundToInt32 (bBox.right);
                //AVAlertNote(os.str().c_str());

  • Looking for app to either print or save text messages in windows

    I saw a couple of posts for this feature but it was for mac. does anyone know if printing or saving text messages is possible? thanks

    Ugly work arounds:
    1) Take screenshot (hold front and press and release top and import)
    2) use a web translator: http://insend.de/
    3) Poke through shareware: http://www.softpedia.com/downloadTag/backupiPhoneSMS
    Good work around:
    Bug Apple for the feature http://www.apple.com/feedback/iphone.html

Maybe you are looking for

  • Pros and cons of having OSX Snow leopard and OSX Lion on the same Computer

    Disclaimer : I am not an expert,my experience with Computers is trial and catastrophic errors. If one owns an early Intel Mac say 2009 and want to have OSX Lion and or Snow Leopard on a partitioned HD.My setup is typical I use my Bundled DVD and clea

  • "Error" Trying to connect to.......

    "Error" trying to connect to Infinitum9342 This message appears since i installed the update of airport for my Macbook C2D when trying to connect to the internet. (my litlte internet box) I dont know how to name that thing in english, so i will just

  • UTF-8 and Chineese Characters

    I have a JSP with the following line at the very top: <%@ page contentType="text/html; charset=utf-8"%> This is so that it will use UTF-8 encoding to display non-english characters. Doing this, allows me to display Arabic, Hebrew, and English charact

  • The effects and adjustment will not work. I just bought a MacPro and had everything moved from my old laptop.

    quick fixes won't work either and there is nothing in the levels file - no histogram. my photos are in raw. I tried deleting the IPhoto plist file and restart but no luck.

  • How to Confiure Route Node to do HTTP Post?

    Hi All, I am trying to create a messge flow that could do HTTP POST. I have a business service that can do HTTP POST. In the Messge flow of the proxy service, I created Route node. With in the route node, I have created an Assign request action to as