从pdf提取阿拉伯语到字符串c# [英] extract arabic from pdf to string c#

查看:104
本文介绍了从pdf提取阿拉伯语到字符串c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我知道这个问题被重复了很多次.但是直到现在我还没有找到解决方案. 我正在使用iTextSharp从pdf中提取.对于英语,效果很好,但对于阿拉伯语,它始终显示"???????"在控制台中,在.txt中是ÓåæáÉ" 这是我的代码

ok i know this question is repeated too many times. but until now i didn't find a solution. I'm using iTextSharp to extract from a pdf. for english it works good, but for Arabic it always shows "???????" in the console and "Ó å æ á É" in the .txt this is my code

private static string ReadPdfFile(string fileName)
    {
        StringBuilder text = new StringBuilder();


        if (File.Exists(fileName))
        {
            PdfReader pdfReader = new PdfReader(fileName);
            ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
            string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, 1, strategy);
            //currentText = Encoding.UTF8.GetString(UTF8Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
            text.Append(currentText);
        }

        return text.ToString();
    }

更新:

通过对输出文件使用UTF8解决了问题 现在我还有2个问题

the problem is solved by using the UTF8 for the output file now i have 2 more problems

它显示"اﻟ ﻟ ﺪ ﻢ ﺗ"而不是تمالتقديم" 所以:

it shows "ا ﻟ ﺘ ﻘ ﺪ ﻳ ﻢ ﺗ ﻢ" instead of "تم التقديم" so:

  1. 我需要删除字母之间的空格.

  1. i need to remove the spaces between letters.

单词的顺序颠倒了.

推荐答案

尝试以下代码将您的ÓåæáÉ"转换为سهولة"

Try the following code to convert your "Ó å æ á É" to "س ه و ل ة"

public static string Arabic1256ToUtf8(string data)
{
    var latin = Encoding.GetEncoding("ISO-8859-1");
    var bytes = latin.GetBytes(data); // get the bytes for your ANSI string

    var arabic = Encoding.GetEncoding("Windows-1256"); // decode it using the correct encoding
    return arabic.GetString(bytes);
}

这篇关于从pdf提取阿拉伯语到字符串c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆