Add PDF Export
|Top Previous Next|
Using our Product wPDF it is very easy to implement PDF export from the WPTools editor.
wPDF is not installed as separate product when used together with WPTools but linked with the WPTools ∞ design package.
wPDF can also be used independently, in contrast to many competing products it is a EMF to PDF converter and is as such compatible to most drawing code, wether it uses a TCanvas or HDC handle.
Instead please open the file WPINC.INC and activate the $define WPPDFEX
then do a "Build All" with the wptools package. Of course the library path must also list the wPDF directory.
To bring life to the PDF export button implemented by the TWPToolbar simply drop a component of the type TWPCreatePDFDlg on the form, link it with the WPDialogCollection (property SaveAsPDF) and, if the WPDialogCollection had been already linked to the TWPRichText the toolbutton will show the PDF export dialog.
Alternativly it is also possible to create the PDF export dialog in code and use the toolbar event to launch it:
uses ... WPToPDFDlg ...
procedure TForm1.WPToolbar1IconSelection(Sender: TObject;
var Typ: TWpSelNr; const str: String; const group, num, index: Integer);
var dlg : TWPCreatePDFDlg;
if (typ=wptIconSel) and (group=WPI_GR_PRINT) then
if num=WPI_CO_PDFExportDialog then
dlg := TWPCreatePDFDlg.Create(Self);
dlg.Filename := WPRichText1.LastFileName;
dlg.EditBox := WPRichText1;
In case You do not want to use the dialog, you can export from a TWPRichText directly by dropping the TWPPDFExport component. Assign the WPRichText using the property Source and set the filename. Call Export to create the PDF.
If you use Export right after a LoadFromStreanm or LoadFromFile you need to call WPRichText.ReformatAll(false, false) to format the text. Otherwise the WPRichText will format the text, when the application is idle.
Of course it also makes sense to do this fully in code, especially when the export is not done on a form or the TWPRichText has been created dynamically:
uses ..., WPPDFWP, WPRTEDefs, WPCTRMemo, WPCTRRich;
procedure TForm1.ExportFromWPTools(Sender: TObject);
var pdf : TWPPDFExport;
pdf := TWPPDFExport.Create(nil);
pdf.Source := WPRichText1;
pdf.FileName := 'c:\temp\wpout.pdf';