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:28 am

All times are UTC




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

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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2015 12:25 pm 
Offline
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:
Code:
private static string EncodingHack(string str)
{
    var encoding = Encoding.BigEndianUnicode;
    var bytes = encoding.GetBytes(str);
    var sb = new StringBuilder();
    sb.Append((char)254);
    sb.Append((char)255);
    for (int i = 0; i < bytes.Length; ++i)
    {
        sb.Append((char)bytes[i]);
    }
    return sb.ToString();
}



And this is how to use the trick (text includes Greek and Cyrillic characters):
Code:
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
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 4 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