Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. print a report sourced by html page

print a report sourced by html page

Scheduled Pinned Locked Moved Java
javahtmltoolshelp
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ceyhunerdil
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • C ceyhunerdil

      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

      D Offline
      D Offline
      David Skelly
      wrote on last edited by
      #2

      Waaaaaaaaay too much code. The least you could do is format it as a <code> block.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups