Search code examples
c#.netpdfmigradoc

.NET C# - MigraDoc - How to change document charset?


I've searched for solution to this problem, but still cannot find the answer. Any help would be appreciated.

    Document document = new Document();
    Section section = document.AddSection();

    Paragraph paragraph = section.AddParagraph();

    paragraph.Format.Font.Color = Color.FromCmyk(100, 30, 20, 50);

    paragraph.AddText("ąčęėįųųūū");

    paragraph.Format.Font.Size = 9;
    paragraph.Format.Alignment = ParagraphAlignment.Center; 
    </b>

<...>

In example above characters "ąčęėįųųūū" are not displayed in exported pdf.

How can I set 'MigraDoc' character set ?


Solution

  • Just tell the Renderer to create an Unicode document:

    PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
    renderer.Document = document;
    

    The first parameter of PdfDocumentRenderer must be true to get Unicode. Please note that not all True Type fonts include all Unicode characters (but it should work with Arial, Verdana, etc.).

    See here for a complete sample: http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx