PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jun 26, 2017 3:24 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Sep 03, 2009 5:57 pm 

Joined: Thu Sep 03, 2009 5:45 pm
Posts: 1
Location: Greece
It would be nice to support Unicode characters in PDF Document Properties. Specifically, I am trying to write Greek text to the document title and author, but all I get is some unreadable characters.

Reply with quote  
PostPosted: Mon Nov 23, 2015 12:25 pm 
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2659
Location: Cologne, Germany
As of now you can use Unicode strings in properties with a little trick:
private static string EncodingHack(string str)
    var encoding = Encoding.BigEndianUnicode;
    var bytes = encoding.GetBytes(str);
    var sb = new StringBuilder();
    for (int i = 0; i < bytes.Length; ++i)
    return sb.ToString();

And this is how to use the trick (text includes Greek and Cyrillic characters):
var document = new PdfDocument();
document.Info.Author = EncodingHack("ABCabcΑΒΓαβγАБВабв");
document.Info.Title = EncodingHack("ABCabcΑΒΓαβγАБВабв");

The trick was developed for and tested with PDFsharp 1.50.
Future versions of PDFsharp will most likely implement support for Unicode strings for properties. With those future versions, the trick will no longer be necessary - but most likely the trick will not do any harm.

Thomas Hoevel
PDFsharp Team

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group