Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-18-2004, 08:29 AM   #1
Registered: Aug 2003
Location: Aberdeen, UK.
Distribution: Debian, Ubuntu
Posts: 208
Blog Entries: 2

Rep: Reputation: 30
Java printing - problem with large strings

Up until recently I have had zero exposure to Java printing but now I I have to print out a String that could be more than a page of 12pt text with formatting. Just simple new lines, and a page number (x of y) at the bottom.

Can anyone help as my trials with drawstring() don't do new lines and I think it won't take a new page.

How do I dolve this problem?
If it helps the text is taken from a JTextArea and just has to be sans-serif 12pt.

Any help greatly appreciated, even a SIMPLE tutorial.
(I have goolged for it but found nothing that I think helps.)
Old 03-18-2004, 06:48 PM   #2
Registered: Aug 2003
Location: Aberdeen, UK.
Distribution: Debian, Ubuntu
Posts: 208
Blog Entries: 2

Original Poster
Rep: Reputation: 30
This is the code im using to try and print:

import javax.print.*;
import javax.print.attribute.*;

public class PrintApp 
    public static void main(String args[]) throws Exception 
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
        PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
        PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, null, pras);
        if (service != null) 
            DocPrintJob job = service.createPrintJob();
            DocAttributeSet das = new HashDocAttributeSet();
            String filename = "g:/programs/java/myprinting/data.txt";
            FileInputStream fis = new FileInputStream(filename);
            Doc doc = new SimpleDoc(fis, flavor, das);
                job.print(doc, pras);
            catch(Exception e)
                System.out.println("error printing");
but in suse and winxp the printer is found (named in printDialog) and is accepting jobs but once the job.print() goes the System.out.println() prints and so ends the app.

BUT no paper...its driving me nuts!
Old 08-03-2004, 02:23 PM   #3
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 18
i am abt 15 min old with java printing ... googled a bit and came here ... i saw another code available online at

the difference is the code in the above listing is for PNG ... i changed tht to AUTODETECT and it did print something (on paper).... havent checked out multiline multipage yet ... hope it helps

edited: was able to print multipage document ... but the line does not wrap ... line longer than the length of the page is not printed

Last edited by linux_ub; 08-03-2004 at 02:27 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java printing problem arubin Programming 0 11-13-2005 03:27 AM
Printing to large scale printer w/local IP jake292 Linux - Software 0 07-29-2005 08:19 PM
Tiled printing of large images in Linux? flieslikeabeagl Linux - Software 1 11-03-2004 02:32 PM
Java Strings jbstew32 Programming 3 02-15-2004 12:08 PM
align columns of strings and explain '\t' (java) dave bean Programming 3 01-10-2004 10:55 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:05 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration