A
A
Alexander2012-12-28 06:24:58
.NET
Alexander, 2012-12-28 06:24:58

C# (VS 2010) Cyrillic in pdf document properties

Hello!
I'm trying to change the metadata in a pdf document like this:

using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

...

PdfDocument document = PdfReader.Open(selectedFullPathFile);
document.Info.Author = "Суслик";
document.Save(selectedFullPathFile);


Everything works, but when viewing the file's metadata in the explorer, it displays "! CA; 8:"
I understand that the problem is in the encoding, but no matter how many methods I tried, none helped.
Can you point me in the right direction?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vvhedgehog, 2015-10-22
@cry_san

I did overcome this problem
. Here is my bike:

class Program
    {
        static string unicodePrefix = new string(new char[] { '\xFE', '\xFF' });
        static string EncodePdfInfoString(string s)
        {
            byte[] originalByteString = Encoding.Unicode.GetBytes(s);
            byte b; //swap pairs
            for (var i = 0; i < originalByteString.Length; i += 2)
            {
                b = originalByteString[i];
                originalByteString[i] = originalByteString[i + 1];
                originalByteString[i + 1] = b;
            }
            return unicodePrefix + Encoding.ASCII.GetString(originalByteString);
        }
        void SomeWork()
        {
                ...
                document.Info.Author = EncodePdfInfoString("Суслик");
                document.Save(selectedFullPathFile);
        }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question