PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 19, 2024 11:40 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Jul 29, 2016 9:03 am 
Offline

Joined: Fri Jul 29, 2016 7:32 am
Posts: 3
Problem with image of the cyrillics in PdfSharp.Pdf.Annotations.PdfTextAnnotation:

Code:
   Public Sub nPDF()
        pdfDIMA = New PdfDocument 'создание документа
        Dim pdfPage As PdfPage = pdfDIMA.AddPage 'добавляем страницу
        Dim graph As XGraphics = XGraphics.FromPdfPage(pdfPage) 'создаем объект Графич sFont
        Dim codFont As XPdfFontOptions = New XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Default)
        Dim fontD As XFont = New XFont("Verdana", 20, XFontStyle.Bold, codFont) 'создаем шрифт
        'Dim fontD As XFont = New XFont(sFont, 20, XFontStyle.Bold, codFont) 'создаем шрифт

        'Dim theColor As Color = Color.Black ' Color.Purple
        Dim mP1 As Point = New Point(10, 10)
        Dim mP2 As Point = New Point(300, 20)
        Dim regEg As XRect = New XRect(mP1.X, mP1.Y, mP2.X - mP1.X, mP2.Y - mP1.Y)
        Dim instF As New XStringFormat
        instF.Alignment = XStringAlignment.Near
        instF.LineAlignment = XLineAlignment.Center 'StringAlignment.Center
        Dim sSize As XSize
        'Dim sSTRI As String = "Кирилица Latinica 12345"
        graph.DrawString("Кирилица Latinica 12345", fontD, XBrushes.Black, regEg, instF)
        sSize = graph.MeasureString("Кирилица Latinica 12345", fontD)

        'пробуем с аннотациями  проблема с кирилицей
        Dim textAnnot As Annotations.PdfTextAnnotation = New Annotations.PdfTextAnnotation
        Dim rect As XRect
        'textAnnot = New PdfSharp.Pdf.Annotations.PdfTextAnnotation
        textAnnot.Title = "Кирилица Latinica 12345"
        textAnnot.Subject = "Кирилица Latinica 12345"
        textAnnot.Contents = "Кирилица Latinica 12345"
        textAnnot.Icon = PdfSharp.Pdf.Annotations.PdfTextAnnotationIcon.Comment '.Note
        rect = graph.Transformer.WorldToDefaultPage(New XRect(sSize.Width + 20, 10, 20, 20))
        textAnnot.Rectangle = New PdfRectangle(rect)
        graph.PdfPage.Annotations.Add(textAnnot)

        pdfDIMA.Save("D:\file.pdf")
        pdfDIMA.Dispose()

        ShellExecute(0, "open", "D:\file.pdf", "", "", SW_SHOWMAXIMIZED)
    End Sub


This possible somehow solve )))
Attachment:
pdf_font.JPG
pdf_font.JPG [ 29.54 KiB | Viewed 4740 times ]


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 02, 2016 10:47 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 915
Location: CCAA
Hi!

With two small changes to the PDFsharp source code you can get Unicode characters in Annotations.

In file PdfString.cs below method "static void CheckRawEncoding(string s)" I added a new method:

Code:
static bool IsRawEncoding(string s)
{
    if (String.IsNullOrEmpty(s))
        return true;

    int length = s.Length;
    for (int idx = 0; idx < length; idx++)
    {
        if (!(s[idx] < 256))
            return false;
    }
    return true;
}


In the same file I also changed the constructor that only takes a string:
Code:
public PdfString(string value)
{
    if (!IsRawEncoding(value))
        _flags = PdfStringFlags.Unicode;
    _value = value;
}


I don't know whether this change has unwanted side-effects, so use it at your own risk.
I do hope that PDF supports Unicode at all items affected by this change.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 03, 2016 6:04 am 
Offline

Joined: Fri Jul 29, 2016 7:32 am
Posts: 3
TH-Soft wrote:
Hi!

With two small changes to the PDFsharp source code you can get Unicode characters in Annotations.

In file PdfString.cs below method "static void CheckRawEncoding(string s)" I added a new method:


The Day good!
C# not my language. But shall try ))

Ups...In my file PdfString.cs no method "static void CheckRawEncoding(string s)" )))

Can, as variant, text to send in format ASCII?


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 03, 2016 10:15 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
fdbir wrote:
Ups...In my file PdfString.cs no method "static void CheckRawEncoding(string s)" )))
Time to get the 2015 source code:
http://pdfsharp.codeplex.com/releases/view/618773

Or add the new method anywhere in the class.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 04, 2016 7:00 am 
Offline

Joined: Fri Jul 29, 2016 7:32 am
Posts: 3
Thomas Hoevel wrote:
fdbir wrote:
Ups...In my file PdfString.cs no method "static void CheckRawEncoding(string s)" )))
Time to get the 2015 source code:
http://pdfsharp.codeplex.com/releases/view/618773

Or add the new method anywhere in the class.


All OK ))))
All thank you

Else question: as background picture in PdfTextAnnotation to insert possible?


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 227 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group