精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>Delphi 网络编程>>Delphi开发WEB应用程序打印组件(3)

主题:Delphi开发WEB应用程序打印组件(3)
发信人: mark7312(小马哥)
整理人: soaringbird(2001-08-20 08:36:50), 站内信件
五、代码解析 


  在这个组件中,我们所要解决的几个问题: 


(1)、在delphi的应用程序设计中自定义打印纸张的设置,delphi中自身带了一个quickreport的打印设计程序,这个程序在一定的程度上方便了打印的设计,但这个设计程序对于自定义纸张的设定和打印支持却不是很好。因此,在这个组件中我们采用手工代码来设定自定义纸张大小。 


function tprttest3.initprintpaper:boolean; 


var 


device:array [0..cchdevicename-1] of char; 


driver:array [0..(max_path-1)] of char; 


port:array [0..32] of char; 


hdmode:thandle; 


pdmode:pdevmode; 


begin 


result:=true; 


if prtiscustompaper then 


begin 


{设置打印机段} 


printer.getprinter(device,driver,port,hdmode); 




if hdmode<>0 then begin 


try 


pdmode:=globallock(hdmode); 


if pdmode<>nil then begin 


//设定打印的方向为纵向或横向 


if paperorientation<>0 then 

         pdmode^.dmorientation:=dmorient_landscape 


else pdmode^.dmorientation:=dmorient_portrait; 


       //设置拷贝份数为1份. 


pdmode^.dmcopies:=1; 


       //以毫米为单位的纸张大小. 


pdmode^.dmpaperlength:= paperheight*10; 


pdmode^.dmpaperwidth:=paperwidth*10; 


       //设置纸张类型为用户自定义. 


pdmode^.dmpapersize:=dmpaper_user; 


end; 


globalunlock(hdmode); 


printer.setprinter(device,driver,port,hdmode); 


except 


result:=false; 


end; 


end else begin 


result:=false; 


end; 


end; 


end; 





----

[关闭][返回]