我尝试使用itextsharp c#从阿拉伯语pdf文件中提取文本时文本方向出错

时间:2016-12-01 21:35:32

标签: c# winforms itext

我的代码有问题 我正在尝试使用itextsharp

从阿拉伯语rtl文件中读取文本
 using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using iTextSharp;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using iTextSharp.text.pdf.parser;
    namespace Masmo3
    {
        public partial class FrmMain : Form
        {
            string book = null;

            public FrmMain()
            {
                InitializeComponent();
            }

            private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
            {

            }

            private void button1_Click(object sender, EventArgs e)
            {
                BtnOpen.Enabled = false;
                book = null;
                using(OpenFileDialog Ofd = new OpenFileDialog() {Filter= "PDF files (*.pdf)|*.pdf|txt files (*.txt)|*.txt",ValidateNames= true, Multiselect= false})
                {
                if (Ofd.ShowDialog() == DialogResult.OK)
                {
                    iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(Ofd.FileName);
                    StringBuilder sb = new StringBuilder();
                    for (int i = 1; i <= reader.NumberOfPages; i++)
                    {
                        sb.Append(PdfTextExtractor.GetTextFromPage(reader, i));
                        book = sb.ToString();
                    }
                    reader.Close();
                }
                }

                BtnOpen.Enabled = true;
            }
        }
    }

这段代码显示我的文字像“میحرلانمحرلااللهمسب”这是错误的,因为它的rtl语言是正确的方式“بسماللهالرحمنالرحيم” 我能做些什么来获得正确的文字方向?

0 个答案:

没有答案