🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.language
3 messages
3 total messages Started by Magnus Fri, 01 Jul 2005 16:21
Simplest way to print reports in java1.4?
#543
Author: Magnus
Date: Fri, 01 Jul 2005 16:21
20 lines
1809 bytes
Hi,

I have been looking for some time on how to achieve a simple report.
At this moment I don't care about headers, footers, different fonts etc.

I use jDataStore and would just select the data that I need and print...

I was hoping that creating a jTextArea, using moonscape font, and (kind 
of the old days) just print text - line by line, and the just send this 
to the printer.

Anyone seen or know how to achieve this with minimal code. Is there any 
books that address this? I have three books and only one even talk about 
it but the example to print text is from 97 for 1.1.

The only thing I have found is how print nice pictures on one page and a 
PrintFramework (JavaWorld - 2001). This is a great start if I need a 
"complete" print system but a bit complicated for my needs now.

Magnus
Re: Simplest way to print reports in java1.4?
#544
Author: Paul Nichols (TeamB)
Date: Sat, 02 Jul 2005 15:32
10 lines
1222 bytes
Magnus wrote:

> Hi,
> 
> I have been looking for some time on how to achieve a simple report.
> At this moment I don't care about headers, footers, different fonts etc.
> 
What I use to print reports, is good ole HTML-XML. Best way to have full
control over your format. Use a browser to send the report to, or a
PrintStream.
Re: Simplest way to print reports in java1.4?
#545
Author: Magnus
Date: Sun, 03 Jul 2005 15:38
80 lines
3735 bytes
Paul Nichols (TeamB) wrote:
> Magnus wrote:
> 
> 
>>Hi,
>>
>>I have been looking for some time on how to achieve a simple report.
>>At this moment I don't care about headers, footers, different fonts etc.
>>
> 
> What I use to print reports, is good ole HTML-XML. Best way to have full
> control over your format. Use a browser to send the report to, or a
> PrintStream.
> 
Thanks Paul!

That sounds good. I have tried to use the below example to stream a file 
to a printer. My plan was to create a txt file and send it to the 
printer but HTML would be even better... However, I always get:
"Print job failed PrintEvent on sun.print.Win32PrintJob@162e295"
no matter what file I try and to what printer I select.

Do you have any sample code to send a HTML file to a printer with 
PrintStream or PrintWriter? Is it possible to get the PageDialog and 
PrintDialog as part of it? Any example of how to handle pagebreak,LETTER 
and A4 size?

As always, I'm truly greatful for any help?

--- My file stream test ---

First I list the printers on the PC that can handle attributes like 
Letter and A4 size and put them in a ComboBox .

printers = PrintFile.listPrinters(attributes);
printerCB.removeAllItems();
for (int i=0; i<printers.length; i++) {
    printerCB.addItem(printers[i].getName());
}

The "filename"=absolute path to a txt-file.

// txt files only but I guess that TEXT_HTML_HOST would work
DocFlavor fileType = DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST;

InputStream readFile = new FileInputStream(filename);
Doc doc = new SimpleDoc(readFile, fileType, null);

DocPrintJob job = printer.createPrintJob();

job.addPrintJobListener(new PrintJobAdapter() { // Monitor the print job 
with a listener

      public void printJobCompleted(PrintJobEvent e) {
            System.out.println("Print job complete");
            System.exit(0);
      }
     public void printDataTransferCompleted(PrintJobEvent e) {
            System.out.println("Document transfered to printer");
     }
     public void printJobRequiresAttention(PrintJobEvent e) {
            System.out.println("Print job requires attention");

     }
     public void printJobFailed(PrintJobEvent e) {
            JOptionPane.showMessageDialog(null,
                        "Print job failed "+e.toString(),
                        "Failure",
                  JOptionPane.ERROR_MESSAGE);
            System.exit(1);
    }
  });

try {
      job.print(doc, attributes);
     }
     catch(PrintException e) {
         System.out.println(e);
         System.exit(1);
     }
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads