[使用iTextsharp从pdf提取Urdu(rtl语言)文本时,它向我显示了镜像(反向)文本,请问有什么例子可以说明我如何从pdf正确提取Urdu文本?
static string ReadPdfFile(string fileName)
{
StringBuilder text = new StringBuilder();
if (File.Exists(fileName))
{
PdfReader pdfReader = new PdfReader(fileName);
for (int page = 2; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
currentText = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.UTF8.GetBytes(currentText)));
text.Append(currentText);
}
pdfReader.Close();
}
return text.ToString();
}
在波斯语中,就像乌尔都语一样,这是一种rtl语言,在使用iTextSharp进行常规提取后,我使用了自定义方法:
public string ReverseTheString(string source)
{
try
{
return new string(source.ToCharArray().Reverse().ToArray());
}
catch (Exception ex)
{
return null;
}
}