Print Page | Close Window

Exporting FormField Fonts

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=3001
Printed Date: 01 May 24 at 12:21AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Exporting FormField Fonts
Posted By: connerdk
Subject: Exporting FormField Fonts
Date Posted: 07 Nov 14 at 10:52AM
Hi, i am using Debenu QuickPDF Library v9.16, but have testet this with v11.12 and i still have same issue.

I have a PDF with text form fields and needs to fill text with string for a certain codepage e.g. codepage 1250 and insert letter Ł. I finally got it to render correct, but when saving it to a file all standard ascii letters are shown as dots when opened in adobe reader and only the speciel letters like Ł can be read.

If i use GetInstalledFontsByCodePage function and just render with the first suggested font it actually works, but it is "arabic typesettings" font which is not very readable, when trying to use another more common font like "Helvetica" or "Arial" it does not work.

Also if i omit SetFormFieldFont and only use SetFormFieldStandardFont(4) // Helvetica on the form field, then it seems to write the file correct but then i can not display the speciel letters when rendering in QuickPDF.


      FQPDF.FindFonts; // Neccessary?

      slFontNames := TStringList.Create;
      slFontNames.CommaText := FQPDF.GetInstalledFontsByCodePage(FCodePage, 0);
      if slFontNames.Count > 0 then
      begin
        iPreferredFontIndex := -1;
        for i := 0 to slFontNames.Count - 1 do
        begin
          if (slFontNames = 'Helvetica') or
             (slFontNames = 'MS Sans Serif') or
             (slFontNames = 'Arial')
          then
          begin
            iPreferredFontIndex := i;
            break;
          end;
        end;

        if iPreferredFontIndex > -1 then
          sFontName := slFontNames[iPreferredFontIndex] + ' {' + IntToStr(FCodePage) + '}'
        else
          sFontName := slFontNames[0] + ' {' + IntToStr(FCodePage) + '}';
        iFontID := FQPDF.AddTrueTypeFont(sFontName ,1);
        FQPDF.SelectFont(iFontId);
      end
      else
      begin
        iFontID := FQPDF.AddStandardFont(integer(SF_Helvetica));
        FQPDF.SelectFont(iFontID);
        sFontName := FQPDF.FontName;
      end;
      slFontNames.Free;

      bFound := false;
      for i := 1 to FQPDF.GetFormFontCount do
      begin
        if sFontName = FQPDF.GetFormFontName(i) then
        begin
          FFormFieldFontID := i;
          bFound := true;
          break;
        end;
      end;

      if not bFound then
        FFormFieldFontID := FQPDF.AddFormFont(iFontID);

  // Following is done for every field
     FQPDF.SetFormFieldStandardFont(oFormField.Fields.Id, integer(SF_Helvetica)); 
     FQPDF.SetFormFieldFont(oFormField.Fields.Id, FFormFieldFontID);

Best regards
Rune



Replies:
Posted By: connerdk
Date Posted: 07 Nov 14 at 1:48PM
FQPDF.AddTrueTypeFont('Garbage-string' ,1);
returns non-zero value even though i dont have a font called 'Garbage-string'


Posted By: AndrewC
Date Posted: 19 Nov 14 at 11:10AM
Conner,

First off I would suggest not using CodePages but instead set all strings as Unicode encoding.

Existing fonts in a PDF file may often only contain a subset of the characters of that font.  

re : SetFormFieldStandardFont(4)

This is a built in PDF font that that is supported by default by all PDF renderers / viewers.  Unfortunately there are only 229 or so charaters in this font so most Unicode characters are not included in the font.

re : Arabic -  We have very limited support for Arabic in the current versions of Debenu Quick PDF Library.

re : FQPDF.AddTrueTypeFont('Garbage-string' ,1);

A PDF library always needs to return the closest matching font to the font requested so that at least some characters are drawn.

In Debenu Quick PDF library 11.12 can you try using something like the following


            // Arial Unicode MS contains most characters
      
            // Create a dynamically subsetted font with Option 4. 
            int fid1 = QP.AddTrueTypeSubsettedFont("Arial Unicode MS", "", 4);
            QP.SelectFont(fid1);

            int ffid1 = QP.AddFormFont(fid1);

            // formfieldId must be a valid formfield ID.  ie.  between 1 and QP.FormFieldCount()
            QP.SetFormFieldValue(formfieldId, "ФЫВАABCDEF123456")

            // Test drawing on the page.
            QP.SetOrigin(1);
            QP.DrawText(50, 50, "ФЫВА  ABCDEF123456");

Andrew



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