|
PDF export with wPDF |
Top Previous Next |
|
You can use the provided PDF creation dialog to create a full featured PDF file with our product wPDF.
To display it only these lines are required:
uses WPToPDFDlg;
var pdfcreate: TWPCreatePDF; begin pdfcreate := TWPCreatePDF.Create(Self); pdfcreate.EditBox := WPRichText1; try pdfcreate.ShowModal; finally pdfcreate.Free; end; end;
Alternatively this simple code can be used to export PDF files from WPTools 5.
The drawing code used by WPTools 5 will makes sure that the hyperlinks and bookmarks are exported to PDF as they are with the 'old' WPPDFExport component. Please note that the component WPRichText1 is a TWPRichText component created on the form with the property Visible set to FALSE. All other properties have not been changed.
// uses WPRTEPaint, WPPDFR1, WPPDFR2;
procedure TForm1.ExportToPDF(Sender: TObject); var WPPDFPrinter1: TWPPDFPrinter; i,w,h : Integer; begin WPPDFPrinter1 := TWPPDFPrinter.Create(nil); WPPDFPrinter1.FileName :='c:\wptools5demo.pdf'; WPPDFPrinter1.CompressStreamMethod := wpCompressFastFlate; WPPDFPrinter1.AutoLaunch := TRUE; WPPDFPrinter1.BeginDoc; try i := 0; while i<WPRichText1.CountPages do begin w := WPRichText1.Memo.PaintPageWidth[i]; h := WPRichText1.Memo.PaintPageHeight[i]; WPPDFPrinter1.StartPage( w, h, Screen.PixelsPerInch, Screen.PixelsPerInch, 0); try // Use 0 as w and h to let the function calculate the width and height WPRichText1.Memo.PaintRTFPage(i,0,0,0,0,WPPDFPrinter1.Canvas, [] ); finally WPPDFPrinter1.EndPage; end; inc(i); end; finally WPPDFPrinter1.EndDoc; WPPDFPrinter1.Free; end; end;
To create watermarks simply add additional code which prints on the WPPDFPrinter1.Canvas.
Or you can easily print 2 pages on the same PDF page, just make changes in 4 lines:
var WPPDFPrinter1: TWPPDFPrinter; i, w, h : Integer; begin WPPDFPrinter1 := TWPPDFPrinter.Create(nil); WPPDFPrinter1.FileName :='c:\wptools5demo.pdf'; WPPDFPrinter1.CompressStreamMethod := wpCompressFastFlate; WPPDFPrinter1.AutoLaunch := TRUE; WPPDFPrinter1.BeginDoc; try i := 0; while i<WPRichText1.CountPages do begin h := WPRichText1.Memo.PaintPageHeight[i]; w := WPRichText1.Memo.PaintPageWidth[i]; WPPDFPrinter1.StartPage(w, h div 2, Screen.PixelsPerInch, Screen.PixelsPerInch, 0); try // Use 0 as w and h to let the function calculate the width and height WPRichText1.Memo.PaintRTFPage(i,0,0,w div 2,h div 2,WPPDFPrinter1.Canvas, [] ); WPRichText1.Memo.PaintRTFPage(i+1,w div 2,0,w div 2,h div 2,WPPDFPrinter1.Canvas, [] ); finally WPPDFPrinter1.EndPage; end; inc(i,2); end; finally WPPDFPrinter1.EndDoc; WPPDFPrinter1.Free; end; end;
|