If is not a problem to put the content of the file in a printpreview like window, use this:
somewhere in your class you add
protected PrintableEditorPane PrintViewer;
and
PrintViewer = new PrintableEditorPane(file);
PrintViewer.setEditable(fa
PrintViewer.printContent()
Of course PrintableEditorPane .... you have to make:
import java.io.IOException;
import java.awt.*;
import java.awt.geom.*;
import java.awt.Graphics2D;
import java.awt.print.*;
import javax.swing.*;
public class PrintableEditorPane extends JEditorPane implements Printable{
public PrintableEditorPane(String
super(file);
}
public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.black);
RepaintManager.currentMana
Dimension d = this.getSize();
double panelWidth = d.width;
double panelHeight = d.height;
double pageHeight = pf.getImageableHeight();
double pageWidth = pf.getImageableWidth();
double scale = pageWidth/panelWidth;
int totalNumPages = (int)Math.ceil(scale * panelHeight / pageHeight);
//System.out.println(panel
//System.out.println(pageH
//System.out.println(total
if(pageIndex >= totalNumPages) {
sec.util.Disp.printError("
return Printable.NO_SUCH_PAGE;
}
// Shift Graphic to line up with beginning of print-imageable region
g2.translate(pf.getImageab
// Shift Graphic to line up with beginning of next page to print
g2.translate(0f, -pageIndex * pageHeight);
// Scale the page so the width fits...
g2.scale(scale, scale);
this.paint(g2); //repaint the page for printing
return Printable.PAGE_EXISTS;
}
public void printContent(){
PrinterJob pj=PrinterJob.getPrinterJo
pj.setPrintable(this);
pj.printDialog();
if (pj.printDialog())
try{
pj.print();
} catch (Exception PrintException) {}
}
}
Thanx for the AAAAAA :)
Main Topics
Browse All Topics





by: ruff_ryderPosted on 2001-05-07 at 09:40:34ID: 6055238
Hi how you doing, JavaWorld has an entire articles series on printng in Java, check it out:
avaworld/j w-10-2000/ jw-1020- pr int.html
http://www.javaworld.com/j