打印和打印机设置函数
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
打印和打印机设置函数
打印和打印机设置函数
打印函数用于在打印机上格式化输出数据。
这组函数与各对象的Print()函数有所不同,程序在使用这组函数时,需要使用PrintOpen()函数打开一个打印作业,然后根据需要执行这组函数中的一个或多个函数,最后使用PrintClose()函数关闭打印作业。
打印机设置函数用于得到当前的打印机名称,设置应用程序使用的打印机,得到系统中包含的所有打印机,显示打印机设置对话框等。
1、Print()
功能:以当前字体在打开的打印作业中打印一行或多行文本。
语法:Print(printjobnumber,{tab1,}string{,tab2})
参数:printjobnumber:用PrintOpen()函数打开的打印作业号;
tab1:Integer类型,可选项,指定文本开始打印的位置,在开始打印字符串之前将打印光标移动到该位置,从打印区的左边界开始计算,以千分之一英寸为单位。
如果打印光标已经位于指定位置、或打印光标已经超过了指定位置、或省略了该参数,那么,Print()函数从打印光标的当前位置开始打印string:string类型,指定要打印的字符串。
如果字符串中包括回车换行字符(~r~n),那么该字符串将被分成多行输出,但是,除第一行之外,其它行忽略tab1参数指定的起始打印位置;
tab2:Integer类型,可选项,指定字符串打印结束后打印光标移动到的位置,从打印区的左边界开始计算,以千分之一英寸为单位。
如果打印光标已经超过了指定位置,那么Print()函数忽略该参数,打印光标位于已打印字符串的尾部。
如果省略了该参数,Print()函数把打印光标移动到下一行的起始位置;
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果任何参数的值为NULL,Print()函数返回NULL。
用法:在打印作业中,PowerBuilder使用打印光标来跟踪打印位置。
打印光标保存了即将打印区域左上角的坐标。
使用Print()函数打
印文本后,PowerBuilder自动更新打印光标。
PowerBuilder使用行距来决定打印出的两行文本之间的距离,行距与字符的高度成比例,缺省的行距是字符高度的1.2倍。
使用PrintSetSpacing()函数可以改变行距。
当Print()函数在下一行打印输出时,它把打印光标的x坐标设置为0、y坐标增加当前行距指示的数值。
由于每打印一行时Print()函数都自动调整打印光标的y坐标位置,因此,该函数会自动处理分页,因此,应用程序没有必要调用PrintPage()函数进行分页。
打印区由纸张的物理尺寸和边界空白决定,PrintSend()函数能够发送具体打印机的ESC控制序列,使用这个函数可以改变边界空白的大小。
另外,在打印开始之前,使用PrintDefineFont()和PrintSetFont()函数可以改变Print()使用的字体。
示例:This example opens a print job, prints the string Sybase Corporation in the default font, and then starts a new line: long Job
// Define a blank page and assign the job an ID
Job = PrintOpen( )
// Print the string and then start a new line
Print(Job, "Sybase Corporation")
...
PrintClose(Job)
This example opens a print job, prints the string Sybase Corporation in the default font, tabs 5 inches from the left edge of the print area but does not start a new line:
long Job
// Define a blank page and assign the job an ID
Job = PrintOpen( )
// Print the string but do not start a new line
Print(Job, "Sybase Corporation", 5000)
...
PrintClose(Job)
The first Print statement below tabs half an inch from the left edge of the print area, prints the string Sybase Corporation, and then starts a new line. The second Print statement tabs one inch from the left edge of the print area, prints the string Directors:, and then starts a new line:
long Job
// Define a blank page and assign the job an ID
Job = PrintOpen( )
// Print the string and start a new line
Print(Job, 500, "Sybase Corporation")
// Tab 1 inch from the left edge and print
Print(Job, 1000, "Directors:")
...
PrintClose(Job)
The first Print statement below tabs half an inch from the left edge of the print area prints the string Sybase Corporation, and then tabs 6 inches from the left edge of the print area but does not start a new line. The second Print statement prints the current date and then starts a new line:
long Job
// Define a blank page and assign the job an ID
Job = PrintOpen( )
// Print string and tab 6 inches from the left edge
Print(Job, 500, "Sybase Corporation", 6000)
// Print the current date on the same line
Print(Job, String(T oday()))
...
PrintClose(Job)
In a window that displays a database error message in a MultiLineEdit mle_message, the following script for a Print button prints a title with the date and time and the message: long li_prt
li_prt = PrintOpen("Database Error")
Print(li_prt, "Database error - "+ String(Today(),
"mm/dd/yyyy") &
+ " - " + String(Now(), "HH:MM:SS"))
Print(li_prt, " ")
Print(li_prt, mle_message.text)
PrintClose(li_prt)
2、PrintBitmap()
功能:在打印区域的指定位置打印位图。
语法:PrintBitmap ( printjobnumber, bitmap, x, y, width, height )
参数:printjobnumber:用PrintOpen()函数打开的打印作业号;
bitmap:string类型,指定要打印的位图文件的文件名;
x:integer类型,指定位图起始打印位置的x坐标,以千分之一
英寸为单位;
y:integer类型,指定位图起始打印位置的y坐标,以千分之一
英寸为单位;
width:integer类型,指定位图的打印宽度,以千分之一英寸为
单位。
如果该参数的值指定为0,那么按图像的原始宽度打印;
height:integer类型,指定位图的打印高度,以千分之一英寸为单位。
如果该参数的值指定为0,那么按图像的原始高度打印。
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果任何参数的值为NULL,PrintBitmap()函数返回NULL。
用法:执行PrintBitmap()函数后,打印光标的位置不变,依然停留在执行该函数前的位置上。
示例:These statements define a new blank page and then print the bitmap in file d:\PB\BITMAP1.BMP in its original size at location 50,100:
long Job
// Define a new blank page.
Job = PrintOpen( )
// Print the bitmap in its original size.
PrintBitmap(Job, "d:\PB\BITMAP1.BMP", 50,100, 0,0)
// Send the page to the printer and close Job.
PrintClose(Job)
3、PrintCancel()
功能:取消用PrintOpen()函数启动的打印作业。
语法:PrintCancel ( printjobnumber )
参数:printjobnumber:要取消的打印作业的作业号。
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果参数printjobnumber的值为NULL,PrintCancel()函数返回NULL。
用法:PrintCancel()函数取消指定的打印作业,删除相应的打印池文件,关闭打印作业,所以,应用程序执行了PrintCancel()函数之后,不需要再执行PrintClose()函数关闭打印作业了。
示例:In this example, a script for a Print button opens a print job and then opens a window with a cancel button. If the user clicks on the cancel button, its script sets a global variable that indicates that the user wants to cancel the job. After each printing command in the Print button's script, the code checks the global variable and cancels the job if its value is TRUE.
The definition of the global variable is:
boolean gb_printcancel
The script for the Print button is:
long job, li
gb_printcancel = FALSE
job = PrintOpen("T est Page Breaks")
IF job < 1 THEN
MessageBox("Error", "Can't open a print job.")
RETURN
END IF
Open(w_printcancel)
PrintBitmap(Job, "d:\PB\bitmap1.bmp", 5, 10, 0, 0)
IF gb_printcancel = TRUE THEN
PrintCancel(job)
RETURN
END IF
... // Additional printing commands,
... // including checking gb_printcancel
PrintClose(job)
Close(w_printcancel)
The script for the cancel button in the second window is:
gb_printcancel = TRUE
Close(w_printcancel)
4、PrintClose()
功能:关闭打印作业并把打印页面发送到打印机上。
语法:PrintClose ( printjobnumber )
参数:printjobnumber:要关闭的打印作业的作业号。
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果参数printjobnumber的值为NULL,PrintClose()函数返回NULL。
用法:应用程序使用PrintOpen()函数启动打印作业后,必须使用PrintClose()在完成打印任务后关闭打印作业,或根据需要使用PrintCancel()函数取消打印作业。
示例:This example opens a print job, which creates a blank
page, prints a bitmap on the page, then sends the current page to the printer or spooler and closes the job:
ulong Job
// Begin a new job and a new page.
Job = PrintOpen( )
// Print the bitmap in its original size.
PrintBitmap(Job, d:\PB\BITMAP1, 5,10, 0,0)
// Send the page to the printer and close Job.
PrintClose(Job)
5、PrintDataWindow()
功能:打印数据窗口控件的内容,用该函数可以在一个打印作业中打印多个数据窗口控件的内容,每个都从新的一页开始打印。
语法:PrintDataWindow ( printjobnumber, dwcontrol )
参数:printjobnumber:用PrintOpen()函数打开的打印作业号;
dwcontrol:要打印其内容的数据窗口控件名或子数据窗口控件名。
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果参数printjobnumber的值为NULL,PrintDataWindow()函数返回NULL。
用法:应用程序通过多次执行PrintDataWindow()函数可以在一个打印作业中一次打印多个数据窗口的
内容,并且每个数据窗口都从新的一页开始打印。
当数据窗口的表现风格为RichTextEdit时,数据窗口中的每一行都在新的一页上开始打印。
需要注意的是,PrintDataWindow()函数在打印数据窗口时使用数据窗口本身定义的字体以及风格,使用PrintDefineFont()和PrintSetFont()函数为当前作业定义的字体不起作用。
示例:These statements send the contents of three DataWindow controls to the current printer in a single print job: long job
job = PrintOpen( )
// Each DataWindow starts printing on a new page.
PrintDataWindow(job, dw_EmpHeader)
PrintDataWindow(job, dw_EmpDetail)
PrintDataWindow(job, dw_EmpDptSum)
PrintClose(job)
6、PrintDefineFont()
功能:定义打印作业使用的字体,对每个打印作业PowerBuilder 支持八种字体。
语法:
PrintDefineFont(printjobnumber,fontnumber,facename,heig ht,weight,font pitch,fontfamily,
italic,underline)
参数:printjobnumber:用PrintOpen()函数打开的打印作业号;
fontnumber:指定赋给当前定义字体的编号,有效值在1到8之间 facename:string类型,指定字体名称,该字体应该是你的打印机支持的字体,比如“宋体”;
height: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。
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果任何参数的值为NULL,PrintDefineFont()函数返回NULL。
用法:在一个打印作业中,应用程序能够最多同时定义8
种字体。
当应用程序需要使用更多的字体时,可以在使用了某个字体号输出内容后使用PrintDefineFont()函数将该字体号对应的字体更换为其它字体。
示例:These statements define a new blank page, and then define print font 1 for Job as Courier 10Cpi, 18 point, normal weight, default pitch, Decorative font, with no italic or underline: long Job
Job = PrintOpen()
PrintDefineFont(Job, 1, "Courier 10Cpi", -18, 400, Default!, Decorative!, FALSE, FALSE)
7、PrintLine()
功能:在当前打印页上绘出指定厚度的一条线。
语法:PrintLine ( printjobnumber, x1, y1, x2, y2, thickness )
参数:printjobnumber:用PrintOpen()函数打开的打印作业号;
x1:integer类型,指定直线起点的x坐标,以千分之一英寸为单位;
y1:integer类型,指定直线起点的y坐标,以千分之一英寸为单位;
x2:integer类型,指定直线终点的x坐标,以千分之一英寸为单位;
y2:integer类型,指定直线终点的y坐标,以千分之一英寸为单位;
thickness:integer类型,指定直线的厚度,以千分之一英寸为单位。
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果任何参数的值为NULL,PrintLine()函数返回NULL。
用法:应用程序执行了PrintLine()函数后,该函数并不改变打印光标的位置。
示例:These statements start a new page in a print job and then print a line starting at 0,5 and ending at 7500,5 with a thickness of 10/1000 of an inch:
long Job
Job = PrintOpen( )
... // various print commands
// Start a new page.
PrintPage(Job)
// Print a line at the top of the page
PrintLine(Job,0,5,7500,5,10)
... // Other printing
PrintClose(Job)
8、PrintOpen()
功能:启动打印作业并返回作业号。
语法:PrintOpen ( { jobname } )
参数:jobname:string类型,可选项,指定要打开打印作业的名称,该名称将显示在打印管理器窗口中。
返回值:Long。
函数执行成功时返回打印作业号,发生错误时返回-1。
如果任何参数的值为NULL,
PrintOpen()函数返回NULL。
用法:应用程序执行PrintOpen()函数后,启动新的打印作业并走纸到下一页,同时将打印机缺省字体设置为该打印作业的字体。
打印光标的位置位于打印区的左上角。
其它同组的打印函数使用PrintOpen()函数返回的作业号来标识作业。
需要注意的是,使用PrintOpen()函数打开打印作业、使用同组的其它函数完成打印任务后,必须使用PrintClose()关闭打印作业,或根据需要使用PrintCancel()函数取消打印作业。
示例:This example opens a job but does not give it a name: ulong li_job
li_job = PrintOpen()
This example opens a job and gives it a name:
ulong li_job
li_job = PrintOpen("Phone List")
9、PrintOval()
功能:在指定位置以指定线宽绘制椭圆或圆。
语法:PrintOval ( printjobnumber, x, y, width, height, thickness )
参数:printjobnumber:用PrintOpen()函数打开的打印作业号;
x:integer类型,指定椭圆或圆外形框左上角的x坐标,以千分
之一英寸为单位;
y:integer类型,指定椭圆或圆外形框左上角的y坐标,以千分
之一英寸为单位;
width:integer类型,指定椭圆或圆外形框的宽度,以千分之一
英寸为单位;
height:integer类型,指定椭圆或圆外形框的高度,以千分之一英寸为单位;
thickness:integer类型,指定椭圆或圆外边线的厚度,以千分之一英寸为单位。
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果任何参数的值为NULL,PrintOval()函数返回NULL。
用法:应用程序执行了PrintOval()函数后,该函数并不改变打印光标的位置。
PrintOval()函数绘出的椭圆或圆是实心的,也就是说,执行该函数后,椭圆或圆下面的文字或图像将完全被覆盖。
如果想在椭圆或圆中输出文字或图形,那么应用程序应该首先绘制椭圆或圆,
然后使用其它函数在椭圆或圆中输出文字或图形。
示例:This example starts a print job with a new blank page, and then prints an oval that fits in a 1-inch square. The upper-left corner of the oval's bounding box is four inches from the top and three inches from the left edge of the print area. Because its height and width are equal, the oval is actually a circle: long Job
// Define a new blank page.
Job = PrintOpen()
// Print an oval.
PrintOval(Job, 4000, 3000, 1000, 1000, 10)
... // Other printing
PrintClose(Job)
10、PrintPage()
功能:将当前页发送给打印机或打印池并在当前打印作业中启动一个新的打印页。
语法:PrintPage ( printjobnumber )
参数:printjobnumber:用PrintOpen()函数打开的打印作业号。
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果任何参数的值为NULL,PrintPage()函数返回NULL。
示例:This example opens a print job with a new blank page, prints a bitmap on the page, and then sends the page to the printer and sets up a new blank page. Finally, the last Print statement prints the company name on the new page: long Job
// Open a job with new blank page.
Job = PrintOpen()
// Print a bitmap on the page.
PrintBitmap(Job, "d:\PB\BITMAP1.BMP", 100,250, 0,0)
// Begin a new page.
PrintPage(Job)
// Print the company name on the new page.
Print(Job, "Sybase Corporation")
11、PrintRect()
功能:在指定位置以指定线宽打印矩形。
语法:PrintRect ( printjobnumber, x, y, width, height, thickness )
参数:printjobnumber:用PrintOpen()函数打开的打印作业号;
x:integer类型,指定矩形左上角的x坐标,以千分之一英寸为
单位;
y:integer类型,指定矩形左上角的y坐标,以千分之一英寸为
单位;
width:integer类型,指定矩形的宽度,以千分之一英寸为单位;
height:integer类型,指定矩形的高度,以千分之一英寸为单位;
thickness:integer类型,指定矩形边线的厚度,以千分之一英
寸为单位。
返回值:Integer。
函数执行成功时返回1,发生错误时返回-1。
如果任何参数的值为NULL,PrintRect()函数返回NULL。
用法:应用程序执行了PrintRect()函数后,该函数并不改变打印光标的位置。
PrintRect()函数绘出实心的矩形,也就是说,执行该函数后,矩形下面的文字或图像将完全被覆盖。
如果想在矩形中输出文字或图形,那么应用程序应该首先绘制矩形,然后使用其它函数在矩形中输出文字或图形。
示例:These statements open a print job with a new page and draw a 1-inch square with a line thickness of 1/8 of an inch. The square's
upper left corner is four inches from the left and three inches from the top of the print area:
long Job
// Define a new blank page.
Job = PrintOpen()
// Print the rectangle on the page.
PrintRect(Job, 4000,3000, 1000,1000, 125)
... // Other printing
PrintClose(Job)
12、PrintRoundRect()
功能:在指定位置以指定线宽打印圆角矩形。
语法:
PrintRoundRect(printjobnumber,x,y,width,height,xradius,yra dius,thickn ess)
参数:printjobnumber:用PrintOpen()函数打开的打印作业号;
x:integer类型,指定圆角矩形左上角的x坐标,以千分之一英寸为单位;
y:integer类型,指定圆角矩形左上角的y坐标,以千分之一英寸为单位;。