print a report sourced by html page
-
I'm working on a system and we have a problem on printing. System send an html content to the print class and we could not get a proper print page. I'm writing my codes. Please have a look..(sorry about my bad english) PrintableEditorPane pane = new PrintableEditorPane( html.getText()); pane.setContentType("text/html"); EditorPanePrinter pnl = new EditorPanePrinter(pane, new Paper(), new Insets(18, 18, 18, 18)); pnl.print(); ---and this is my printing class package org.esse.utility.image; import javax.swing.*; import javax.swing.text.View; import javax.swing.text.Position; import javax.print.PrintService; import java.awt.print.*; import java.awt.*; import java.awt.geom.Area; import java.awt.geom.AffineTransform; import java.util.ArrayList; public class EditorPanePrinter extends JPanel implements Pageable, Printable { JEditorPane sourcePane; Paper paper; Insets margins; ArrayList pages; int pageWidth; int pageHeight; View rootView; public static int PAGE_SHIFT = 20; PageFormat pageFormat; public EditorPanePrinter(JEditorPane pane, Paper paper, Insets margins) { initData(pane, paper, margins); } public void initData(JEditorPane pane, Paper paper, Insets margins) { JEditorPane tmpPane = new JEditorPane(); tmpPane.setEditorKit(pane.getEditorKit()); tmpPane.setContentType(pane.getContentType()); tmpPane.setText(pane.getText()); this.sourcePane = tmpPane; this.paper = paper; this.margins = margins; this.pageWidth = (int) paper.getWidth(); this.pageHeight = (int) paper.getHeight(); pageFormat = new PageFormat(); paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight() ); pageFormat.setPaper(paper); doPagesLayout(); } public void doPagesLayout() { setLayout(null); removeAll(); this.rootView = sourcePane.getUI().getRootView(sourcePane); sourcePane.setSize(pageWidth - margins.top - margins.bottom, Integer.MAX_VALUE); Dimension d = sourcePane.getPreferredSize(); sourcePane.setSize(pageWidth - margins.top - margins.bottom, d.height); calculatePageInfo(); int count = pages.size(); this.setPreferredSize(new Dimension(pageWidth * 2 + 50, PAGE_SHIFT + count * (pa
-
I'm working on a system and we have a problem on printing. System send an html content to the print class and we could not get a proper print page. I'm writing my codes. Please have a look..(sorry about my bad english) PrintableEditorPane pane = new PrintableEditorPane( html.getText()); pane.setContentType("text/html"); EditorPanePrinter pnl = new EditorPanePrinter(pane, new Paper(), new Insets(18, 18, 18, 18)); pnl.print(); ---and this is my printing class package org.esse.utility.image; import javax.swing.*; import javax.swing.text.View; import javax.swing.text.Position; import javax.print.PrintService; import java.awt.print.*; import java.awt.*; import java.awt.geom.Area; import java.awt.geom.AffineTransform; import java.util.ArrayList; public class EditorPanePrinter extends JPanel implements Pageable, Printable { JEditorPane sourcePane; Paper paper; Insets margins; ArrayList pages; int pageWidth; int pageHeight; View rootView; public static int PAGE_SHIFT = 20; PageFormat pageFormat; public EditorPanePrinter(JEditorPane pane, Paper paper, Insets margins) { initData(pane, paper, margins); } public void initData(JEditorPane pane, Paper paper, Insets margins) { JEditorPane tmpPane = new JEditorPane(); tmpPane.setEditorKit(pane.getEditorKit()); tmpPane.setContentType(pane.getContentType()); tmpPane.setText(pane.getText()); this.sourcePane = tmpPane; this.paper = paper; this.margins = margins; this.pageWidth = (int) paper.getWidth(); this.pageHeight = (int) paper.getHeight(); pageFormat = new PageFormat(); paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight() ); pageFormat.setPaper(paper); doPagesLayout(); } public void doPagesLayout() { setLayout(null); removeAll(); this.rootView = sourcePane.getUI().getRootView(sourcePane); sourcePane.setSize(pageWidth - margins.top - margins.bottom, Integer.MAX_VALUE); Dimension d = sourcePane.getPreferredSize(); sourcePane.setSize(pageWidth - margins.top - margins.bottom, d.height); calculatePageInfo(); int count = pages.size(); this.setPreferredSize(new Dimension(pageWidth * 2 + 50, PAGE_SHIFT + count * (pa
Waaaaaaaaay too much code. The least you could do is format it as a <code> block.