LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Java printing - problem with large strings (https://www.linuxquestions.org/questions/programming-9/java-printing-problem-with-large-strings-159376/)

Andy@DP 03-18-2004 08:29 AM

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

Andy@DP 03-18-2004 06:48 PM

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!

linux_ub 08-03-2004 02:23 PM

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


All times are GMT -5. The time now is 06:40 PM.