Create fields |
Top Previous Next |
wPDF uses GDI comments to store the commands to create fields. This makes it possible to create fields in source code which does not use a reference to the wPDF VCL.
You only would need to copy this code and adapt the class name "TDrawClass":
type TWPEditControlPDFOne = (wpecAutosizeFont, wpecAlignRight, wpecAlignCenter, wpecDrawBorder, wpecMultiLine); TWPEditControl = set of TWPEditControlPDFOne; TWPEditControlFont = ( wpecHelvetica, wpecTimes, wpecCourier, wpecZapfDingbats );
procedure TDrawClass.WriteGDICommentStr(Comm: Integer; const r: TRect; text: AnsiString); type PWPComRec = ^TWPComRec; TWPComRec = packed record a: Integer; b: Integer; c: TRect; d: Integer; end; var p: PWPComRec; pp: PAnsiChar; begin GetMem(p, SizeOf(TWPComRec) + Length(text)); try FillChar(p^, SizeOf(TWPComRec) + Length(text), 0); p^.b := 120269; p^.a := comm; p^.c := r; if text <> '' then begin pp := PAnsiChar(p); inc(pp, SizeOf(TWPComRec)); Move(text[1], pp^, Length(text)); p^.d := Length(text); end; GdiComment(Canvas.Handle, SizeOf(TWPComRec) + Length(text), PAnsiChar(p)); finally FreeMem(p); end; end;
procedure TDrawClass.DrawTextField( Text : String; R : TRect; FieldName : String {$IFNDEF D3}= ''{$ENDIF}; Hint : string {$IFNDEF D3}= ''{$ENDIF}; FontSize : Integer {$IFNDEF D3}= 0{$ENDIF}; Options : TWPEditControl {$IFNDEF D3}= [wpecAutosizeFont]{$ENDIF} ; Font : TWPEditControlFont {$IFNDEF D3}= wpecHelvetica{$ENDIF} ); var h : string; const PDFFonts : array[TWPEditControlFont] of String = ('Helv', 'Times', 'Cour', 'ZaDb'); begin FieldName := Trim(FieldName); if FieldName='' then begin inc(FFieldNr); FieldName := 'FIELD' + IntToStr(FFieldNr); end; // Reset Parameters WriteGDICommentStr( 518, Rect(0,0,0,0), 'RESET=1'); //WPDFCOMM_TEXTFIELD_PARAM // Write Parameters if Font>wpecHelvetica then WriteGDICommentStr( 516, Rect(0,0,0,0), PDFFonts[Font]); //WPDFCOMM_TEXTFIELD_FONT if wpecAlignRight in Options then WriteGDICommentStr( 517, Rect(0,0,0,0), '2') //WPDFCOMM_TEXTFIELD_ALIGN else if wpecAlignCenter in Options then WriteGDICommentStr( 517, Rect(0,0,0,0), '1');
if wpecDrawBorder in Options then WriteGDICommentStr( 518, Rect(0,0,0,0), 'BORDER=1'); //WPDFCOMM_TEXTFIELD_PARAM
if wpecMultiLine in Options then WriteGDICommentStr( 518, Rect(0,0,0,0), 'MULTI=1'); //WPDFCOMM_TEXTFIELD_PARAM
if not (wpecAutosizeFont in Options) then begin if FontSize>0 then WriteGDICommentStr( 518, Rect(0,0,0,0), 'SIZE=' + IntToStr(FontSize)) //WPDFCOMM_TEXTFIELD_PARAM else WriteGDICommentStr( 518, Rect(0,0,0,0), 'SIZE=' + IntToStr(MulDiv((R.Bottom-R.Top),5,6))) end;
// Create Field if Hint = '' then h := '' else h := '@@HINT@@' + Hint; WriteGDICommentStr( 519, R, '@' + FieldName + '=' + Text+ h);
end;
procedure TDrawClass.DrawCheckbox( R : TRect; Value : Boolean; FieldName : String {$IFNDEF D3}= ''{$ENDIF}; Hint : String {$IFNDEF D3}= ''{$ENDIF} ); begin WriteGDICommentStr( 515, R, FieldName + '=' + IntToStr(Ord(Value)) + '@@HINT@@' + Hint); end; |