打印和打印机设置函数Word文件下载.docx
- 文档编号:20391024
- 上传时间:2023-01-22
- 格式:DOCX
- 页数:20
- 大小:24.35KB
打印和打印机设置函数Word文件下载.docx
《打印和打印机设置函数Word文件下载.docx》由会员分享,可在线阅读,更多相关《打印和打印机设置函数Word文件下载.docx(20页珍藏版)》请在冰豆网上搜索。
如果任何参数的值为NULL,Print()函数返回NULL。
用法:
在打印作业中,PowerBuilder使用打印光标来跟踪打印位置。
打印光标保存了即将打印区域左上角的坐标。
使用Print()函数打印文本后,PowerBuilder自动更新打印光标。
PowerBuilder使用行距来决定打印出的两行文本之间的距离,行距与字符的高度成比例,缺省的行距是字符高度的1.2倍。
使用PrintSetSpacing()函数可以改变行距。
当Print()函数在下一行打印输出时,它把打印光标的x坐标设置为0、y坐标增加当前行距指示的数值。
由于每打印一行时Print()函数都自动调整打印光标的y坐标位置,因此,该函数会自动处理分页,因此,应用程序没有必要调用PrintPage()函数进行分页。
打印区由纸张的物理尺寸和边界空白决定,PrintSend()函数能够发送具体打印机的ESC控制序列,使用这个函数可以改变边界空白的大小。
另外,在打印开始之前,使用PrintDefineFont()和PrintSetFont()函数可以改变Print()使用的字体。
示例:
Thisexampleopensaprintjob,printsthestringSybaseCorporationinthedefaultfont,andthenstartsanewline:
longJob
//DefineablankpageandassignthejobanID
Job=PrintOpen()
//Printthestringandthenstartanewline
Print(Job,"
SybaseCorporation"
)
...
PrintClose(Job)
Thisexampleopensaprintjob,printsthestringSybaseCorporationinthedefaultfont,tabs5inchesfromtheleftedgeoftheprintareabutdoesnotstartanewline:
//Printthestringbutdonotstartanewline
5000)
ThefirstPrintstatementbelowtabshalfaninchfromtheleftedgeoftheprintarea,printsthestringSybaseCorporation,andthenstartsanewline.ThesecondPrintstatementtabsoneinchfromtheleftedgeoftheprintarea,printsthestringDirectors:
andthenstartsanewline:
//Printthestringandstartanewline
Print(Job,500,"
//Tab1inchfromtheleftedgeandprint
Print(Job,1000,"
Directors:
"
ThefirstPrintstatementbelowtabshalfaninchfromtheleftedgeoftheprintareaprintsthestringSybaseCorporation,andthentabs6inchesfromtheleftedgeoftheprintareabutdoesnotstartanewline.ThesecondPrintstatementprintsthecurrentdateandthenstartsanewline:
//Printstringandtab6inchesfromtheleftedge
6000)
//Printthecurrentdateonthesameline
Print(Job,String(Today()))
InawindowthatdisplaysadatabaseerrormessageinaMultiLineEditmle_message,thefollowingscriptforaPrintbuttonprintsatitlewiththedateandtimeandthemessage:
longli_prt
li_prt=PrintOpen("
DatabaseError"
Print(li_prt,"
Databaseerror-"
+String(Today(),"
mm/dd/yyyy"
)&
+"
-"
+String(Now(),"
HH:
MM:
SS"
))
"
Print(li_prt,mle_message.text)
PrintClose(li_prt)
2、PrintBitmap()
在打印区域的指定位置打印位图。
PrintBitmap(printjobnumber,bitmap,x,y,width,height)
bitmap:
string类型,指定要打印的位图文件的文件名;
x:
integer类型,指定位图起始打印位置的x坐标,以千分之一英寸为单位;
y:
integer类型,指定位图起始打印位置的y坐标,以千分之一英寸为单位;
width:
integer类型,指定位图的打印宽度,以千分之一英寸为单位。
如果该参数的值指定为0,那么按图像的原始宽度打印;
height:
integer类型,指定位图的打印高度,以千分之一英寸为单位。
如果该参数的值指定为0,那么按图像的原始高度打印。
如果任何参数的值为NULL,PrintBitmap()函数返回NULL。
执行PrintBitmap()函数后,打印光标的位置不变,依然停留在执行该函数前的位置上。
Thesestatementsdefineanewblankpageandthenprintthebitmapinfiled:
\PB\BITMAP1.BMPinitsoriginalsizeatlocation50,100:
//Defineanewblankpage.
//Printthebitmapinitsoriginalsize.
PrintBitmap(Job,"
d:
\PB\BITMAP1.BMP"
50,100,0,0)
//SendthepagetotheprinterandcloseJob.
3、PrintCancel()
取消用PrintOpen()函数启动的打印作业。
PrintCancel(printjobnumber)
要取消的打印作业的作业号。
如果参数printjobnumber的值为NULL,PrintCancel()函数返回NULL。
PrintCancel()函数取消指定的打印作业,删除相应的打印池文件,关闭打印作业,所以,应用程序执行了PrintCancel()函数之后,不需要再执行PrintClose()函数关闭打印作业了。
Inthisexample,ascriptforaPrintbuttonopensaprintjobandthenopensawindowwithacancelbutton.Iftheuserclicksonthecancelbutton,itsscriptsetsaglobalvariablethatindicatesthattheuserwantstocancelthejob.AftereachprintingcommandinthePrintbutton'
sscript,thecodecheckstheglobalvariableandcancelsthejobifitsvalueisTRUE.
Thedefinitionoftheglobalvariableis:
booleangb_printcancel
ThescriptforthePrintbuttonis:
longjob,li
gb_printcancel=FALSE
job=PrintOpen("
TestPageBreaks"
IFjob<
1THEN
MessageBox("
Error"
"
Can'
topenaprintjob."
RETURN
ENDIF
Open(w_printcancel)
\PB\bitmap1.bmp"
5,10,0,0)
IFgb_printcancel=TRUETHEN
PrintCancel(job)
...//Additionalprintingcommands,
...//includingcheckinggb_printcancel
PrintClose(job)
Close(w_printcancel)
Thescriptforthecancelbuttoninthesecondwindowis:
gb_printcancel=TRUE
4、PrintClose()
关闭打印作业并把打印页面发送到打印机上。
PrintClose(printjobnumber)
要关闭的打印作业的作业号。
如果参数printjobnumber的值为NULL,PrintClose()函数返回NULL。
应用程序使用PrintOpen()函数启动打印作业后,必须使用PrintClose()在完成打印任务后关闭打印作业,或根据需要使用PrintCancel()函数取消打印作业。
Thisexampleopensaprintjob,whichcreatesablankpage,printsabitmaponthepage,thensendsthecurrentpagetotheprinterorspoolerandclosesthejob:
ulongJob
//Beginanewjobandanewpage.
PrintBitmap(Job,d:
\PB\BITMAP1,5,10,0,0)
5、PrintDataWindow()
打印数据窗口控件的内容,用该函数可以在一个打印作业中打印多个数据窗口控件的内容,每个都从新的一页开始打印。
PrintDataWindow(printjobnumber,dwcontrol)
dwcontrol:
要打印其内容的数据窗口控件名或子数据窗口控件名。
如果参数printjobnumber的值为NULL,PrintDataWindow()函数返回NULL。
应用程序通过多次执行PrintDataWindow()函数可以在一个打印作业中一次打印多个数据窗口的
内容,并且每个数据窗口都从新的一页开始打印。
当数据窗口的表现风格为RichTextEdit时,数据窗口中的每一行都在新的一页上开始打印。
需要注意的是,PrintDataWindow()函数在打印数据窗口时使用数据窗口本身定义的字体以及风格,使用PrintDefineFont()和PrintSetFont()函数为当前作业定义的字体不起作用。
ThesestatementssendthecontentsofthreeDataWindowcontrolstothecurrentprinterinasingleprintjob:
longjob
job=PrintOpen()
//EachDataWindowstartsprintingonanewpage.
PrintDataWindow(job,dw_EmpHeader)
PrintDataWindow(job,dw_EmpDetail)
PrintDataWindow(job,dw_EmpDptSum)
6、PrintDefineFont()
定义打印作业使用的字体,对每个打印作业PowerBuilder支持八种字体。
PrintDefineFont(printjobnumber,fontnumber,facename,height,weight,fontpitch,fontfamily,
italic,underline)
fontnumber:
指定赋给当前定义字体的编号,有效值在1到8之间facename:
string类型,指定字体名称,该字体应该是你的打印机支持的字体,比如“宋体”;
Integer类型,使用正值指定字体的高度,以千分之一英寸为单位;
使用负值指定字体点数,比如,-18代表18点。
一般来说,使用点数更精确些;
weight:
指定字体的磅数,正常字体为400磅,粗体为700磅;
fontpitch:
FontPitch枚举类型,指定字体标准。
有效取值为:
Default!
--缺省值;
Fixed!
--固定形式;
Variable!
--可变形式;
fontfamily:
FontFamily枚举类型,指定字体系列。
AnyFont!
、Decorative!
、Modern!
、Roman!
、Script!
、Swiss!
italic:
boolean类型,指定是否使用斜体样式。
TRUE--使用斜体样式;
FALSE--不使用斜体样式;
缺省值为FALSE;
underline:
boolean类型,指定是否加下划线。
TRUE--加下划线;
FALSE--不加下划线;
缺省值为FALSE。
如果任何参数的值为NULL,PrintDefineFont()函数返回NULL。
在一个打印作业中,应用程序能够最多同时定义8种字体。
当应用程序需要使用更多的字体时,可以在使用了某个字体号输出内容后使用PrintDefineFont()函数将该字体号对应的字体更换为其它字体。
Thesestatementsdefineanewblankpage,andthendefineprintfont1forJobasCourier10Cpi,18point,normalweight,defaultpitch,Decorativefont,withnoitalicorunderline:
Job=PrintOpen()
PrintDefineFont(Job,1,"
Courier10Cpi"
-18,400,Default!
Decorative!
FALSE,FALSE)
7、PrintLine()
在当前打印页上绘出指定厚度的一条线。
PrintLine(printjobnumber,x1,y1,x2,y2,thickness)
x1:
integer类型,指定直线起点的x坐标,以千分之一英寸为单位;
y1:
integer类型,指定直线起点的y坐标,以千分之一英寸为单位;
x2:
integer类型,指定直线终点的x坐标,以千分之一英寸为单位;
y2:
integer类型,指定直线终点的y坐标,以千分之一英寸为单位;
thickness:
integer类型,指定直线的厚度,以千分之一英寸为单位。
如果任何参数的值为NULL,PrintLine()函数返回NULL。
应用程序执行了PrintLine()函数后,该函数并不改变打印光标的位置。
Thesestatementsstartanewpageinaprintjobandthenprintalinestartingat0,5andendingat7500,5withathicknessof10/1000ofaninch:
...//variousprintcommands
//Startanewpage.
PrintPage(Job)
//Printalineatthetopofthepage
PrintLine(Job,0,5,7500,5,10)
...//Otherprinting
8、PrintOpen()
启动打印作业并返回作业号。
PrintOpen({jobname})
jobname:
string类型,可选项,指定要打开打印作业的名称,该名称将显示在打印管理器窗口中。
Long。
函数执行成功时返回打印作业号,发生错误时返回-1。
如果任何参数的值为NULL,
PrintOpen()函数返回NULL。
应用程序执行PrintOpen()函数后,启动新的打印作业并走纸到下一页,同时将打印机缺省字体设置为该打印作业的字体。
打印光标的位置位于打印区的左上角。
其它同组的打印函数使用PrintOpen()函数返回的作业号来标识作业。
需要注意的是,使用PrintOpen()函数打开打印作业、使用同组的其它函数完成打印任务后,必须使用PrintClose()关闭打印作业,或根据需要使用PrintCancel()函数取消打印作业。
Thisexampleopensajobbutdoesnotgiveitaname:
ulongli_job
li_job=PrintOpen()
Thisexampleopensajobandgivesitaname:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 打印 打印机 设置 函数