Print Page | Close Window

Formfield-Font

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3312
Printed Date: 17 Jan 26 at 9:24PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Formfield-Font
Posted By: Josef Gschwendtner
Subject: Formfield-Font
Date Posted: 19 Apr 16 at 4:01PM
Hi,
below I inserted some code, showing how we create formfields.
Everything works except the font-setting does not work correct.
Some field have the correct font, some have not.

It would be great if somebody would look over the code (the bold sections) and maybe tell us how to make it betterSmile

Thank you very much,
Josef Gschwendtner


procedure TfmMain.GeneratePDFDocument;
var
  PDF: TDebenuPDFLibrary;
begin
  PDF := TDebenuPDFLibrary.Create;
  UnlockResult := PDF.UnlockKey(cDebenuLicenseKey);
  try
    if (UnlockResult = 1) then begin

      PDF.LoadFromFile('C:\Temp\Template.pdf', '');

      // Set the paper size
      PDF.SetPageSize('A4');
      // Set the origin to the top-left corner
      PDF.SetOrigin(1);
      // Set the measurement units to millimetres
      PDF.SetMeasurementUnits(1);

      AddPDFFormField(PDF, 'Field1', 'Field 1', 1, qrffctTextbox,
        20, 28, 50, 5.5, 'Arial', 10, clBlack, [fsBold]);
      AddPDFFormField(PDF, 'Field2', 'Field 2', 1, qrffctTextbox,
        20, 48, 50, 5.5, 'Arial', 10, clBlack, [fsBold]);

      // Compress the contents of the file
      PDF.CompressContent;

      PDF.SaveToFile('C:\Temp\Test.pdf');
    end;

  finally
    PDF.Free;
  end;
end;

procedure TfmMain.AddPDFFormField(APDF: TDebenuPDFLibrary;
  AName, AValue: String; APageNumber: Integer; AControlType: TQrffControlType;
  ALeft, ATop, AWidth, AHeight: Double; AFontName: String; AFontSize: Integer;
  AFontColor: TColor; AFontStyle: TFontStyles; AAlign: TQrsAlign;
  AFlatten, AReadOnly, AMultiLine, ATransparent, AShowBorder: Boolean;
  ABackgroundColor, ABorderColor: TColor; InTestMode: Boolean);
var
  vFieldIndex, vFontID, vFormFontID, vAlign: Integer;
  vColor: TRGBTriple;
begin
  if (Trim(AFontName) = '') then
    AFontName := 'Arial';

  if (fsBold in AFontStyle) and (fsItalic in AFontStyle) then
    AFontName := AFontName + ' [BoldItalic]'
  else if (fsBold in AFontStyle) then
    AFontName := AFontName + ' [Bold]'             
  else if (fsItalic in AFontStyle) then
    AFontName := AFontName + ' [Italic]';

  vFontID := APDF.AddTrueTypeFont(AFontName, 0);
  vFormFontID := APDF.AddFormFont(vFontID);

  if (AControlType = qrffctCheckbox) then
    vFieldIndex := APDF.NewFormField(AName, 3)
  else
    vFieldIndex := APDF.NewFormField(AName, 1);

  // Position
  APDF.SetFormFieldBounds(vFieldIndex, ALeft, ATop, AWidth, AHeight);

  APDF.SetFormFieldPage(vFieldIndex, APageNumber); // Pagenumber

  APDF.SetFormFieldFont(vFieldIndex, vFormFontID); // Font

  APDF.SetFormFieldTextSize(vFieldIndex, AFontSize);  // FontSize

  vColor := RGBValue(AFontColor);
  APDF.SetFormFieldColor(vFieldIndex, (vColor.rgbtRed/255), (vColor.rgbtGreen/255), (vColor.rgbtBlue/255)); // FontColor

  // Alignment ( 0 = Left, 1 = Center, 2 = Right)
  vAlign := 0;
  case AAlign of
    qaLeftJustify  : vAlign := 0;
    qaCentered     : vAlign := 1;
    qaRightJustify : vAlign := 2;
  end;
  APDF.SetFormFieldAlignment(vFieldIndex, vAlign);


  if InTestMode then begin
    vColor := RGBValue(clSilver);
    APDF.SetFormFieldBackgroundColor(vFieldIndex, (vColor.rgbtRed/255), (vColor.rgbtGreen/255), (vColor.rgbtBlue/255));
    APDF.SetFormFieldBorderColor(vFieldIndex, (vColor.rgbtRed/255), (vColor.rgbtGreen/255), (vColor.rgbtBlue/255));
    APDF.SetFormFieldBorderStyle(vFieldIndex, 1, 0, 0, 0);
  end
  else begin
    vColor := RGBValue(ABackgroundColor);
    APDF.SetFormFieldBackgroundColor(vFieldIndex, (vColor.rgbtRed/255), (vColor.rgbtGreen/255), (vColor.rgbtBlue/255));

    if AShowBorder then begin
      vColor := RGBValue(ABorderColor);
      APDF.SetFormFieldBorderColor(vFieldIndex, (vColor.rgbtRed/255), (vColor.rgbtGreen/255), (vColor.rgbtBlue/255));
      APDF.SetFormFieldBorderStyle(vFieldIndex, 1, 0, 0, 0);
    end;
  end;

  if (AControlType = qrffctTextbox) and AMultiLine then
    APDF.SetFormFieldTextFlags(vFieldIndex, 1, 0, 0, 0, 0);

  if (AControlType = qrffctCheckbox) then begin
    APDF.SetFormFieldCheckStyle(vFieldIndex, 1, 1); // Style = Check, Centred
    if AnsiSameText(AValue, 'T') then
      APDF.SetFormFieldValue(vFieldIndex, 'Yes')
    else
      APDF.SetFormFieldValue(vFieldIndex, 'No');
  end
  else
    APDF.SetFormFieldValue(vFieldIndex, AValue);

  if AReadOnly then
    APDF.SetFormFieldReadOnly(vFieldIndex, 1);

  if AFlatten then
    APDF.UpdateAndFlattenFormField(vFieldIndex);
end;




Replies:
Posted By: Ingo
Date Posted: 19 Apr 16 at 6:56PM
Hi,

"... 20, 28, 50, 5.5, 'Arial', 10, clBlack, [fsBold]); ..."
if you write code like the line above, you're using the font "Arial" - nothing more.
Arial is not the standard - so you have to add this font.
If you need - for example - the bold Arial font you have to add the font-file "C:\Windows\Fonts\arialbd.ttf".
The real font name is "Arial Bold".
First you should try to add the font with the correct name...
then you should select it to make it active...
and then you can use it.
If you don't know the real font names you should call (in windows):
System control -> All System control elements -> Fonts
On the font file you can choose the properties and the details and there you can see the correct font name.



-------------
Cheers,
Ingo



Posted By: Josef Gschwendtner
Date Posted: 20 Apr 16 at 4:21PM
Hi,

could anybody please write down 10 lines of real code how to insert two formfields:
First field with font "Arial", second field with "Arial Bold"

We are only interested on the code needed for setting the font.

Your help is very appreciated.

Josef Gschwendtner


Posted By: Josef Gschwendtner
Date Posted: 20 Apr 16 at 4:29PM
Hi,

you write "Arial" is not the standard.

So what would be the standard?

Thank you,
Josef


Posted By: Ingo
Date Posted: 20 Apr 16 at 7:23PM
Hi Josef,

standard are the 14 (or so...) fonts inside the library.



-------------
Cheers,
Ingo



Posted By: Ingo
Date Posted: 20 Apr 16 at 7:41PM
Hi Josef,

why you don't want to read the sample on page 32 of the developer guide?!
http://www.debenu.com/docs/pdf_library_developer_guide/debenu_quick_pdf_library_10_developer_guide.pdf



-------------
Cheers,
Ingo




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk