Flying网络打印(WEB)
# FastWeb之Flying网络打印
- 适用平台:WEB(桌面)
# 1. 说明
本范例采用HTTP通讯协议,连接打印服务器进行打印操作。该范例需配合爱招飞旗下的Flying(飞印,局域网数据报表打印工具)使用。
请注意,该范例仅在输出文件类型为pdf时可在打印预览界面查看输出的文档,其他输出的文件类型无法预览查看。
FastWeb中暂不支持MQTT通讯协议的打印模式。
在使用该范例前,请按照Flying操作手册之快速上手中的内容建立报表打印格式。
通过本范例学习,可以掌握TUgFlying控件的使用方式。
# 2. 设计明细
开启FastWeb设计器,分别加入下插图之控件。或者点击左上角的[导入]
选择模板文件来打开对应模板。

①:TUgEdit组件,控件名称为UgEdit01
。
②:TUgSpinEdit组件,控件名称为UgSpinEdit01
。
③:TUgButton组件,控件名称为UgButton01
。
④:TUgRFDataSet组件,控件名称为UgRFDataSet01
。
⑤:TUgFlying组件,控件名称为UgFlying01
。
⑥:TUgComboBox组件,控件名称为UgComboBox02
。
⑦:TUgSpinEdit组件,控件名称为UgSpinEdit02
。
⑧:TUgFSToggle组件,控件名称为UgFSToggle01
。
⑨:TUgButton组件,控件名称为UgButton02
。
⑩:TUgPDFFrame组件,控件名称为UgPDFFrame01
。
UgWebRunFrame属性设置
Height
:设置页面高度=767
。Width
:设置页面宽度=954
。
UgPanel01属性
Anchors
:设定控件定位锚。将其中的所有选项akLeft
、akTop
、akRight
、akBottom
均设置为True
。
①UgEdit01属性设置
FieldLabel
:设置标签显示的文本=服务器地址
。FieldLabelWidth
:设置标签显示文本的宽度=80
。Text
:设置标签显示的文本。此处需设置为服务器所在的地址。
②UgSpinEdit01属性设置
FieldLabel
:设置标签显示的文本=端口号
。FieldLabelWidth
:设置标签显示文本的宽度=80
。Value
:设置编辑框中显示的数值,设置为8801
,该端口号为Flying的HTTP打印默认地址。
③UgButton01属性设置
Caption
:设置按钮显示的文本内容,设置为获取打印机列表
。
④UgRFDataSet01属性设置
SQL
:设置其中填写的SQL查询内容,设置为SELECT * FROM Basic_Unit
。
⑤UgFlying01属性设置
ReportName
:设置打印格式的名称,此处设置为test.fr3
。
⑥UgComboBox02属性设置
FieldLabel
:设置标签显示的文本=打印机
。FieldLabelWidth
:设置标签显示文本的宽度=80
。
⑦UgSpinEdit02属性设置
FieldLabel
:设置标签显示的文本=打印份数
。FieldLabelWidth
:设置标签显示文本的宽度=80
。Value
:设置编辑框中显示的数值,设置为1
,设置默认打印的份数。
⑧UgFSToggle01属性设置
Toggled
:设置开关是否处于开启状态,设置为True
。
⑨UgButton02属性设置
Caption
:设置按钮显示的文本内容,设置为执行打印
。
⑩UgPDFFrame01属性设置
Align
:设置控件的对齐方式,设置为alClient
,即客户区对齐。
# 3. 程序设计
点击程序设计界面右下角的按钮,切换至单元选择界面,勾选需要使用的单元。该程式的程序需要引用TARSLink
单元。
# 3.1. 程序初始设置
在程序启动时进行初始赋值。
//JScript
{
UgEdit01.OnChange = &UgEdit01OnChange;
UgSpinEdit01.OnChange = &UgSpinEdit01OnChange;
UgSpinEdit02.OnChange = &UgSpinEdit02OnChange;
UgButton01.OnClick = &UgButton01OnClick;
UgButton02.OnClick = &UgButton02OnClick;
UgFlying01.OnReceived = &UgFlying01OnReceived;
}
function UgWebRunFrameOnAfterRunScript(sender)
{
UGMM.LC(Self);
UgFlying01.HTTPOptions.Host = UgEdit01.Text;
UgFlying01.HTTPOptions.Port = UgSpinEdit01.Value;
UgFlying01.MQTTOptions.BrokerHost = UgEdit01.Text;
UgFlying01.PrintOptions.PrintCopies = UgSpinEdit02.Value;
UgFDQuery01.Connection = UGMM.GetNodeDataLink("demo");
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//PasScript
procedure UgWebRunFrameOnAfterRunScript(const sender: tobject);
//翻译
begin
UGMM.LC(Self);
UgFlying01.HTTPOptions.Host := UgEdit01.Text;
UgFlying01.HTTPOptions.Port := UgSpinEdit01.Value;
UgFlying01.MQTTOptions.BrokerHost := UgEdit01.Text;
UgFlying01.PrintOptions.PrintCopies := UgSpinEdit02.Value;
UgFDQuery01.Connection := UGMM.GetNodeDataLink("demo");
end;
2
3
4
5
6
7
8
9
10
11
// Make sure to add code blocks to your code group
# 3.2. 事件设置
- ①UgEidt01-OnChange事件
填写服务器地址,该地址会回传给UgFlying01
控件。
//JScript
function UgEdit01OnChange(sender){
//修改打印服务器地址。
UgFlying01.HTTPOptions.Host = UgEdit01.Text;
UgFlying01.MQTTOptions.BrokerHost = UgEdit01.Text;
UgFlying01.WebSocketOptions.Host = UgEdit01.Text;
}
2
3
4
5
6
7
//PasScript
procedure UgEdit01OnChange(sender: tobject);
//修改打印服务器地址。
begin
UgFlying01.HTTPOptions.Host := UgEdit01.Text;
UgFlying01.MQTTOptions.BrokerHost := UgEdit01.Text;
UgFlying01.WebSocketOptions.Host := UgEdit01.Text;
end;
2
3
4
5
6
7
8
// Make sure to add code blocks to your code group
- ②UgSpinEdit01-OnChange事件
修改服务器端口号。
//JScript
function UgSpinEdit01OnChange(sender){
//修改服务器端口号
UgFlying01.HTTPOptions.Port = UgSpinEdit01.Value;
UgFlying01.WebSocketOptions.Port = UgSpinEdit01.Value;
}
2
3
4
5
6
//PasScript
procedure UgSpinEdit01OnChange(sender: tobject);
//修改服务器端口号
begin
UgFlying01.HTTPOptions.Port := UgSpinEdit01.Value;
UgFlying01.WebSocketOptions.Port := UgSpinEdit01.Value;
end;
2
3
4
5
6
7
// Make sure to add code blocks to your code group
- ⑦UgSpinEdit02-OnChange事件
修改打印份数。
//JScript
function UgSpinEdit02OnChange(sender){
//修改打印份数
UgFlying01.PrintOptions.PrintCopies = UgSpinEdit02.Value;
}
2
3
4
5
//PasScript
procedure UgSpinEdit02OnChange(sender: tobject);
//修改打印份数
begin
UgFlying01.PrintOptions.PrintCopies := UgSpinEdit02.Value;
end;
2
3
4
5
6
// Make sure to add code blocks to your code group
- ③UgButton01-OnClick事件
点击[获取打印机列表]
,获取打印机设备并显示在选择框中。
//JScript
function UgButton01OnClick(sender){
//加载打印机列表
UgFlying01.GetPrinterList;
}
2
3
4
5
//PasScript
procedure UgButton01OnClick(sender: tobject);
//加载打印机列表
begin
UgFlying01.GetPrinterList;
end;
2
3
4
5
6
// Make sure to add code blocks to your code group
- ④UgButton02-OnClick事件
点击[执行打印]
按钮,将执行打印操作。
//JScript
function UgButton02OnClick(sender){
if (demo) {return;}
if (UgComboBox02.Items.Text == "") {return;}
UgFlying01.PrintOptions.PrinterName = UgComboBox02.Items.Strings[UgComboBox02.ItemIndex];
UgFDQuery01.SQL.Text = "SELECT * FROM Basic_Unit";
UgFDQuery01.Open;
UgFlying01.AddPrintData(TDataSet(UgFDQuery01),"A");
UgFlying01.ReportPrint;
}
2
3
4
5
6
7
8
9
10
//PasScript
procedure UgButton02OnClick(sender: tobject);
//点击图片传输打印
begin
if demo then exit;
if UgComboBox02.Items.Text := '' then exit;
UgFlying01.PrintOptions.PrinterName := UgComboBox02.Items.Strings[UgComboBox02.ItemIndex];
UgRFDataSet01.SQL.Text := 'SELECT * FROM Basic_Unit';
UgRFDataSet01.Open;
UgFlying01.AddPrintData(UgRFDataSet01,'A');
UgFlying01.Data.Text := DataToJson(UgRFDataSet01,'A');
UgFlying01.ReportPrint;
end;
2
3
4
5
6
7
8
9
10
11
12
13
// Make sure to add code blocks to your code group
- ⑤UgFlying01-OnReceived事件
接收相关的打印事件。
//JScript
function UgFlying01OnReceived(asender,atype,acontent){
var Guid = UGMM.CreateGuid;
if (atype == "GetPrinterList"){
UgComboBox02.Items.CommaText = acontent;
if (UgComboBox02.ItemIndex != 0){
UgComboBox02.ItemIndex = 0;
}
}
if (atype == "GetReportFile"){
if (UgFSToggle01.Toggled){
if (UGMM.URLDownloadToFile(acontent,"temp\\" + Guid + "-report.pdf") <= 1){
UgPDFFrame01.PdfURL = "temp/" + Guid + "-report.pdf";
}
}
}
if (atype == "error"){
Showmessage(acontent);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//PasScript
procedure UgFlying01OnReceived(asender: tobject;atype: string;acontent: string);
//获取接受的信息
var
Guid:String;
begin
Guid := UGMM.CreateGuid;
if atype = 'GetPrinterList' Then
begin
UgComboBox02.Items.CommaText := acontent;
if UgComboBox02.ItemIndex <> 0 Then
UgComboBox02.ItemIndex := 0;
End;
if AType='GetReportFile' then
Begin
if UgFSToggle01.Toggled Then
Begin
if UGMM.URLDownloadToFile(acontent,'temp\' + Guid + 'report.pdf') <= 1 then
begin
UgPDFFrame01.PdfURL := 'temp/' + Guid + '-report.pdf';
End;
End;
End;
if AType='error' then
Showmessage(AContent);
end;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Make sure to add code blocks to your code group
# 4. 运行结果
使用鼠标在FastWeb菜单,点击[保存至数据库]
按钮,将其保存至数据库,点击[调试运行]
确认能够正常打开。

在打开的程序中填写服务器地址,确认端口号无误后,点击[获取打印机列表]
,下方的打印机选框中出现可选择的打印机列表,点击右侧的下拉按钮下拉选择所需的打印机。点击[执行打印]
按钮,右侧的打印预览界面显示输出的PDF文件的预览界面。