eDocEngine VCL
Create documents and reports in 18 formats
Compatibility
Delphi C++Builder

Unicode Support In eDocEngine v3

Native support for mixed language text, right-to-left languages and bi-directional writing modes.
By V. Subhash

In the new version of eDocEngine, the PDF engine provides full support for Unicode. This means that eDocEngine can:

  1. Render text in any language that has codepoints in Unicode.
  2. Specify bidirectional text modes (BiDi modes) specified in Classes.TBidiMode.
  3. Render text that are written from right to left such as those in Arabic, Farsi or Hebrew.
  4. Automatically perform font mapping.
  5. Reduce file size of document by performing subset embedding of PDF fonts in a more compact manner.

In eDocEngine v2.x, the PDF engine class TgtPDFEngine had a boolean property Bidi. In Version 3, this property is replaced with another property BiDiMode. You can use a Classes.TBidiMode enum value to set the value of this property.

Following is some sample code that illustrates Unicode capabilities of the PDF engine. In this code snippet, text in several non-English languages are rendered on a page under different bidirectional text modes. The default page font is set to Arial. However, to render text whose glyphs are not present in Arial, the PDF engine automatically finds a more suitable font. All of these fonts are set to be subset embedded in the code. Arial has been excluded from getting embedded, simply to demonstrate that it is possible to exclude certain fonts in that way.

program Demo_eDocEngine_Unicode_Demo;

{$APPTYPE CONSOLE}

uses
  SysUtils, Classes, Graphics, TypInfo,
  gtCstPDFEng, gtCstDocEng, gtPDFEng;

var
  gtPDFEngine1: TgtPDFEngine;
  ArabicStr, BrazilianPortugueseStr, ChineseStr, DeutschStr, EspañolStr,
      FrenchStr, HebrewStr, JapaneseStr, MalayalamStr,
      SanskritStr, RussianStr, TamilStr, ThaiStr: WideString;
  y: Double;
  BidiModeIterator: TBidiMode;
begin

  ArabicStr :=
    'من الحبة تنشأ الشجرة';
  BrazilianPortugueseStr :=
    'Toda regra tem uma exceção';
  ChineseStr :=
    '人要脸树要皮';
  DeutschStr :=
    'Das Eisen schmieden, solange es heiß ist';
  EspañolStr :=
    'Más vale maña que fuerza';
  FrenchStr :=
    'L''on est bien faible quand on est amoureux';
  HebrewStr :=
    'אל תסתכל בקנקן, אלא במה שבתוכו';
  JapaneseStr  :=
    'たげいはむげい';
  MalayalamStr  :=
    'പിത്തള മിനുക്കിയാല്‍ പൊന്നാവില്';
  RussianStr  :=
    'Два медве́дя в одно́й берло́ге не живу́т';
  SanskritStr :=
    'धर्मो रक्षति रक्षितः';
  TamilStr  :=
    'அறம் செய விரும்பு';
  ThaiStr  :=
    'แมลงเม่าบินเข้ากองไฟ';

  gtPDFEngine1 := TgtPDFEngine.Create(nil);

  try
    with gtPDFEngine1 do begin
      Font.Name := 'Arial';
      Font.Size := 13;
      Page.PaperSize := A3;
      Preferences.ShowSetupDialog := False;
      Preferences.OpenAfterCreate := True;
      Preferences.EmbedTrueTypeFonts := etfSubset;
      FontEmbedExcludeList.Add('Arial'); // Do not embed Arial
      Filename := 'edocengine_v3_Unicode_Demo.pdf';

      BeginDoc;

      y := 0.2;
      // Write text in multiple BiDi modes
      for BidiModeIterator  := Low(TBidiMode) to High(TBidiMode) do begin
        BiDiMode := BidiModeIterator;
        Textout(4, y, 'BiDimode is ' +
                      GetEnumName(TypeInfo(TBiDiMode), Ord(BidiModeIterator)));

        // Render text in different languages
        TextOut(4, y + 0.2,  ArabicStr);
        TextOut(4, y + 0.45, BrazilianPortugueseStr);
        TextOut(4, y + 0.7,  ChineseStr);
        TextOut(4, y + 0.95, DeutschStr);
        TextOut(4, y + 1.2,  EspañolStr);
        TextOut(4, y + 1.45, FrenchStr);
        TextOut(4, y + 1.7,  HebrewStr);
        TextOut(4, y + 1.95, JapaneseStr);
        TextOut(4, y + 2.2,  MalayalamStr);
        TextOut(4, y + 2.45, RussianStr);
        TextOut(4, y + 2.7,  SanskritStr);
        TextOut(4, y + 2.95, TamilStr);
        TextOut(4, y + 3.2,  ThaiStr);
        TextOut(4, y + 3.45, ArabicStr +  // Mixed-language string
                            ' From the seed, grows the tree ');
        y := y + 3.45 + 0.6;
      end;

      EndDoc;
    end;
  except
    on E: Exception do begin
      Writeln('Sorry, an error occured in ' +
              E.ClassName, ' with message ', E.Message);
    end;
  end;

  Writeln('Press Enter to quit');
  Readln;
end.

And, here is the output in screenshots.

Latin, Non-Latin and Mixed Language Texts Rendered using bdRightToLeftNoAlign and bdRightToLeft Bidirectional Text Modes

 
Latin, Non-Latin and Mixed Language Texts Rendered using bdRightToLeftNoAlign and bdRightToLeftReadingOnly Bidirectional Text Modes

Finally, examine the fonts used in the document.

Automatic Font Mapping and Different Types of Font Embedding

Thanks to the automatic and intelligent font mapping, you do not have to specify Arial Unicode MS or some other big polyglot Unicode font to support multiple languages. eDocEngine Version 3 does all that internally. You only need to have the appropriate fonts installed in Windows.

Please note that the above code snippet requires the PAS file to be Unicode-encoded. You will be able to use it in Delphi 2007, 2009 or 2010. If you are using an older version of Delphi, then you could read the Unicode strings from a stream and store them in a TWideStringList. Alternatively, you could load them off TNT Delphi Unicode Components.

---o0O0o---

The test phrases and the meanings are listed below.

---o0O0o---

Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
Gnostice Document Studio Java

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2025 Gnostice Information Technologies Private Limited. All rights reserved.