FWPdf

Source: source/classes/fwpdf.prg

Inherits from: TPdf

FWPdf is an enhanced PDF generation class that extends TPdf with additional features such as Unicode support, RTF text rendering, pie charts, gradient fills, barcodes, image printing, hyperlinks, and multi-unit coordinate support (points, inches, centimeters, millimeters). It provides a complete high-level API for creating professional PDF documents.

Key DATA Members

DATATypeDescription
lUnicodeLogicalEnable UTF-8 encoding for PDF text
hTrueTypeHashCache of loaded TrueType fonts (face name to handle)
aPhySizeArrayPhysical page dimensions in mm: { nWidth, nHeight }
cAuthorCharacterPDF document author metadata
cCreatorCharacterPDF document creator metadata
cTitleCharacterPDF document title metadata
cSubjectCharacterPDF document subject metadata
lTimeStampLogicalInclude creation date timestamp (default .T.)
oFontObjectDefault font object (Courier 10)
oPrnTPrinterOptional printer device for coordinate translation
bPreviewBlockCode block to open PDF after save (default: ShellExecute)
nOrientNumeric1 = Portrait, 2 = Landscape

Methods

MethodDescription
New( cFileName, cPassword, cOwnerPassword, nPermission, lPreview )Create enhanced PDF document with Unicode support
Save( cFileName )Save PDF with metadata, permissions, and time stamp
StartPage()Start a new page with automatic size sync
SetPage( nPageSize )Set page size with physical dimensions
GetPhySize( cUnits )Get page dimensions in PIX, IN, CM, or MM
DefineFont( cFaceName, nSize, lEmbed, lBold, lItalic, nEsc )Define a font with bold/italic/escapement support
LoadTrueType( cFaceName, lBold, lItalic, lEmbed )Explicitly load a TrueType font
Say( nRow, nCol, cText, oFont, nWidth, nClrText, nBkMode, nPad, cUnits )Draw text with unit support
SayRTF( nRow, nCol, cText, nWidth, nHeight, cUnits )Render rich text (RTF) content
SayText( nRow, nCol, cText, nWidth, nHeight, oFont, cAlign, nClrText, nClrBack, cUnits, nClrPen, nPenSize )Draw formatted text in a bounding box with alignment
Line( nTop, nLeft, nBottom, nRight, oPen, cUnits )Draw a line with unit support
Rect( nTop, nLeft, nBottom, nRight, oPen, oBrush, aText, cUnits )Draw rectangle with optional brush fill and text
RoundBox( nTop, nLeft, nBottom, nRight, nWidth, nHeight, oPen, oBrush, aText, cUnits )Draw rounded rectangle with fill
Ellipse( nTop, nLeft, nBottom, nRight, nClrBorder, oBrush, aText, cUnits )Draw an ellipse or circle
GradientFill( aRect, aGrad, lVert, cUnits )Fill a region with gradient colors
PieChart( aRect, aValues, aColors, aPen, nStartAngle, nInnerDia, aLabels, oFont, cUnits )Draw a pie/donut chart with labels
PrintImage( nRow, nCol, uImage, nWidth, nHeight, lStretch, nAlpha, lTransp, lGray, cUnits, cAlign, cURL )Print an image with alpha, transparency, grayscale, and optional hyperlink
PrintBarcode( cText, nRow, nCol, nWidth, nHeight, cUnits, cType, nClrText, nClrBack, lVertical, lTransparent )Print a barcode on the PDF
PrintGraph( nRow, nCol, oGraph, nWidth, nHeight, cUnits )Print a TGraph chart object
PrintChart( nRow, nCol, oTable, nWidth, nHeight, cType, aColors, cTitle, cUnits )Print a chart from a TArrayData table
PrintTable( nRow, nCol, oTable, nWidth, nHeight, oFont, lBorder, cTitle, cUnits )Print a data table with optional borders and title
SetLinkToURL( aRect, cURL, cUnits )Add a hyperlink annotation to a rectangle
GetTextWidth( cText, oFont, cUnits )Measure text width in specified units
GetTextHeight( cText, oFont, cUnits )Measure text height in specified units
Units2Pix( ... )Convert from specified units to PDF points
Pix2Units( ... )Convert from PDF points to specified units
End()Close and release the PDF document

Example: Rich PDF with Image, Chart, and Gradient

#include "FiveWin.ch"

function Main()

   local oPdf, oFont

   oPdf := FWPdf():New( "rich_doc.pdf" )
   oPdf:cAuthor  := "FWH User"
   oPdf:cTitle   := "Rich Document"
   oPdf:cSubject := "Demonstrates FWPdf features"

   oPdf:SetPage( HPDF_PAGE_SIZE_A4 )
   oPdf:StartPage()

   oFont := oPdf:DefineFont( "Arial", 16, .T., .T. )

   // Title text
   oPdf:Say( 2, 2, "FWPdf Rich Document", oFont, , , , , "CM" )

   // Gradient fill
   oPdf:GradientFill( { 2, 2, 19, 5 }, { { CLR_HRED, 0.5 }, { CLR_HBLUE, 0.5 } }, .F., "CM" )

   // Draw a line separator
   oPdf:Line( 2, 6, 19, 6, , "CM" )

   // Barcode
   oPdf:PrintBarcode( "FWH-12345", 2, 7, 6, 2, "CM" )

   oPdf:EndPage()
   oPdf:Save()

return nil

Notes

See Also