打印中动态设置纸张大小带来的烦恼!(50分)

S

suiyuan

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要在打印中动态设置纸张大小,从以前的帖子中发现一段代码,能够实现,
但也有了新的麻烦,每次调用它时,不管打印机是什么状态,
都会弹出一个警告窗口---“请插入纸张”
哪为高手能帮忙解决,或者有更好的方法来控制纸张的大小?

那段代码如下:

在打印前调用以下函数
procedure SetPaperSize(X, Y: Integer);
// 这段代码绝对可用。单位是0.1mm
// A4时 Printer.Pagewidth:=1440; A5时 Printer.Pagewidth:=1049;
// B5时 Printer.Pagewidth:=1290; 16K时 Printer.Pagewidth:=1035;
// lq1600宽行打印机这个值宽度最大为42cm左右, 长度大约2m。
{Question:
How can I change the papersize of my print job?
Answer:
One way to change printer settings at the start
of a print job is to change the printer's devicemode
structure.
See: TDEVMODE in the Delphi 1.02 help file or DEVMODE
in the Delphi 2.01 help file for other settings you can
change (providing the print driver supports the change).
The following example, contains code to change the papersize and
the paper bin that is uses:}
var
Device: array[0..255] of char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
hDMode: THandle;
PDMode: PDEVMODE;
begin

Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then

begin

pDMode := GlobalLock(hDMode);
if pDMode <> nil then

begin

if (x = 0) or (y = 0) then

begin

{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
{pDMode^.dmPaperSize := DMPAPER_LEGAL;
changed by wulianmin}
pDMode^.dmPaperSize := DMPAPER_FANFOLD_US;
end
else

begin

{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth := x {SomeValueInTenthsOfAMillimeter};
pDMode^.dmPaperLength := y {SomeValueInTenthsOfAMillimeter};
end;

{Set the bin to use}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;

GlobalUnlock(hDMode);
end;

end;

Printer.PrinterIndex := Printer.PrinterIndex;
//以下开始打印
end;

 
你用的是老式的针打吧,我也曾遇到过,没什么好办法
如果是激光打印机,应该不会的
 
没错,是老式的针打--LQ2600K
单位里就这种打印机,没有别的了,真的没什么好办法吗?
 
把你的打印机进纸设置从手动改成其它的方式就行了!
^^^^
 
不行,我试了几种打印机(canon 5500,lq1600k),都是如此:-(
 
把此句去掉:
{Set the bin to use}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
是设定进纸为手动(DMBIN_MANUAL)
 
黄豆:您说的没错,可惜我太笨,没看懂那段代码。
coffeeffee:非常感谢您的帮助,现在没问题了,痛快!
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
691
import
I
I
回复
0
查看
598
import
I
I
回复
0
查看
600
import
I
I
回复
0
查看
699
import
I
顶部