In This Topic
    Use Composite True Type fonts
    In This Topic

    Introduction

    The following example demonstrates how to use Composite True Type fonts in a PDF document.

    Composite True Type fonts can be used to add text in languages like Japanese in a PdfDocument; it supports more than 255 characters per font & thus allows for a more complex font set.

    Use composite True Type fonts (C#)
    Copy Code
    public static void UseCompositeTrueTypeFont()
    {
      Console.WriteLine( "=== USE COMPOSITE TRUE TYPE FONT ===" );
      var outputFileName = "UseCompositeTrueTypeFont.pdf";
      var outputPath = FontsSample.FontsSampleOutputDirectory + outputFileName;
    
      // Creates a PdfDocument.
      using( var pdfoutput = PdfDocument.Create( outputPath ) )
      {
        // Gets the first Page of the document.
        var page = pdfoutput.Pages.First();
    
        // Adds a title.
        var titleStyle = TextStyle.WithFont( pdfoutput.Fonts.GetStandardFont( StandardFontType.Helvetica ), 15d );
        page.AddParagraph( "Use Composite TrueType Fonts", titleStyle, new ParagraphStyle( ParagraphHorizontalAlignment.Center ) );
    
        // Creates a TextStyle from a TrueType Japanese font.
        // The default FontEmbeddingMode.Auto will create a Type0 composite Font (for Fonts with more than 255 characters).
        var ttfTextStyle = TextStyle.WithFont( pdfoutput.Fonts.GetFontFromFile( FontsSample.FontsSampleResourcesDirectory + @"NotoSansJP-SemiBold.ttf" ), 12 );
    
        // Specifies the text to write.
        var text = "モントリオール発 ― 有望な才能に注目するNHLスカウトたちにケベック・ホッケーを説明する際に最も頻繁に挙げられるのは「希薄化」という言葉だ。\r\n\r\nたとえルーアン=ノランダからベ=コモーまで足を運んだとしても、その発展を阻む問題を十分に調査するには時間が足りないだろう。QMJHLに専属ではないNHLスカウトとの話し合いを要約すると、以下の通りだ。\r\n\r\n「現在、ホッケーをプレーするには確かに非常に費用がかかり、それが登録できる選手の質に影響を与えることもあります」と、このスカウトは認め、ホッケー・ケベックが会員とより頻繁に協議することを望んでいる。\r\n\r\n彼が指摘するように、ホッケーが貧しい家庭の子供たちによってプレーされ、主に楽しい逃避の手段だった時代は、はるか昔に過ぎ去った";
    
        // Adds a paragraph, starting 75 pts from the top of the Page and with the specified text and TextStyle.
        page.AddParagraph( text, 75, ttfTextStyle );
    
        // Saves the output document.
        pdfoutput.Save();
        Console.WriteLine( $"Info exported to path: {outputFileName}" );
      }
    }

     Learn More

    To know more about how to add text at a specific location in the document, please consult the "How To Add Text In A Specific Location" example.

    To know how to use standard fonts instead of standard fonts to stylize text in a PDF document, please consult the "How To Use Standard Fonts" example.


    See Also