可視化報告生成器FastReport VCL功能指南:從Delphi / C ++ Builder / Lazarus制作PDF
報表生成器FastReport VCL是用于在您的軟件中集成商務智能的現代解決方案。它提供了可視化模板設計器,可以訪問最受歡迎的數據源,報告引擎,預覽,將過濾器導出為30多種格式,并可以部署到云,Web,電子郵件和打印中。
近日,FastReport VCL升級到v6.6版,在此版本中,所有面板隱藏在“Data Tree”數據樹,添加了新的線性條形碼類型:Pharmacode,改進了預覽窗口中的搜索,感興趣的朋友可點擊下方按鈕下載最新版。
通常建議使用專門的解決方案,PDF轉換器(例如itext,Synopse PDF Engine,PowerPDF,HotPDF,PDF Creator Pilot,PDFtoolkit VCL,Debenu Quick PDF庫等)。
在Delphi中創建一個新的VCL應用程序
將FastReport選項卡中的TfrxReport,TfrxPDFExport和TButton組件添加到窗體。

雙擊TfrxReport,輸入FR設計器。創建一個新報告(文件->新建報告)。將TfrxMemoView和文本“ Test text”添加到MasterData1。

設置MasterData1.RowCount = 200,退出設計器并為Button1編寫OnClick處理程序:
procedure TForm1.Button1Click(Sender: TObject); begin {Generate a report. The report must be generated before exporting} if frxReport1.PrepareReport then frxReport1.ShowPreparedReport; {and show preview window} end;
實際上,此代碼足以進行全面的工作,生成報告并導出為PDF。現在,在設計時創建一個任何復雜的文檔(您可以連接任何數據源并從那里獲取信息)–表格,列表,插圖,地圖,QR碼–為此,請確保首先將適當的組件添加到項目中(否則它們將在運行時中不存在),帶有錨點,內聯鏈接和目錄的復合和多頁文檔-您需要的任何大小的文檔-一頁收據,一頁目錄,年度報告工廠員工動靜數千頁。并且不要忘記將PDF導出組件放到我們的項目中!啟動并單擊表單上的唯一按鈕。

從Delphi應用程序中保存PDF
點擊按鈕–在下面的預覽中調用導出,將展示如何通過代碼執行所有操作,只需點擊鏈接即可– 從代碼發送到PDF)。隨即,我們看到出現的PDF設置對話框。

如您所見,任何專業的PDF轉換器都會羨慕這種選擇!我們可以選擇將文檔的哪些頁面發送到PDF,使用哪個版本的PDF,壓縮可以減少生成的文件的大小,嵌入字體可以保存任何第三方設備的文檔外觀。我們可以選擇是否將背景附加到PDF文檔。
我們的PDF也可以針對打印進行優化(圖像質量會更好,但是尺寸會更大)或僅針對屏幕顯示。我們可以設置生成的PDF是否將包含原始目錄中的外部目錄(在我的示例中沒有,因此無法選擇),透明度,位圖圖像的壓縮率。
另一個功能–所有文本(包括RTF)在保存為PDF時都會進行矢量化處理,即在保留從PDF復制一部分文本的能力的同時,質量不會喪失(除非您禁止在下面提到的適當選項)。

保存到:我們將確切發送PDF(本地文件或電子郵件或云)的位置。導出后打開-默認情況下,分配給操作系統的PDF查看器將在導出后立即打開結果文件(例如,Adobe Acrobat Reader)。
我們可以將生成的文檔導出為存檔格式,例如PDF / A-1a,PDF / A-1b,PDF / A-2a,PDF / A-2b,PDF / A-3a,PDF / A-3b。設計用于以電子形式保持文檔不變。例如,在此標準中,文檔中存在的字體,圖像,第三方對象會自動嵌入到文檔中。這些標準之一經常在大型組織中用于電子文檔管理。

非存檔PDF格式也有多個版本。

服務信息,也將轉至PDF文件:標題,作者,主題,關鍵字(您可以將PDF上傳到網絡,它將被完美索引),PDF創作工具,文檔制作者。

安全性–使用密碼(使用RC4加密)保護文檔免于打開。禁止打印和修改文檔,復制文本和圖形,添加或修改文本注釋的功能。

打開文檔時設置PDF查看器:隱藏工具欄,隱藏菜單欄,隱藏窗口用戶界面,適合窗口,中心窗口,打印比例。通常,在導出時,我使用默認設置的參數,但是這次我檢查了所有參數。
從Delphi或Lazarus代碼發送到PDF
procedure TForm1.Button1Click(Sender: TObject); begin {Generate a report. The report must be generated before exporting} frxReport1.PrepareReport(); {Set the range of pages to export. By default, all pages of the generated report are exported.} frxPDFExport1.PageNumbers := '2-3'; {Set the PDF standard TPDFStandard = (psNone, psPDFA_1a, psPDFA_1b, psPDFA_2a, psPDFA_2b, psPDFA_3a, psPDFA_3b); It is required to add the frxExportPDFHelpers module to the uses list: uses frxExportPDFHelpers;} frxPDFExport1.PDFStandard := psNone; {You can set the PDF standard version for PDFStandard = psNone TPDFVersion = (pv14, pv15, pv16, pv17); It is required to add the frxExportPDFHelpers module to the uses list: uses frxExportPDFHelpers;} frxPDFExport1.PDFVersion := pv17; {To get smaller file size, you can set the compression} frxPDFExport1.Compressed := True; {Set whether to embed fonts in the resulting document. Embedding fonts significantly increases the size of the resulting document} frxPDFExport1.EmbeddedFonts := False; {Set whether we need to export the background image} frxPDFExport1.Background := True; {Disable export of objects with optimization for printing. With option enabled images will be high-quality but 9 times larger in volume} frxPDFExport1.PrintOptimized := False; {Set whether the resulting PDF will contain an external table of contents, as in the original report} frxPDFExport1.Outline := False; {Set whether to export images with transparency} frxPDFExport1.Transparency := True; {You can set the desired DPI of images. Enabling this option disables SaveOriginalImages option, which allows you to save images in their original form} frxPDFExport1.PictureDPI := 150; {Set the compression ratio of bitmap images} frxPDFExport1.Quality := 95; {Set whether to open the resulting file after export} frxPDFExport1.OpenAfterExport := False; {Set whether to display export progress (show which page is currently being exported)} frxPDFExport1.ShowProgress := False; {Set whether to display a dialog box with export filter settings} frxPDFExport1.ShowDialog := False; {Set the name of the resulting file. Please note that if you do not set the file name and disable the export filter dialog box, the file name selection dialog will still be displayed} frxPDFExport1.FileName := 'C:\Output\test.pdf'; {Fill in the corresponding fields of the Information tab} frxPDFExport1.Title := 'Your Title'; frxPDFExport1.Author := 'Your Name'; frxPDFExport1.Subject := 'Your Subject'; frxPDFExport1.Keywords := 'Your Keywords'; frxPDFExport1.Creator := 'Creator Name'; frxPDFExport1.Producer := 'Producer Name'; { Fill in the corresponding fields of the Security tab } frxPDFExport1.UserPassword := 'User Password'; frxPDFExport1.OwnerPassword := 'Owner Password'; frxPDFExport1.ProtectionFlags := [ePrint, eModify, eCopy, eAnnot]; {Set the Viewer settings (Viewer tab)} frxPDFExport1.HideToolbar := False; frxPDFExport1.HideMenubar := False; frxPDFExport1.HideWindowUI := False; frxPDFExport1.FitWindow := False; frxPDFExport1.CenterWindow := False; frxPDFExport1.PrintScaling := False; {Export the report} frxReport1.Export(frxPDFExport1); end;
還想要更多嗎?您可以點擊閱讀【FastReport 報表2019最新資源盤點】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入FastReport技術交流群(783996712),我們很高興為您提供查詢和咨詢。