empira / PDFsharp-1.5

A .NET library for processing PDF
MIT License
1.28k stars 588 forks source link

Support Right to left languages (persian, arabic, ...) #144

Open Gholamalih opened 3 years ago

Gholamalih commented 3 years ago

for example when we draw persian string "سلام" it draws "م ا ل س"

ThomasHoevel commented 3 years ago

Known implementation restriction, see FAQ.

Gholamalih commented 3 years ago

why we didn't use .Net's Graphic class? this class can handle right to left languages.

ThomasHoevel commented 3 years ago

Maybe .NET’s Graphics class can not handle PDF. Feel free to prove me wrong. Is there an easy way to use it for PDF generation?

ibrhabash commented 2 years ago

you can rivers string and pike the right glyph for character you can use AraibcPdfUnicodeGlyphsResharper to help

using PdfSharp.Drawing;
using PdfSharp.Pdf;
using AraibcPdfUnicodeGlyphsResharper;
namespace MigraDocArabic
{
internal class PrintArabicUsingPdfSharp
{
    public PrintArabicUsingPdfSharp(string path)
    {
        PdfDocument document = new PdfDocument();
        document.Info.Title = "Created with PDFsharp";
        System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
        // Create an empty page
        PdfPage page = document.AddPage();

        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);

        // Create a font
        XFont font = new XFont("Arial", 20, XFontStyle.BoldItalic);
        var xArabicString = "كتابة اللغة  العربية شيئ جميل".ArabicWithFontGlyphsToPfd();
        // Draw the text
        gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
        gfx.DrawString(xArabicString, font, XBrushes.Black, new XRect(50, 50, page.Width, page.Height), XStringFormats.Center);

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

    }
}