LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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


Hello,
Up until recently I have had zero exposure to Java printing but now I must...so 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
Andy@DP
Member
 
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:

Code:
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;

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);
            try
            {
                job.print(doc, pras);
                System.out.println("printing...");
            }
            catch(Exception e)
            {
                System.out.println("error printing");
            }
        }
        System.exit(0);
    }
}
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
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 17
i am abt 15 min old with java printing ... googled a bit and came here ... i saw another code available online at http://www-106.ibm.com/developerwork...ary/j-mer0322/

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.
 
  


Reply


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


All times are GMT -5. The time now is 07:44 PM.

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