关于报表固定尺寸的纸张进行打印的问题(50分)

  • 主题发起人 主题发起人 1q
  • 开始时间 开始时间
1

1q

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将报表按照固定尺寸的纸张进行打印?能够直接输出打印,最好提供预缆功能!
这个需求该如何实现?
大侠们多多帮助!
 
制作报表时按你的纸张大小制作就可以了呀。
 
function SetPaperSize(var nWidth,nHeight,nOrient:Word;var nHandle: THandle):integer;
export;
var
szPrinterKey: array[0..99] of Char;
szDeviceName: String;
szPort: String;
cbBuffer: DWORD;
dwRV: DWORD;
dwPapers: DWord;
lpwPapers: array[0..255] of Word;
fSupportUserDefind: Boolean;
fSupportA3: Boolean;
fSupportA4: Boolean;
fSupportB5: Boolean;
hDriver: THandle;
hMem: HGLOBAL;
lpDevMode: Pdevicemode;
a1: Pdevicemode;
i: integer;
begin
fSupportUserDefind:=FALSE;
fSupportA3:=FALSE;
fSupportA4:=FALSE;
fSupportB5:=FALSE;
//取当前默认打印机设备名
szDeviceName:=GetDeviceName();
if szDeviceName='' then
result:=-1;
//取打印机端口
szPort:=GetPortName();
if szPort='' then
result:=-2;
//取打印机支持的全部纸型
dwPapers:=DeviceCapabilities(PChar(szDeviceName),PChar(szPort),DC_PAPERS,@lpwPapers,nil);
if (dwPapers<1)or(dwPapers>256) then
result:=-3;
//判断打印机是否支持自定义、A3、A4、B5纸型
while (dwPapers > 0)do
begin
case DWORD(lpwPapers[dwPapers]) of
DMPAPER_USER: fSupportUserDefind:=TRUE;
DMPAPER_A3: fSupportA3:=TRUE;
DMPAPER_A4: fSupportA4:=TRUE;
DMPAPER_B5: fSupportB5:=TRUE;
end;
dwPapers:=dwPapers-1;
end;

//取打印机的DeviceMode
a1:=nil;
if not(OpenPrinter(PChar(szDeviceName),hDriver,nil)) then
result:=-4;
hMem:=GlobalAlloc(GPTR,DocumentPropertiesA(nHandle,hDriver,PChar(szDeviceName),a1^,a1^,0));
lpDevMode:=GlobalLock(hMem);
a1:=nil;
do
cumentProperties(nHandle,hDriver,PChar(szDeviceName),lpDevMode^,a1^,DM_OUT_BUFFER);
//设置纸型或大小
i:=0;
if ((nWidth=2970)and(nHeight=4200))and(fSupportA3) then
i:=1;
if ((nWidth=2100)and(nHeight=2970))and(fSupportA4) then
i:=i+2;
if ((nWidth=1820)and(nHeight=2570))and(fSupportB5) then
i:=i+3;
case i of
1: begin
//A3
lpDevMode.dmFields:=DM_PAPERSIZE;
lpDevMode.dmPaperSize:=DMPAPER_A3;
end;
2: begin
//A4
lpDevMode.dmFields:=DM_PAPERSIZE;
lpDevMode.dmPaperSize:=DMPAPER_A4;
end;
3: begin
//B5
lpDevMode.dmFields:=DM_PAPERSIZE;
lpDevMode.dmPaperSize:=DMPAPER_B5;
end;
else
if fSupportUserDefind then
begin
lpDevMode.dmFields:=DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
lpDevMode.dmPaperSize:=DMPAPER_USER;
lpDevMode.dmPaperWidth:=nWidth;
lpDevMode.dmPaperLength:=nHeight;
end
else
lpDevMode.dmFields:=0;
end;

//设置方向
case nOrient of
0: begin
lpDevMode.dmFields:=lpDevMode.dmFields or DM_ORIENTATION;
lpDevMode.dmOrientation:=DMORIENT_PORTRAIT;
end;
1: begin
lpDevMode.dmFields:=lpDevMode.dmFields or DM_ORIENTATION;
lpDevMode.dmOrientation:=DMORIENT_LANDSCAPE;
end;
end;

a1:=nil;
do
cumentProperties(nHandle,hDriver,PChar(szDeviceName),a1^,lpDevMode^,DM_IN_BUFFER or DM_UPDATE);
GlobalUnlock(hMem);
GlobalFree(hMem);
ClosePrinter(hDriver);
result:=1;
end;
 
可以说的再详细一点吗?我是菜鸟!
 
其实你不用这样麻烦,你在设计报表时预先定义好纸张大小就可以了.然后在你的打印机自定义和报表尺寸一样的纸张就可以了.
 
你用什么设计的报表啊?
 
这个问题我已经解决了!我用QREPORT组件就可以实现了!
谢谢大家对我的帮助!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部