PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Unicode [U+1F512] does not render
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3151
Page 1 of 1

Author:  cBra [ Mon Jul 20, 2015 10:58 am ]
Post subject:  Unicode [U+1F512] does not render

Hello everyone,
I am working on a project where I have to export some Unicode chars.

This works fine for everyone Unicode letter like : [U+00B1] but not for [U+1F512]any chance to work this out?

Code:
 
            _document = new Document();

            Style style = _document.Styles["Normal"];
            style.Font.Name = "Segoe UI Symbol"; // Includes both Unicode chars!

            var _lastSection = _document.AddSection();
            _lastSection.AddParagraph("[U+00B1] [U+1F512]"); // These are the actual symbols, the forum doesnt allow me to submit the post otherwise!!
            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "test.pdf");
            if(File.Exists(path))
                File.Delete(path);

            // Create a renderer for the MigraDoc document.
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);

            // Associate the MigraDoc document with a renderer
            pdfRenderer.Document = _document;

            // Layout and render document to PDF
            pdfRenderer.RenderDocument();

            // Save the document...
            pdfRenderer.PdfDocument.Save(path);


This code produces the 'broken' (not rendering Unicode) pdf. (All Unicode symbols are shown correctly in the debugger and the used Font does implement both!)

Thanks for the help

cBra

Author:  TH-Soft [ Mon Jul 20, 2015 11:32 am ]
Post subject:  Re: Unicode [U+1F512] does not render

Hi!

AFAIK all Unicode characters greater or equal to U+10000 are not yet supported by PDFsharp.

Author:  cBra [ Mon Jul 20, 2015 12:01 pm ]
Post subject:  Re: Unicode [U+1F512] does not render

Any chance to "hack" my way around it? It is a necessity to have access to all Unicode symbols for me.

Author:  TH-Soft [ Mon Jul 20, 2015 3:38 pm ]
Post subject:  Re: Unicode [U+1F512] does not render

cBra wrote:
Any chance to "hack" my way around it?
I don't know how much is required for that.

Look at this code:
Code:
const string strA = "\u0081";
const string strB = "\U0001f512";
int lenA = strA.Length;
int lenB = strB.Length;
lenA will be 1 and lenB will be 2. Oops.
These surrogate pairs are a problem for this forum, they are a problem for PDFsharp, they are a problem for C#/.NET or whatever.

I don't know how many changes are required in PDFsharp, but you won't get away with changing just two or three lines. The problem starts earlier as the normal .NET string functions won't handle those surrogate pairs as one character.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/