⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在java中轻松打印文档__天极yesky2.htm

📁 java swing DocumentRenderer,all jdk。
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0040)http://www.yesky.com/237/1709237_1.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>在Java中轻松打印文档__天极Yesky</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN>
<META content=all name=robots>
<META content="index, follow" name=googlebot>
<META content="MSHTML 6.00.2800.1561" name=GENERATOR>
<META content="天极Yesky | 全球中文IT第一门户" name=author>
<META content="天极Yesky | 全球中文IT第一门户" name=Copyright>
<META 
content=Java,在Java中轻松打印文档,本文就将介绍这样一个对象――DocumentRenderer,它将一个文档作为方法中的一个参数并处理指定任务来完成打印,在Java中轻松打印文档 
name=description></META>
<META content=Java,硬件,软件,数码,游戏,e时代,下载,社区,评测,笔记本; name=keywords><LINK media=all 
href="在Java中轻松打印文档__天极Yesky2.files/y_newcontent.css" type=text/css 
rel=stylesheet>
<SCRIPT language=JavaScript 
src="在Java中轻松打印文档__天极Yesky2.files/newcontentjs.js"></SCRIPT>
</HEAD>
<BODY><!--头部-->
<SCRIPT src="在Java中轻松打印文档__天极Yesky2.files/y_newcontenthead_0608.js"></SCRIPT>
<!--当前位置开始-->
<DIV id=currentposition><SPAN>您现在的位置: <A 
href="http://www.yesky.com/">天极Yesky</A> &gt; <A 
href="http://soft.yesky.com/">软件</A> &gt; <A 
href="http://dev.yesky.com/">开发者网络</A> </SPAN><SPAN 
style="PADDING-LEFT: 240px"><SPAN id=ad2></SPAN></SPAN></DIV><!--当前位置结束--><!--正文开始-->
<DIV id=contentarea><!--左部开始-->
<DIV id=contentleft><!--左部的右部开始-->
<DIV id=contentright1><!--文章内容开始-->
<DIV class="left fontsize2">在Java中轻松打印文档</DIV>
<DIV class=fontclear></DIV><BR>
<DIV class=left><SPAN class=span>作者:sadly</SPAN><SPAN 
class=span>出处:论坛</SPAN><SPAN class=span>责任编辑:<A title=向本编辑提问 
href="http://comments.yesky.com/t/·&frac12;&Ouml;&Ucirc;/6,324/1709237.shtml"> 方舟 </A></SPAN><SPAN 
class=span>[ 2003-06-20 12:39 ]</SPAN></DIV>
<DIV class=fontclear></DIV>
<DIV 
class="left fontsize3">本文就将介绍这样一个对象――DocumentRenderer,它将一个文档作为方法中的一个参数并处理指定任务来完成打印</DIV>
<DIV class=fontclear></DIV>
<HR class=hr1>

<CENTER><SPAN id=ad9></SPAN></CENTER>
<DIV class="left fontsize4">
<DIV class=guanggao><SPAN id=ad3></SPAN></DIV>
<DIV class=guanggao><SPAN 
id=contentAdv></SPAN></DIV>  <B>显示文档</B><BR><BR>  DocumentRenderer能够用来打印几类包含在JEditorPane中的文档。我们用三种类型的文档(JEditorPane能够缺省识别的)测试了这个printer类:HTMLDocuments、PlainDocuments和Rich 
Text Format文档。只需要做一些很小的改动,这个类就应该可以将包含在JEditorPane中的其他类型文档打印出来了。 
<P></P>
<P>  DocumentRenderer类将一个文档的打印形式从其视频显示中区分出来了。这就使你能够针对特定的打印结果进行文本格式化,而会不影响其屏幕显示。DocumentRenderer采用所有打印页面的实际大小来显示文本并计算出行间距(line 
break)。当文档的宽度不足以显示在打印页面上时,该类会允许使用缩放(scaling)。</P>
<P>  DocumentRenderer相当智能。分页符不会将一行单一语句分放到两个页面上。字符也不会被切成两半,不会象浏览器在处理一般打印时会在这一页末尾显示一句话的上半部分而在下一页的顶部显示这句话的下半部分。这个类能够处理大量字体、颜色和小图标。分栏文本的显示也没有问题。对于每一个JEditorPane能够显示的文本特性,通常DocumentRenderer都可以将这种性能呈现到纸上。</P>
<P>  你只需使用两行代码便可以将DocumentRenderer结合到你的程序中去了。用一个不带参数的构造器创建这个类的实例,再调用一个合适的打印方法来处理其他事情。比如,以下代码将打印这个htmlDocument,它是HTMLDocument类的一个有效实例:<BR></P>
<TABLE cellPadding=0 width="100%" bgColor=#ffffff border=0>
  <TBODY>
  <TR>
    <TD>DocumentRenderer DocumentRenderer = new 
      <BR>DocumentRenderer();<BR>DocumentRenderer.print(htmlDocument);</TD></TR></TBODY></TABLE>
<P>  它给用户显示一个打印对话框,允许用户选择打印机、打印数量等,同时还有一个取消打印的选项。</P>
<P>  PlainDocuments使用了print(PlainDocument)方法,采用和HTMLDocuments相同的方式执行打印。由于在Java中不能直接访问Rich 
Text 
Format文档,所以你必须将这种类型的文档发送到DocumentRenderer中(通过将它封装到一个JEditorPane里),就象这样:DocumentRenderer.print(jeditorPane);</P>
<P>  这里的jeditorPane是JEditorPane的一个有效实例,其中包含一个Rich Text Format文档。 </P>
<P>  为了给用户提供方便,你可以调用DocumentRenderer的pageDialog方法来显示一个打印对话框以便用户可以调整页面大小、页边设置和纸的打印方向(orientation)。DocumentRenderer还提供了一种方法使开发人员可以选择是否对那些无法在打印宽度内完全显示的文档进行按比例缩放。我们认为能够进行缩放通常是比较好的选择,因为它能够防止文本在正确的页边处被分开,但它似乎比较适合让用户去选择。这种名为setScaleWidthToFit(boolean)的方法提供了按比例缩放的选项。你必须确定在调用打印方法之前调用这个scaling和pageDialog方法。</P>
<P></P>
<DIV class=right>共4页。 <A class=page 
href="http://www.yesky.com/237/1709237.shtml" target=_self><FONT 
face=Webdings>9</FONT></A> <A class=page 
href="http://www.yesky.com/237/1709237.shtml" target=_self><FONT 
face=Webdings>7</FONT></A> <A class=page 
href="http://www.yesky.com/237/1709237.shtml" target=_self><B>1</B></A> <A 
class=page href="http://www.yesky.com/237/1709237_1.shtml" target=_self><FONT 
color=#666666><B>2</B></FONT></A> <A class=page 
href="http://www.yesky.com/237/1709237_2.shtml" target=_self><B>3</B></A> <A 
class=page href="http://www.yesky.com/237/1709237_3.shtml" 
target=_self><B>4</B></A> <A class=page 
href="http://www.yesky.com/237/1709237_2.shtml" target=_self><FONT 
face=Webdings>8</FONT></A> <A class=page 
href="http://www.yesky.com/237/1709237_3.shtml" target=_self><FONT 
face=Webdings>:</FONT></A></DIV></DIV>
<DIV class=fontclear></DIV>
<HR class=hr1>

<DIV class=left><SPAN id=ad7></SPAN></DIV>
<DIV class=fontclear></DIV>
<HR class=hr1>
<!--文章内容结束--><!--文章评论开始--><A name=tlwb></A>
<SCRIPT language=JavaScript>
<!--
var aid = 1709237;
var channelid = 324;
var tagname = "Java";
//-->
</SCRIPT>

<DIV class=photobox id=Layer11><A name=plpl></A>
<SCRIPT src="在Java中轻松打印文档__天极Yesky2.files/comments.js"></SCRIPT>
</DIV><SPAN id=commentsSpanText></SPAN>
<SCRIPT language=javascript><!--if(typeof(aid) != "undefined") {		document.write("<script language=\"JavaScript\" charset=\"gb2312\"  src=\"http://comments.yesky.com/articlereplies/6/"+(aid%5000)+"/"+aid+".js\"><\/script>"); }//--></SCRIPT>

<DIV class=left>
<DIV class=left><IMG 
src="在Java中轻松打印文档__天极Yesky2.files/y_newcontent27.gif"></DIV>
<DIV class=right><IMG 
src="在Java中轻松打印文档__天极Yesky2.files/y_newcontent28.gif"></DIV></DIV>
<DIV class=fontclear style="HEIGHT: 5px"></DIV><!--文章评论结束--><!--相关厂商开始--><A 
name=xgcs></A><!-- Error --><!--相关厂商结束--><!--相关产品开始--><A name=xgcp></A><!-- Error --><!--相关产品结束--><!--文字广告开始-->
<DIV id=adendtext><SPAN id=ad8></SPAN></DIV><!--文字广告结束--><!--最新更新等内容开始--><A 
name=xgwz></A>
<DIV class=photobg1>
<DIV class=newarticle1 id=Layer2-2>相关文章</DIV>
<DIV class=newarticle2 id=Layer2-2-1 style="DISPLAY: none; CURSOR: hand" 
onclick="MM_showHideLayers('Layer1','','show','Layer2-2','','show','Layer3-3-1','','show','Layer1-1-1','','show','Layer4-4-1','','show','Layer5-5-1','','show','Layer3','','hide','Layer2','','hide','Layer4','','hide','Layer5','','hide','Layer3-3','','hide','Layer1-1','','hide','Layer4-4','','hide','Layer5-5','','hide','Layer2-2-1','','hide')">相关文章</DIV>
<DIV class=newarticle2 id=Layer1-1-1 style="CURSOR: hand" 
onclick="MM_showHideLayers('Layer2','','show','Layer1-1','','show','Layer3-3-1','','show','Layer2-2-1','','show','Layer4-4-1','','show','Layer5-5-1','','show','Layer3','','hide','Layer1','','hide','Layer4','','hide','Layer5','','hide','Layer3-3','','hide','Layer2-2','','hide','Layer4-4','','hide','Layer5-5','','hide','Layer1-1-1','','hide')">最新更新</DIV>
<DIV class=newarticle1 id=Layer1-1 style="DISPLAY: none">最新更新</DIV>
<DIV class=newarticle2 id=Layer3-3-1 title=此文章的读者还看了以下文章 style="CURSOR: hand" 
onclick="MM_showHideLayers('Layer3','','show','Layer3-3','','show','Layer1-1-1','','show','Layer2-2-1','','show','Layer4-4-1','','show','Layer5-5-1','','show','Layer1','','hide','Layer2','','hide','Layer4','','hide','Layer5','','hide','Layer1-1','','hide','Layer2-2','','hide','Layer4-4','','hide','Layer5-5','','hide','Layer3-3-1','','hide')">继续阅读</DIV>
<DIV class=newarticle1 id=Layer3-3 title=此文章的读者还看了以下文章 
style="DISPLAY: none">继续阅读</DIV>
<DIV class=newarticle2 id=Layer4-4-1 title="本文编辑 方舟 的其他文章" style="CURSOR: hand" 
onclick="MM_showHideLayers('Layer4','','show','Layer4-4','','show','Layer1-1-1','','show','Layer2-2-1','','show','Layer3-3-1','','show','Layer5-5-1','','show','Layer1','','hide','Layer2','','hide','Layer3','','hide','Layer5','','hide','Layer1-1','','hide','Layer2-2','','hide','Layer3-3','','hide','Layer5-5','','hide','Layer4-4-1','','hide')">编辑新作</DIV>
<DIV class=newarticle1 id=Layer4-4 title="本文编辑 方舟 的其他文章" 
style="DISPLAY: none">编辑新作</DIV>
<DIV class=newarticle2 id=Layer5-5-1 title=阅读排行 style="CURSOR: hand" 
onclick="MM_showHideLayers('Layer5','','show','Layer5-5','','show','Layer1-1-1','','show','Layer2-2-1','','show','Layer3-3-1','','show','Layer4-4-1','','show','Layer1','','hide','Layer2','','hide','Layer3','','hide','Layer4','','hide','Layer1-1','','hide','Layer2-2','','hide','Layer3-3','','hide','Layer4-4','','hide','Layer5-5-1','','hide')">热点文章</DIV>
<DIV class=newarticle1 id=Layer5-5 title=阅读排行 
style="DISPLAY: none">热点文章</DIV></DIV>
<DIV class=photobox id=Layer1>
<DIV class=photocolorblock></DIV>
<DIV class=fontclear></DIV>
<DIV class=newarticlebox>
<UL>
  <LI><A 
  href="http://www.yesky.com/40/1704040.shtml">《东方影都2003》媒体工具测试</A>(2003-05-29 
  16:25) 
  <LI><A 
  href="http://www.yesky.com/458/1704458.shtml">优化JAVA性能的几种方法</A>(2003-06-05 
  00:00) 
  <LI><A 
  href="http://www.yesky.com/459/1704459.shtml">Java技术实现数据库应用系统慨述</A>(2003-06-04 
  00:00) 
  <LI><A href="http://www.yesky.com/462/1704462.shtml">深入理解Collections 
  API</A>(2003-06-06 00:00) 
  <LI><A 
  href="http://www.yesky.com/10/1706010.shtml">通过Java套接字传递对象</A>(2003-06-13 
  11:23) 
  <LI><A 
  href="http://www.yesky.com/11/1706011.shtml">正则表达式和Java编程语言</A>(2003-06-12 
  15:42) 
  <LI><A href="http://www.yesky.com/14/1706014.shtml">使用Java 
  API压缩和解压缩数据</A>(2003-06-16 09:16) 
  <LI><A 
  href="http://www.yesky.com/18/1706018.shtml">用RMI和CORBA进行分布式Java编程</A>(2003-06-17 
  15:18) 
  <LI><A 
  href="http://www.yesky.com/428/1706928.shtml">正则表达式和Java编程语言</A>(2003-06-11 
  14:40) 
  <LI><A 
  href="http://www.yesky.com/397/1707397.shtml">用Java实现PDF报表</A>(2003-06-12 
  15:05) 
  <LI><A href="http://www.yesky.com/443/1711443.shtml">Java游戏编程初步</A>(2003-07-01 
  17:54) 
  <LI><A 
  href="http://www.yesky.com/195/1711695.shtml">Java平台上的CRM系统</A>(2003-07-02 
  16:41) 
  <LI><A href="http://www.yesky.com/382/1712382.shtml">Java Swing 
  组件全演示</A>(2003-07-07 13:11) 
  <LI><A 
  href="http://www.yesky.com/202/1712702.shtml">在Word和WPS中打印反字</A>(2003-07-08 
  16:05) 
  <LI><A 
  href="http://www.yesky.com/114/1714114.shtml">Java开发中的线程安全选择与Swing</A>(2003-07-14 
  18:00) 
  <LI><A 
  href="http://www.yesky.com/163/1714663.shtml">Java布局管理器在现实工程中的应用</A>(2003-07-16 
  14:06) </LI></UL></DIV>
<DIV class=fontclear></DIV></DIV>
<DIV class=photobox id=Layer2 style="DISPLAY: none">
<DIV class=photocolorblock></DIV>
<DIV class=fontclear></DIV>
<DIV class=newarticlebox>
<UL>
  <LI><A href="http://diy.yesky.com/25/3037525.shtml">AMD推出DTX规格 打造轻巧型PC新标准</A> 
  <LI><A 
  href="http://digital.yesky.com/1/3037501.shtml">四大绝技傍身,朗科A150成车载MP3年底热推产品!</A> 

  <LI><A href="http://diy.yesky.com/input/0/3037500.shtml">发烧推荐:创新Fatal1ty 
  1010明星设计</A> 
  <LI><A href="http://notebook.yesky.com/498/3037498.shtml">再提性价比 宏基 Aspire 
  5583跌至8k售</A> 
  <LI><A href="http://sh.yesky.com/497/3037497.shtml">上海星光相机文化节开幕 新光影像网上线</A> 
  </LI></UL></DIV>
<DIV class=fontclear></DIV></DIV>
<DIV class=photobox id=Layer3 style="DISPLAY: none">
<DIV class=photocolorblock></DIV>
<DIV class=fontclear></DIV>
<DIV class=newarticlebox>
<UL>
  <LI><A href="http://diy.yesky.com/monitor/482/2696982.shtml">宽屏继续普及 
  明基22英寸FP222W售价破3K</A> </LI></UL></DIV>
<DIV class=fontclear></DIV></DIV>
<DIV class=photobox id=Layer4 style="DISPLAY: none">
<DIV class=photocolorblock></DIV>
<DIV class=fontclear></DIV>
<DIV class=newarticlebox>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -