delphi如何修改打印机首选项设置页码

如何在程序里控制打印纸张大小(A3,A4)和打印方向?不想打开设置窗口 ---------------------------------------------------------------
TForm1.Button1Click(Sender:
array[0..255]
DeviceHandle:
//初始化打印机
Printer.GetPrinter(ADevice,
DeviceHandle);
DeviceHandle
Printer.PrinterIndex
Printer.PrinterI
Printer.GetPrinter(ADevice,
DeviceHandle);
DeviceHandle
Exception.Create('不能初始化打印机!')
GlobalLock(DeviceHandle);
DeviceHandle
DM_ORIENTATION;
//在下面这里设置打印方向
dmOrientation
DMORIENT_LANDSCAPE;
//DMORIENT_PORTRAIT
dmPaperSize
DMPAPER_A3;
Printer.SetPrinter(ADevice,
DeviceHandle);
GlobalUnLock(DeviceHandle);
PrinterSetupDialog1.E
//验证一下设置是否成功了
*************printer.pagewidth是只读属性
---------------------------------------------------------------
参考这个 var
PDEVMODE;Printer.GetPrinter(Device,
GlobalLock(hDMode);
pDMode^.dmFields
DM_PAPERSIZE
DM_PAPERWIDTH
DM_PAPERLENGTH;
pDMode^.dmPaperSize
DMPAPER_USER;
pDMode^.dmPaperWidth
pDMode^.dmPaperLength
pDMode^.dmFields:=pDMode^.dmFields
DM_ORIENTATION;
pDMode^.DMORIENTATION:=
//打印机设置的纸张大小
--------------------------------------------------------------- 在执行打印前调用以下函数:
SetPaperSize(X,
单位是0.1mm
Printer.Pagewidth:=1440;
Printer.Pagewidth:=1049;
Printer.Pagewidth:=1290;
Printer.Pagewidth:=1035;
lq1600宽行打印机这个值宽度最大为42cm左右,
长度大约2m。
//改变devicemode结构
array[0..255]
array[0..255]
array[0..255]
Printer.PrinterIndex
Printer.PrinterI
Printer.GetPrinter(Device,
GlobalLock(hDMode);
pDMode^.dmFields
pDMode^.dmFields
{pDMode^.dmPaperSize
DMPAPER_LEGAL;
wulianmin}
pDMode^.dmPaperSize
DMPAPER_FANFOLD_US;
pDMode^.dmFields
pDMode^.dmFields
DM_PAPERSIZE
DM_PAPERWIDTH
DM_PAPERLENGTH;
pDMode^.dmPaperSize
DMPAPER_USER;
pDMode^.dmPaperWidth
{SomeValueInTenthsOfAMillimeter};
pDMode^.dmPaperLength
{SomeValueInTenthsOfAMillimeter};
{设定纸张来源}
pDMode^.dmFields
pDMode^.dmFields
DMBIN_MANUAL;
pDMode^.dmDefaultSource
DMBIN_MANUAL;
GlobalUnlock(hDMode);
Printer.PrinterIndex
Printer.PrinterI
//以下开始打印
Printer.BeginD
Printer.Canvas.TextOut(100,100,
Printer.EndD
xinzheng_wang
浏览: 81128 次
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'获取默认打印机名:function TForm1.GetDefaultPrinterName:
sIniFile, sSection, sKeyName: PC
iSize := 256;
sIniFile := 'win.ini';
sSection := 'windows';
sKeyName := 'device';
SetLength(Result, iSize);
GetPrivateProfileString(sSection, sKeyName, nil, PChar(Result), iSize, sIniFile);
Result := Copy(Result, 0, Pos(',', Result) - 1);
更改默认打印机:需要Uses WinSpoolprocedure ChangeDefaultPrinter(const Name: string);
W2KSDP: function(pszPrinter: PChar): B
Size, Dummy: C
PI: PPrinterInfo2;
if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion &= 5) then
@W2KSDP := GetProcAddress(GetModuleHandle(winspl), 'SetDefaultPrinterA');
if @W2KSDP = nil then RaiseLastOSE
if not W2KSDP(PChar(Name)) then RaiseLastOSE
if not OpenPrinter(PChar(Name), H, nil) then RaiseLastOSE
GetPrinter(H, 2, nil, 0, @Size);
if GetLastError && ERROR_INSUFFICIENT_BUFFER then RaiseLastOSE
GetMem(PI, Size);
if not GetPrinter(H, 2, PI, Size, @Dummy) then RaiseLastOSE
PI^.Attributes := PI^.Attributes or PRINTER_ATTRIBUTE_DEFAULT;
if not SetPrinter(H, 2, PI, PRINTER_CONTROL_SET_STATUS) then RaiseLastOSE
FreeMem(PI);
ClosePrinter(H);
//ChangeDefaultPrinterChangeDefaultPrinter函数 在D7下使用SetDefaultPrinterA,在Delphi2010以上版本使用SetDefaultPrinterWprocedure TDM.ChangeDefaultPrinter(const Name: string);
Device: array[0..255] of C
Driver: array[0..255]
Port: array[0..255]
s : array[0..255] of C
hDeviceMode: TH
for I := 0 to Printer.Printers.Count - 1 do
if Printer.Printers.Strings[I] = name then
Printer.PrinterIndex := I;
Printer.GetPrinter (Device, Driver, Port, hDeviceMode);
StrCopy (s, Device);
StrCat (s, ',');
StrCat (s, Driver);
StrCat (s, ',');
StrCat (s, Port);
WriteProfileString ('windows', 'device', s);
StrCopy (s, 'windows');
SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@s));
//这个函数也可以更改打印机,效果没有上面的好
声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至: 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。Delphi7中已经设置了纸张大小,但打印时仍按A4纸打_百度知道
Delphi7中已经设置了纸张大小,但打印时仍按A4纸打
用Delphi7作了个小程序,需要打印非标纸张,在Delphi7中设置了纸张大小,在制作的表格上是用设置的纸张大小显示,打印时却按A4纸走,我也在打印机服务器属性中创建了新格式,并且设为默认的打印纸张,而在Delphi7中却看不到新格式的名称,打印时还是按A4执行,...
在Delphi7程序里我再加了一个关于设置纸张大小的语句,问题已经解决。不论我在Delphi7自带的控件设,还是打印服务器属性里设新格式或是在打印机里的属性设所有为默认的新纸格式都不管用,原来只要在Delphi7中再加一句设置纸张大小的语句就可以了。谢谢大家的帮忙!
我有更好的答案
估计是没有设置成功,不行就不要在程序里面设置纸张了,直接取打印机默认纸张,当然默认纸张及默认打印机要设置一下。
采纳率:43%
还是windows打印机设置的问题,打印首选项要设置,纸盒设置也要设,,,两个地方,丢一个都不行
你用的什么控件打印的啊?
为您推荐:
其他类似问题
delphi7的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。如何 编程 修改打印机打印内容?
[问题点数:80分,结帖人wangyaninglm]
如何 编程 修改打印机打印内容?
[问题点数:80分,结帖人wangyaninglm]
只显示楼主
取消只显示楼主
匿名用户不能发表回复!|Delphi程序实现打印功能_百度文库
赠送免券下载特权
10W篇文档免费专享
部分付费文档8折起
每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Delphi程序实现打印功能
你可能喜欢

我要回帖

更多关于 打印机首选项设置 的文章

 

随机推荐