.NET C # - MigraDoc - How to change the encoding of documents?

I was looking for a solution to this problem, but still I can not 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 the example above, the characters "ąčęėįųųūūū" are not displayed in the exported pdf file.

How to set the MigraDoc character set?

+5
source share
2 answers

Just tell Renderer to create a 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. Note that not all True Type fonts include all Unicode characters (but they should work with Arial, Verdana, etc.).

. : http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

+8

PDFSharp MigraDoc, ( , PdfSharp PdfDocument MigraDoc doc, document), . , PDFSharp MigraDoc .

:

  • , MigraDoc , MigraDoc PDF XGraphics gfx.
  • hack gfx.

XGraphics gfx = XGraphics.FromPdfPage(page);
        // HACK²
            gfx.MUH = PdfFontEncoding.Unicode;
            gfx.MFEH = PdfFontEmbedding.Always;
        // HACK²
  Document doc = new Document();

  PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);
        pdfRenderer.Document = doc;
        pdfRenderer.RenderDocument();

  MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
        docRenderer.PrepareDocument();
        docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", para);

1.5.x-

 let gfx = XGraphics.FromPdfPage(page)
 gfx.MUH <- PdfFontEncoding.Unicode
 let doc = new Document()

 let pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always)
 pdfRenderer.Document <- doc
 pdfRenderer.RenderDocument()

 let docRenderer = new DocumentRenderer(doc)
 docRenderer.PrepareDocument()
 docRenderer.RenderObject(gfx, XUnit.FromCentimeter 5, XUnit.FromCentimeter 10, "12cm", para)
+1

All Articles