Aspose.Pdf.dll或pdfbox 提取txt乱码,不能识别中文

apei1002 2018-01-09 09:55:55
使用Aspose.Pdf.dll或pdfbox提出中文时,出现乱码。乱码原因已明白,是编码的原因。因为它是Identity-H的,而使用foxit等生成的pdf是ANSI之类的编码不会有问题。
pdfbox代码:
OpenFileDialog open = new OpenFileDialog();
open.Title = "请选择要导入的pdf文件";
open.Filter = "pdf文件(*.pdf)|*.pdf";
string fileName = "";
if (open.ShowDialog() == DialogResult.OK)
{
fileName = open.FileName;
}
else
return;
PDDocument doc = PDDocument.load(fileName);
PDFTextStripper pdfStripper = new PDFTextStripper();
string str= pdfStripper.getText(doc);
textBox1.Text = str;

Aspose:
string file = "";
if (fileDialog.ShowDialog() == DialogResult.OK)
{
file = fileDialog.FileName;
}
else
return;
d = new Document(file);
TextAbsorber txt = new TextAbsorber();

d.Pages[1].Accept(txt);
textBox1.Text = txt.Text;
请问怎么处理,任一办法都可以 附件为样本
...全文
539 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_42634768 2018-08-13
  • 打赏
  • 举报
回复
PDFTextStripper pdfStripper = new PDFTextStripper("GBK");
apei1002 2018-01-12
  • 打赏
  • 举报
回复
有大神知道怎么解决不
apei1002 2018-01-09
  • 打赏
  • 举报
回复
呃,怎么不能上传附件呢
apei1002 2018-01-09
  • 打赏
  • 举报
回复
引用 2 楼 Eiceblue 的回复:
关键要看你的文档。可以用Spire.PDF试试,它支持中文,参考文章:C# 何如提取 PDF 文档中的文本和图片
谢谢,测试了下,与aspoes之类一样,还是乱码,还是编码的问题

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧