Question

I want to print Header with some text and a specific logo and footer with some text and page no.

How to add image on header?

public class JEditorPaneTest {
    public static void main(String args[]) {
        JEditorPane pane = new JEditorPane();
        JScrollPane js = new JScrollPane(pane);
        try {
            URL url = new URL("file:C:/temp/html/12.html");
            // File f=new File("C:/temp/html/12.html");
            pane.setPage(url);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        pane.setContentType("text/html");
        JFrame frmae = new JFrame();
        frmae.setSize(200, 300);
        try {
            MessageFormat header = new MessageFormat("Order Details History");
            MessageFormat footer = new MessageFormat(" Page #{0,number,integer}");
            pane.print(header, footer);

        } catch (PrinterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // frmae.add(pane);
        frmae.add(js);
        frmae.setVisible(true);
    }
}
Was it helpful?

Solution

http://java-sl.com/JEditorPanePrinter.html this one is editor kit independent printing http://java-sl.com/Pagination_In_JEditorPane_HF.html this one if you need WYSIWYG editor.

Or you can jus override paintComponent() method and after calling super draw your images over the content.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top