Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Pdf.Canvas

Classes, interfaces and records

classePdfCanvas

inherits from Exception

The composer's own failure class. It descends from Exception directly, like ePdfError in StreamSec.Pdf.Model and ePdfSignError in StreamSec.Pdf.Signer: this unit is the DEEPEST of the three - stDERUtils and nothing else - so it cannot reach either of theirs without acquiring the dependency the unit exists to avoid. Nothing here raises a bare Exception.

(no public members)

classtPdfCanvas

constructor Create; overload; constructor Create(aWidth, aHeight: Double); overload;
A4 is what Create alone gives; this is the same thing with the size stated. Refuses a side outside cPdfMinSide .. cPdfMaxSide.
destructor Destroy; override; procedure SetPageSize(aWidth, aHeight: Double);
THE PAGE SIZE, AND WHY IT CAN ONLY BE SET BEFORE ANYTHING IS DRAWN. TextOut and HLine convert the caller's top-left y into PDF's bottom-up frame with fHeight at the moment of the call, and SaveToOS writes ONE MediaBox for every page in the file. Full description »
procedure NewPage;
Finishes the current page and starts the next. The first page exists from Create; an empty last page is not emitted.
property Unrenderable: tPdfUnrenderable read fUnrenderable write fUnrenderable;
Can every character of aText be carried by WinAnsiEncoding? When not, aBadAt is the 1-based index into aText of the first that cannot and aCodePoint is its Unicode scalar value (a surrogate pair is reported as the one code point it encodes, and its index is that of the high surrogate). Full description »
property Substitutions: Integer read fSubstitutions;
How many characters this canvas has substituted since it was created. Zero on a puRefuse canvas by construction - it would have raised.
function CanRender(const aText: string; out aBadAt: Integer; out aCodePoint: Cardinal): Boolean; procedure TextOut(aX, aY: Double; aFont: tPdfFont; aSize: Double; const aText: string; aAlign: tPdfAlign = paLeft; aLetterSpace: Double = 0);
Places aText with its LEFT/RIGHT/CENTER reference at aX, its BASELINE aY points below the top edge. aLetterSpace is PDF character spacing in points - the header logotype uses it, nothing else should.
function TextWidth(aFont: tPdfFont; aSize: Double; const aText: string; aLetterSpace: Double = 0): Double;
The rendered width of aText - the measurement TextOut aligns with.
function FitText(aFont: tPdfFont; aSize: Double; const aText: string; aMaxWidth: Double; out aRest: string): string;
Cuts aText so it fits aMaxWidth, breaking at a space where one exists. Returns the part that fits; aRest is the remainder ('' when it all fit). The item table wraps long specification lines with this.
procedure HLine(aX1, aX2, aY: Double; aThickness: Double = 0.75);
A horizontal rule from aX1 to aX2 at depth aY, aThickness points.
function SaveToOS: OctetString;
The finished file - header, objects, xref, trailer.
procedure SaveToFile(const aFileName: string); property PageWidth: Double read fWidth;
Read-only on purpose - SetPageSize is the one door, so the refusal cannot be walked around by setting one side at a time.
property PageHeight: Double read fHeight;

Types (enumerations, sets, aliases)

enumtPdfUnrenderable

WHAT TO DO WITH A CHARACTER WinAnsiEncoding CANNOT CARRY.
puRefuse is the default and the right answer for a document that will be signed, filed and read back in seven years: a '?' standing where a customer's name should be is a defect, and one that no longer announces itself once the file is closed.
puSubstitute exists because that is not every caller's trade-off. A webshop generating an invoice automatically the moment a payment is captured cannot stop and ask a human, and for it a document with a mangled name beats no document at all - the invoice still has to exist. The choice is therefore PER INSTANCE and not per unit, because both callers are right about their own case. SUBSTITUTION IS NEVER SILENT. The original objection to '?' was not the character, it was that nothing recorded the loss. So a canvas in
puSubstitute counts every substituted character in Substitutions, and a caller that opts in is expected to look at it - log it, flag the document, or warn the operator. A count nobody reads is the defect the strict mode exists to prevent, merely relocated.

  tPdfUnrenderable = (puRefuse, puSubstitute);

enumtPdfFont

  tPdfFont = (pfHelvetica, pfHelveticaBold, pfHelveticaOblique);

enumtPdfAlign

  tPdfAlign = (paLeft, paRight, paCenter);