Printing a TextArea. PLEASE HELP ME! :)

I'm trying to use this code for printing the content of a TextArea:
void Stampare(){   
PrinterJob printJob = PrinterJob.getPrinterJob();
Book book = new Book();
PageFormat documentPageFormat = new PageFormat();
documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
book.append(new Document(), documentPageFormat);
printJob.setPageable(book);
if (printJob.printDialog()) {
try {
printJob.print();
catch (Exception PrintException){
PrintException.printStackTrace();
public class Document implements Printable {
private final static int POINTS_PER_INCH = 72;
public int print (Graphics g, PageFormat pageFormat, int page) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
g2d.setPaint(Color.black);
g2d.setStroke(new BasicStroke (4));
Rectangle2D.Double border = new Rectangle2D.Double (0, 0, pageFormat.getImageableWidth (), pageFormat.getImageableHeight ());
//g2d.draw(border);
String text = new String(areaStampa.getText());
Point2D.Double pen = new Point2D.Double(0.25 * POINTS_PER_INCH, 0.25 * POINTS_PER_INCH);
double width = 7.5 * POINTS_PER_INCH;
AttributedString paragraphText = new AttributedString(text);
paragraphText.addAttribute(TextAttribute.FONT, new Font("serif", Font.PLAIN, 12));
LineBreakMeasurer lineBreaker = new LineBreakMeasurer(paragraphText.getIterator(), new FontRenderContext(null, true, true));
TextLayout layout;
while ((layout = lineBreaker.nextLayout((float) width)) != null){
pen.y += layout.getAscent();
layout.draw(g2d, (float) pen.x, (float) pen.y);
pen.y += layout.getDescent() + layout.getLeading();
return (PAGE_EXISTS);
Obviuosly, it doesn't work as I would like it to do!
First of all, It doesn't print the lines as they are in the TextArea. I mean, the carriage returns are not the one that are in the TextArea.
Secondly, If there's a lot of text, It does exactly nothing! My purpose is to print pages as if they were a Word document, while here it seems that I cannot print more than a page.
Please, please, please, help me!!!! I'm becoming crazy with this problem!
Thanks a lot,
Giorgio

I really need somebody who could give me the correct version of this application. Have you ever developed an application that uses a TextArea (or a JTextArea, if it is possible to use that) exactly as it was a Word document? I mean, something that would let you print what is inside the TextArea as if it was inside a Word document, with more than one page, all the lines printed correctly and so on. If you have that, please, please, please!!! send me a copy. My e-mail address is [email protected]
I would really, really appreciate that!
Thanks,
Giorgio

Similar Messages

  • I have Xerox 3140 printer. Mountain Lion version can not use my printer. could you please help me. I know little English. I would like to thank those who help.

    I have Xerox 3140 printer. Mountain Lion version can not use my printer. could you please help me. I know little English. I would like to thank those who help.

    I have a small office. I have three devices mac mini osx 10.08. your suggestions helped me. I would like to thank. I liked your help. partially solved the problem .. I installed the drivers from the other computers on the network. When printing a document, "no pages found" error occurs. and can not print the document. please help me. I do not want to get a new printer. thank you for friendship ...

  • Hi,I changed my fios router and since then my c4580 printer is offline.Please help.

    Hi,I changed my fios router and since then my c4580 printer is offline.Please help.
    Router brand Actiontec and model # 20.10.7.5

    Hi and welcome to the forums!
    Here is the Verizon BIS (Blackberry Internet Service) website and procedures.
    Thanks,
    Bifocals
    https://bis.na.blackberry.com/html?brand=vzw  
    http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/8067/645045/788117/1166305/1...
    Message Edited by Bifocals on 01-11-2009 01:00 AM
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • Any Mac expert who can solve my Printing problem? PLEASE HELP!!!!

    So I am asking this again... I have a Samsung 4200 SCX Series printer. It was able to print everything properly till the 14th of April when I installed the latest Security update and the thing stopped working after that (When I give a print command, it just Pauses.... Then when I resume it again, it doesn't respond, just stays there) ... I also noticed that the name of my Mac changed to XXX (3) from XXX (2) after that update, so I am thinking it's the culprit here.. I dunno if it's related, but I just thought I put it forward.
    I also went to Printer and Fax settings in my System Preferences and reseted my Printer and changed the LOCATION name to the new name but no solution... I tried even installing the drivers manually, but the thing just PAUSES!!!!
    And before doubting my printer, I also have Windows installed via bootcamp and the printer works fine with it, it's only the Mac creating an issue.
    I got some response of people asking for the log file about it, so I am posting the last 10-20 line...
    ------->
    E [01/May/2010:10:18:36 +0530] CUPS-Add-Modify-Printer: Unauthorized
    I [01/May/2010:10:18:36 +0530] Setting SamsungSCX_4200Series device-uri to "usb://Samsung/SCX-4200%20Series?serial=8T67BAIP221002W." (was "file:/dev/null".)
    I [01/May/2010:10:18:36 +0530] Setting SamsungSCX_4200Series printer-is-accepting-jobs to 1 (was 0.)
    I [01/May/2010:10:18:36 +0530] Setting SamsungSCX_4200Series printer-state to 3 (was 5.)
    I [01/May/2010:10:18:36 +0530] Saving printers.conf...
    I [01/May/2010:10:18:36 +0530] New printer "SamsungSCX_4200Series" added by "AUTHREF".
    I [01/May/2010:10:18:36 +0530] Setting SamsungSCX_4200Series printer-is-shared to 1 (was 1.)
    I [01/May/2010:10:18:36 +0530] Saving printers.conf...
    I [01/May/2010:10:18:36 +0530] Printer "SamsungSCX_4200Series" modified by "AUTHREF".
    I [01/May/2010:10:19:09 +0530] [Job ???] Request file type is application/pdf.
    I [01/May/2010:10:19:09 +0530] [Job 1] Adding start banner page "none".
    I [01/May/2010:10:19:09 +0530] [Job 1] Adding end banner page "none".
    I [01/May/2010:10:19:09 +0530] [Job 1] File of type application/pdf queued by "chintanvora".
    I [01/May/2010:10:19:09 +0530] [Job 1] Queued on "SamsungSCX_4200Series" by "chintanvora".
    I [01/May/2010:10:19:09 +0530] [Job 1] Started filter /usr/libexec/cups/filter/cgpdftoraster (PID 452)
    I [01/May/2010:10:19:09 +0530] [Job 1] Started filter /usr/libexec/cups/filter/rastertoqpdl (PID 453)
    I [01/May/2010:10:19:09 +0530] [Job 1] Started backend /usr/libexec/cups/backend/usb (PID 454)
    E [01/May/2010:10:19:09 +0530] PID 454 (/usr/libexec/cups/backend/usb) crashed on signal 10!
    I [01/May/2010:10:19:09 +0530] Hint: Try setting the LogLevel to "debug" to find out more.
    I [01/May/2010:10:19:10 +0530] [Job 1] Backend returned status -10 (crashed)
    I [01/May/2010:10:19:10 +0530] Saving printers.conf...
    *E [01/May/2010:10:21:41 +0530] Resume-Printer: Unauthorized*
    I [01/May/2010:10:21:41 +0530] Saving printers.conf...
    I [01/May/2010:10:21:41 +0530] Printer "SamsungSCX_4200Series" started by "chintanvora".
    Oh and it's connected via USB, not the network...
    It still baffles me cause I have searched and the only people getting this issue are the one's who use a printer via bonjour or online.. I AM USING A FREAKING USB AND IT's NOT PRINTING!!!!
    PLEASE HELP if you can... I can't replace my printer or re-install the OS just for this crap...
    MacBook Air running on Mac OS X 10.5.8

    Hey Rodney, the name changed after I installed the latest security patch... And it's not only me, it's a common problem.. Here check it out...
    http://discussions.apple.com/thread.jspa?threadID=2319594&tstart=0
    I wish I never installed that security update...
    And what exactly does this deleting System pref files does??? What does setting up network again imply... You mean just adding the password and selecting the net name of my wifi don't you?? Cause I would hate to reset all those MAC address and other stuff (I really don't have much knowledge about those so wouldn't like to tamper with those).
    Anyways, thanks.

  • Reg: Printer Drivers Installations please Help me Urgent

    Dear All,
    I need to know how to install printer plugin in Moutain lion version   The thing which i have moutain lion OSX in my iMac i have a printer its offical. But i cant able to give a print in iMac osx then i have asked to my supported printer person about it then they provided me a plugin the details below.
    File Format { Terminal Install }
    File EF551699.plugin ( format .plugin )
    Please advise me how to install that plugin and how to get connected please help me
    Even i am attaching here screenshot of the same.
    Please waiting

    That package is corrupt, you need to get another copy of the installation or from a different webpage / source
    Good Luck

  • Report Printing Issue ,. Please help

    I have report query and when testing the report I get the following error. Can someone please help with necessary steps.
    ORA-20001: The printing engine could not be reached because either the URL specified is incorrect or a proxy URL needs to be specified.
    Thanks
    George

    All,
    I think there are now a number of issues discussed in this thread, so here are a few clarifications:
    - If you use BI Publisher as the print server, then you can access BI Publisher through a URL, this URL along with the configured port was supplied during the install. It is also listed in the documentation. It's typically something like this:
    http://yourhost.domain:port/xmlpserver
    - If you use another print server (Apache FOP, Cocoon, etc), then it depends on that server whether or not there's a browser accessible configuration utility, e.g when using Apache FOP along with Oracle OC4J, then the URL would be something like this:
    http://yourhost.domain:port/em
    This takes you to the "Enterprise Manager" for OC4J from where you can deploy the war file and also review the log files to diagnose potential issues.
    - Regarding the RTF vs XSL-FO question, for new users I would recommend using report regions along with the burned in generic, configurable report layouts first, and see how far that gets you and only if you need further customization I would recommend using XSL-FO templates. And when doing so, start with the generic XSL-FO templates, because they are being pre-populated, so you won't have to start from scratch but can modify existing templates.
    Regards,
    Marc

  • How do I connect my ipad2 to a lexmark wireless printer?? Please help

    I need some help syncing my iPad2 to a lexmark wireless printer. Can someone please help out on what I can do to sync them together?

    You will need to install the LexPrint Application on your iPad2 so you can print to your Lexmark printer. Please check this article for more info: Introducing the LexPrint Mobile Print Application. You can also download the LexPrint application by visiting the Lexmark website.

  • Canon Pro-100 13x19" Prints - Images suddently printing misaligned/slanted - Please help!

    Hi, I purchased a Canon Pro-100 printer about two weeks ago and I have been printing lots of 13x19 prints on Canon brand semi-gloss paper. I have successfully printed about 60 prints, but suddenly I have an issue. The images are printing misaligned/slanted on the paper, so that there is a sliver of blank paper on the bottom right and bottom left. Here is a picture of what is happening to the prints:
    http://i923.photobucket.com/albums/ad79/milligangames/101_22941_zpsf995dcd2.jpg
    I have tried cleaning the bottom plate, cleaning the roller, aligning the print head both manually and automatically, but nothing is helping. When I print on 8.5x11 or 4x6 paper I do not seem to encounter this issue. Does this mean the paper is feeding unevenly for some reason? Please help!

    Hi pmilligan,
    It is recommended that you contact live technical support . There is NO charge for this call. Real time feedback of a live technical support call would be very beneficial in this case.
    Please dial 1-866-261-9362, Monday - Friday 10:00 a.m. - 10:00 p.m. ET (excluding holidays). A Canon technical support representative will be able to resolve this issue faster.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • Snow Leopard causing Printer & Excel crashes PLEASE HELP!

    Original install from 10.5.8 to 10.6.0 - now at 10.6.1.
    The first install the system was freezing up and I couldn't get the printer to work. Internet was intermittent and slow as was the whole system and couldn't get Quicktime to work. Then the system hung up at the log in screen and went into a loop back to the log in screen effectively making the Mac Pro inoperable.
    I wiped the computer and re-loaded Snow Leopard and used a Time Machine back-up to get everything back. Everything I opened worked fine (including the printer). I had to re-install Office:mac 2008 and then the problems started.
    1.The printer would crash on anything I tried to print on any app, and the System Preference panel for printers would crash every time I tried to open it. I tried downloading the fix for HP Photosmart 3180 C All-In-One printer and got to a certain point and a warning resulted:
    "/system/library/extensions/pulsedriver.kext was installed improperly and cannot be used. Get update from HP" ????
    2. Excel will open about 5 workbooks with no data and the beach ball spins until it crashes.
    A complete wipe and re-install of Office did not fix it.
    I also fixed the permissions on my HD and repaired the disk and this did not help.
    Is there anything I can do to fix these two areas without wiping the HD and starting from scratch?
    The printer started to crash AFTER I installed Office:mac 2008. but wiping the program off the HD did not fix the printer.
    Please Help !!!

    I finished validating the fonts and used YUSA to clean up the caches but to no avail. I will look at an uninstall for the print driver and see what that does. My problem is that I can't even get into the print preferences because it fails to open.
    Though I agree with you on Office being a very stable program. I am not able to get Excel to open up... It starts up and opens the last 5 spreadsheets that were previously opened before the problem started. The sheet shell is there for all 5 workbooks but there is no data and nothing but a beach ball bouncing around. Summer is over and I am sick of playing with the beach ball LOL
    By the way - what All in one printer would you recommend for Mac. The HP printers I have are from my days when I used a (yuk) PC.
    Also, I have two other Macs - a 15 Macbook Pro and a recently purchased 17 Macbook Pro - I have not installed Snow Leopard on either one and probably will not based on all the issues I am having with my tower. they run great right now and no problems with Office or the HP printers.

  • Really need help in printing JTextArea. Please help me

    Hi,
    i want to print the content of JTextarea which span more than 1 page.i have tried all suggestion in the forums but still have the same result.
    it only print the first page.
    Please help me.
    attached is the code for printing:
    public class PrintUtilities implements Printable {
    private Component componentToBePrinted;
    public static void printComponent(Component c) {
    new PrintUtilities(c).print();
    public PrintUtilities(Component componentToBePrinted) {
    this.componentToBePrinted = componentToBePrinted;
    public void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPrintable(this);
    if (printJob.printDialog())
    try {
    printJob.print();
    } catch(PrinterException pe) {
    System.out.println("Error printing: " + pe);
    public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    /* get component width and table height */
    Dimension dimension = componentToBePrinted.getSize();
    double compWidth      = dimension.width;
    double compHeight     = dimension.height;
    /* get page width and page height */
    double pageWidth      = pageFormat.getImageableWidth();
    double pageHeight      = pageFormat.getImageableHeight();
    double scale = pageWidth / compWidth;
    /* calculate the no. of pages to print */
    final int totalNumPages= (int) Math.ceil( ( scale * compHeight ) / pageHeight );
    if (pageIndex > totalNumPages) {
    return(NO_SUCH_PAGE);
    } else {
    Graphics2D g2d = (Graphics2D)g;
    g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    g2.translate( 0f, 0f );
    g2.translate( 0f, -pageIndex * pageHeight );
    g2.scale( scale, scale );
    disableDoubleBuffering(componentToBePrinted);
    componentToBePrinted.paint(g2d);
    enableDoubleBuffering(componentToBePrinted);
    return(PAGE_EXISTS);
    /** The speed and quality of printing suffers dramatically if
    * any of the containers have double buffering turned on.
    * So this turns if off globally.
    * @see enableDoubleBuffering
    public static void disableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(false);
    /** Re-enables double buffering globally. */
    public static void enableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(true);
    THANKS

    Use freely downloadable smart jprint class AtDocumentPrinter from http://www.activetree.com. This package alos allows you to print contents of any kind of JTextComponent such as JTextField, JTextArea, JEditorPane, and JTextPane.
    It breaks the text, images and forms into multiple pages by breaking horizontally and vertically. JTable printing is specially interesting.

  • Printing in AIR, please help

    Hi guys, is it possible to make a software where you can customize a page, and then prints whatever is in the page (like converting a canvas content to bytearray) and then show's the print preview?
    Uhm, I already know how to convert the canvas content to bytearray. Just wanted to know if print preview and print is in AIR? Please help, thanks

    Printing in AIR isn't great, but it's better with AIR 2.
    http://blogs.adobe.com/koestler/2010/05/printing_in_air_2.html
    http://dryicons.com/blog/2008/04/26/multiple-page-printing-from-a-html-adobe-air-applicati on/
    http://vfoo.wordpress.com/2009/03/24/adobe-air-print-css-and-html-printing-hack/
    http://anirudhs.chaosnet.org/blog/2008.02.15.html

  • Printer Problem. Please help!

    I can not connect my home printer to my computer. It is a Lexmark Z710. It worked with my computer before. I had to reformat my hard drive because the computer got stuck in safe mode, and now the printer will not work. I install the software, and it says I have to add the printer to my printer list. I go to do that, and it says the driver is not installed ever though I installed the software for the printer. I have the printer connected through a USB hub. I then tried a direct connection to my computer, and got the same thing. The computer does work with my parents computer. Can anyone help me please? Thanks.
    Brian Nowicki
    iBook G4   Mac OS X (10.3.9)  

    Since your issue is a printing question and probably not really specific to your iBooks, you may want to post in the Mac OS X 10.4 (Tiger) > Printing & Faxing forum.
    -Doug

  • Photos printing overly Red, please help!!!!!

    Hi,
    I'm having a huge problem I have no idea how to fix. When I have a photo I print it looks good on the screen but the skin tones print very red when using either my Epson Picturemate or my Canon MP600. I got an idea and hit print preview today and guess what,....the print preview is so much more red than the original picture. I've posted a picture here:
    http://farm3.static.flickr.com/2279/20705091420fb8bf0c09o.png
    If you look a the faces you can see what I am talking about. I have no idea how to fix this and am desperate for help. I read about colorsync and when I went into it and hit verify I got an error that the EW-SRGb was damaged and unfixable. I'm not sure if this is part of my problem or not.
    I really need some guidance please!!!

    aubiem:
    Not sure what the EW-sRGB is. What does EW stand for? There are a number of color RGB profiles but I've not seen that one. When did this start? What camera is it from and does it affect all of your photos? Is the photo you posted a scanned photo? If so what color profile does it have? If it's Adobe RGB I suggest you rescan to the sRGB profile.
    Do you Twango?
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • Print to windows remote printer from solaris Please help

    Hi,
    I basically have 2 machines that are networked ( a solaris 9 sparc machine & a windows machine) The epson C42UX is on the Windows XP machine. I have samba set up on the Unix machine and can succesfully access solaris folders from the my network places folder in windows. My problem is that I want to print documents from my unix machine through the windows printer?
    How would I go about doing this, I have searched the documentation for months and all I have come up with is lots of different ways of doing this none of which seem to work? Most of the methods refer to ancient equipment :-)
    Also my Epson C42UX is connected to a USB port on windows USB0001 I think. Even if anyone could give me any links to a complete tutorial! I even have 2 samba books which mention about printer setup then conviently assume you no the most difficult parts.
    Any Help would be greatly appreciated
    iVE been at this for months ........I am starting to see why windows does so well
    Regards
    David

    Are you using Bonjour on the Mac and the PC?
    That should fix it.
    http://www.twistermc.com/blog/2005/06/21/bonjour-for-wireless-mac-pc-printing

  • Airport and Printer Not working: Please Help!

    I'm considering of trowing out my printer or the airport extreme, or my mac pro. The thing is, I don't no which one, So one more try; hope someone can help me!
    My printer (Epson SP 2400) is working fine via USB directly and from my old G4 (also via Airport).
    I can print from my Mac Pro, via Airport and then via the G4, but not directly from Macpro-airport.
    I've got the latest update for every software, read all the articles on this forum (did the http://ftp.easysw.com/pub/cups/contrib/FixAirportPrinter.dmg solvers).
    I hope I missed one trick and that someone can get me out of this frustration!
    THANKS!

    do you have printer driver v6.12, if not here's the link
    http://www.epson.com/cgi-bin/Store/support/SupportLeopardDetails.jsp?BV_UseBVCoo kie=yes&oid=54861#stage1
    did you contact epson? try them too..

  • Colors are not printing accurately. Please help!

    Colors are not printing accurately.  I have cleaned print heads.  Cartridges are full
    Officejet 8500

    Hi,
    Please go thru this HP document for print quality issues....
    http://h10025.www1.hp.com/ewfrf/wc/document?docname=c02208875&tmp_task=solveCategory&cc=us&dlc=en&la...
    Although I am an HP employee, I am speaking for myself and not for HP.
    *Say thanks by clicking the "Kudos! Star" which is on the left*
    Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue.

Maybe you are looking for

  • Share iCloud KeyChain & Bookmarks?

    Hey gang... I have a question as it relates to iCloud and more specifically, icloud Keychain. Up until now, the way my wife and I have things setup is we have one family icloud account which we use for all our iTunes and Apple Store purchases and the

  • How do I make a random order of songs in iTunes?

    it's been a long time since I have made a playlist in iTunes and I know see that creating a playlist with a random order seems no longer possible. No, I DO NOT want to shuffle on my iPod because I have other playlists that I want o segregate from the

  • XQuery problem

    Hi All, I have am XML document for Machines as follows <xmldb> <machines name = "machine1"> <part>nut<\part> <part>nut<\part> <part>bolt<\part> <machines name = "machine2"> <part>bolt<\part> <part>hinge<\part> <machines name = "machine3"> <part>nut<\

  • ICM - Remove E-mail Manager & ECC Variables

    How do I uninstall / remove the e-mail manager and associated ECC Variables?  My initial thought was this must be an option in icmsetup but after a little poking around I can't find any options that jump out at me.  The ECC Variables for e-mail manag

  • White background on output?

    Hi, guys! Sorry for the stupid question, but how do you change the output background from black to white? Thank you!