近日單位須要用到會議通知單的打印功能,故引出篇。web
unigui是delphi環境下快速開發web應用的優秀工具,再也不贅述,下面直接記錄使用搭配使用,基本邏輯就是:瀏覽器
unigui實現數據錄入和瀏覽的web頁---->點擊打印按鈕時使用【frxPDFExport】動態將報表導出爲pdf------>將pdf文件動態載入打印預覽窗口(UniURLFrame)實現打印預覽功能。工具
具體實現:ui
1,用unigui控件實現數據的「增改刪」,以下圖:url
2,unigui實現預覽窗口,以下圖,須要引入frxReport、frxPDFExport和frxRichObject組件:spa
3,雙擊frxReport設計好會議通知單模板,且將文件另存到unigui發佈目錄的files文件夾下,文件名爲」會議通知單模板.fr3「,以下圖:設計
4,點擊【打印會議通知單】按鈕實現以下代碼(利用frxReport打開已設計好的會議通知單模板.fr3,經過frxPDFExport將frxReport的報表導出爲pdf文件):code
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;
完成上述幾步,就能看到成果了:orm
BTW,unigui配合Chrome瀏覽器效果最佳,與舊版IE的兼容性不太好。blog
QQ:508882988。