Print any type of document using Delphi
来源:互联网 发布:吴语拼音软件 编辑:程序博客网 时间:2024/06/09 15:37
Print any type of document using Delphi
1.Drop a TComboBox on a form. Name it "cboPrinter". Set Style to csDropDownList.
2.Put the next two lines in the form's OnCreate event handler.
// have available printers in the combo box
cboPrinter.Items.Assign(printer.Printers);
// pre-select the default / active printer
cboPrinter.ItemIndex := printer.PrinterIndex;Now, here's the method you can use to print any document type to a specified printer:
uses ShellAPI, Printers;
...
procedure TForm1.PrintDocument(const documentToPrint : string) ;
var
printCommand : string;
printerInfo : string;
Device, Driver, Port: array[0..255] of Char;
hDeviceMode: THandle;
begin
if Printer.PrinterIndex = cboPrinter.ItemIndex then
begin
printCommand := 'print';
printerInfo := '';
end
else
begin
printCommand := 'printto';
Printer.PrinterIndex := cboPrinter.ItemIndex;
Printer.GetPrinter(Device, Driver, Port, hDeviceMode) ;
printerInfo := Format('"%s" "%s" "%s"', [Device, Driver, Port]) ;
end;
ShellExecute(
Application.Handle,
PChar(printCommand),
PChar(documentToPrint),
PChar(printerInfo),
nil,
SW_HIDE
);
end;
Note
To use this code you'll need an application registered for each file type you want to print.
- Print any type of document using Delphi
- Delphi 2009 Delphi 2007 (any old version) is STRING type:
- The first experience of any type of regression
- variable-size type declared outside of any function错误说明
- Changing the Title of a Print Dialog in Delphi
- SAP print Document
- To find sum of two numbers without using any operator. Only use of printf() is allowed.
- [zz]Determine the maximum of two integers using macro without any operators.
- 【问题】Cannot find any information on property 'userPhone' in a bean of type 'Bean'.
- Top 20 Online Tools Useful For Any Type of Web Developer
- Cannot find any information on property 'User' in a bean of type 'com.entity.user'
- could not load any Objective-C class information. This will significantly reduce the quality of type
- Cannot find any information on property 'S' in a bean of type 'beans.Circle'
- Cannot find any information on property 'S' in a bean of type 'beans.Circle'
- 异常处理_Cannot find any information on property 'XXX' in a bean of type 'XXX'
- Cannot find any information on property [datetime] in a bean of type
- FI—Document—Print
- Write a method to print the last K lines of an input file using C++
- WPF and Silverlight 学习笔记(十五):WPF命令(Commands)
- How to use a TControlCanvas in a component
- 国内CAD二次开发关注度比较
- OLAP 函数 建议大家看看,还是不错的!
- 一个弹出层
- Print any type of document using Delphi
- 使用LAG和LEAD函数统计
- brook+编程之GPU加速到底多快?
- 3G业务成功的基本法则(摘要)
- zend studio 打开TPL文件显示语法高亮
- 下面我使用vector容器为基础来构成一棵树
- 《JS语法字典》
- JAVA批量操作数据库
- 从“不敢涉入”到“乐在其中”