近日单位需要用到会议通知单的打印功能,故引出篇。
unigui是delphi环境下快速开发web应用的优秀工具,不再赘述,下面直接记录使用搭配使用,基本逻辑就是:
unigui实现数据录入和浏览的web页---->点击打印按钮时使用【frxPDFExport】动态将报表导出为pdf------>将pdf文件动态载入打印预览窗口(UniURLFrame)实现打印预览功能。
具体实现:
1,用unigui控件实现数据的“增改删”,如下图:
2,unigui实现预览窗口,如下图,需要引入frxReport、frxPDFExport和frxRichObject组件:
3,双击frxReport设计好会议通知单模板,且将文件另存到unigui发布目录的files文件夹下,文件名为”会议通知单模板.fr3“,如下图:
4,点击【打印会议通知单】按钮实现如下代码(利用frxReport打开已设计好的会议通知单模板.fr3,通过frxPDFExport将frxReport的报表导出为pdf文件):
procedure TfrmMeetingInf.btnPrintClick(Sender: TObject); begin with frmMeetingInfPrint do begin try sTitle := memTitle.Lines.Text; sTime := edTime.Text; sPsn := edPsn.Text; sAddress := memAddress.Lines.Text; ShowModal(nil); finally end; end; end;
procedure TfrmMeetingInfPrint.UniFormBeforeShow(Sender: TObject); var rptFileName,url: string; begin rptFileName := '会议通知单.fr3'; frxReport1.Clear(); try frxReport1.LoadFromFile(UniServerModule.FilesFolderPath+rptFileName); //存放在files目录下面 frxReport1.PrintOptions.ShowDialog := false; frxReport1.ShowProgress := false; frxReport1.EngineOptions.SilentMode := true; frxReport1.EngineOptions.EnableThreadSafe := true; frxReport1.EngineOptions.DestroyForms := false; frxReport1.EngineOptions.UseGlobalDataSetList := false; frxPDFExport1.Background:=true; frxPDFExport1.ShowProgress:=False; frxPDFExport1.ShowDialog:=false; frxPDFExport1.FileName:=UniServerModule.NewCacheFileUrl(False,'pdf','','',url,true); frxPDFExport1.DefaultPath := ''; frxReport1.PreviewOptions.AllowEdit := false; frxReport1.PrepareReport(); frxReport1.Export(frxPDFExport1); UniURLFrame1.URL := url; finally end; end;
procedure TfrmMeetingInfPrint.frxReport1BeforePrint( Sender: TfrxReportComponent); begin if (Sender is TfrxMemoView) then begin if ((Sender as TfrxMemoView).Name = 'memTitle') then begin (Sender as TfrxMemoView).Memo.Text := sTitle; end; if ((Sender as TfrxMemoView).Name = 'memPsn') then begin (Sender as TfrxMemoView).Memo.Text := sPsn; end; if ((Sender as TfrxMemoView).Name = 'memTime') then begin (Sender as TfrxMemoView).Memo.Text := sTime; end; if ((Sender as TfrxMemoView).Name = 'memAddress') then begin (Sender as TfrxMemoView).Memo.Text := sAddress; end; end; end;
完成上述几步,就能看到成果了:
BTW,unigui配合Chrome浏览器效果最佳,与旧版IE的兼容性不太好。
QQ:508882988。