Article View: borland.public.jbuilder.java.swing
Article #11040print a HTML doc
From: Roman Huerlimann
Date: Wed, 21 Jul 1999 00:00
Date: Wed, 21 Jul 1999 00:00
67 lines
2548 bytes
2548 bytes
Hi
I have a EditorPane with a HTML Document inside. This document I'm
printing. My Problem now: If there is more than one page I don't know
where to stop printing the first and starting the second page. It can
happen that one part of the line is on page 1 and the second on the page
2
Has anybody an idea?
Thanks
Roman
---------------------------------------------------------------------------------------------------------------
my print methode: (htmlPane is a JEditorPane)
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
if (pageIndex >= anzSeiten)
{
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.black);
int fontHeight=g2.getFontMetrics().getHeight();
int fontDesent=g2.getFontMetrics().getDescent();
//leave room for page number
double pageHeight = pageFormat.getImageableHeight()-fontHeight;
double pageWidth = pageFormat.getImageableWidth();
double htmlHeight = htmlPane.getPreferredSize().getHeight() *
htmlScale;
g2.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());
g2.drawString("Seite: "+(pageIndex+1),(int)pageWidth/2-35,
(int)(pageHeight+fontHeight-fontDesent));//bottom
center
g2.translate(0f, -pageIndex * pageHeight);
//If this piece of the table is smaller than the size available,
//clip to the appropriate bounds.
if (pageIndex + 1 == anzSeiten)
{
double h = htmlHeight - pageIndex * pageHeight;
g2.setClip(0, (int)(pageHeight * pageIndex),
(int) Math.ceil(pageWidth),
(int) Math.ceil(pageHeight * pageIndex + h));
}
//else clip to the entire area available.
else
{
g2.setClip(0, (int)(pageHeight * pageIndex),
(int) Math.ceil(pageWidth),(int) Math.ceil(pageHeight *
(pageIndex + 1)));
}
g2.scale(htmlScale, htmlScale);
htmlPane.paint(g2);
return Printable.PAGE_EXISTS;
}
Technical Details
Message-ID:
<3795DB99.E786FB0B@tamedia.ch>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e8a580a1d8445d9a,start X-Google-Attributes: gid111d45,public From: Roman Huerlimann <Roman.Huerlimann@tamedia.ch> Subject: print a HTML doc Date: 1999/07/21 Message-ID: <3795DB99.E786FB0B@tamedia.ch> X-Deja-AN: 503525459 Content-Transfer-Encoding: 7bit Organization: EUnet AG X-Accept-Language: de-CH,en Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing