2016-08-02 14 views
0

Omega文字(0x3A9)を含むテキストがあります。この文字をデフォルトのHelveticaフォントで表示すると、PDFに何も表示されません。iTextSharp - Helveticaフォントにすべての文字がありません

予想、Helvetica.CharExists(0x3A9)はfalseを返すように私は、

BaseFont Helvetica = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); 

を使用して、私のフォントを作成しています。

また、TIMES_ROMAN、SYMBOL、およびZAPF_DINGBATSフォントにCharExists(0x3A9)を呼び出しました。すべてfalseを返します。

  1. フォントを間違って作成していますか?オメガ文字を含むフォントを作成するより良い方法はありますか?
  2. このような不足している文字を処理する一般的な方法はありますか? CharExists(0x3A9)がtrueを返すフォントが見つかるまで、利用可能なすべてのフォントを列挙するだけですか?

    P.S.など、プラス/マイナス、左右の二重引用符、ミクロン -

マイドキュメントは英語であるが、特殊文字の片言を持っています

BaseFont arial = BaseFont.CreateFont("c:\\windows\\fonts\\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); 

文字が0x3A9のグリフが含まれています。しかし、明らかにIDENTITY_HエンコーディングでHELVETICAフォントを作成することはできません。

+1

HELVETICA、TIMES_ROMAN、SYMBOL、およびZAPF_DINGBATSは、各PDFビューアが特定の制限付き文字セットを提供する標準14フォントです。より多くの文字が必要な場合は、Arialの場合と同じように、自分でフォントを提供する必要があります。 – mkl

答えて

0

私が結局何か複雑なのですが、しっかりしています。今まで私は新しいフレーズを作成するだけで、文字列内の各文字を列挙し、BaseFont.CharExists()を呼び出すことで、ドキュメントにテキストを追加するたびに使用しました。答えが文字でない場合は、CharExists()の連続したシーケンスに基づいて、テキストをチャンクに分割します。次に、Helveticaに存在するチャンクについては、私はHelveticaでChunkを作成し、他はArialでChunkを作成し、それらのチャンクをPhraseに組み込みます。

私がこれを行う理由は、ほとんどの読者には明らかですが、その場合には、PDFファイルにArialフォントを常に追加したくないということです。私の文書の%にはArialが必要なOmegaのような文字は含まれていません。この方法では、実際に必要な少数のドキュメントにのみArialフォントを追加します。

Phrase phrase = null; 
string s = ""; 
for (int i = 0 ; i < text.Length ; i++) 
{ 
    char c = text[i]; 
    if (fonts.Regular.BaseFont.CharExists(c)) 
     s += c; // Accumulate Helvetica characters in 's' 
    else 
    { 
     // Try adding the Arial font 
     iTextSharp.text.Font arial = fonts.Arial;  // Creates the Arial font and adds it to the document if not already there 
     if (arial == null) 
     { 
     Debug.WriteLine(" Arial font not found"); 
     s += c; 
     } 
     else if (!arial.BaseFont.CharExists(c)) 
     { 
     Debug.WriteLine(" Arial does not contain the required glyph"); 
     s += c; 
     } 
     else 
     { 
     // We have a character that Helvetica doesn't have, that Arial does 
     if (phrase == null) 
     { 
      // This is the first time we've realize that we need a split phrase 
      if (s.Length > 0) 
      { 
       // There was Helvetica text before the Arial character. 
       phrase = new Phrase(s, fonts.Regular); 
       // This code assumes that non-Helvetica characters generally come singly 
       phrase.Add(new Chunk(c, arial)); 
       s = ""; 
      } 
      else 
      { 
       // The Arial character is the first one in the string 
       phrase = new Phrase(new Chunk(c, arial)); 
      } 
     } 
     else 
     { 
      // This is not the first Arial character in the string 
      if (s != "") 
      { 
       // There were Helvetica characters before this Arial character 
       phrase.Add(new Chunk(s, fonts.Regular); 
       s = ""; 
      } 
      phrase.Add(new Chunk(c, arial)); 
     } 
     } 
    } 
} 

if (phrase == null) 
{ 
    // We did not encounter any Arial characters, create a simple Phrase 
    phrase = new Phrase(text, fonts.Regular); 
} 
else if (s.Length > 0) 
{ 
    // There were Helvetica characters at the end of the string, add them now 
    phrase.Add(new Chunk(s, fonts.Regular)); 
} 
関連する問題