我想将pdf格式的文档转化为txt文档,但是不知道为什么在txt中汉字显示的都是乱码,其他字符都可以显示:
郁闷之极,不知哪位大侠能给我一个解脱:((注:从java中抽取word pdf文档的四种方法:http://touchpdf.blogdriver.com/touchpdf/98972.html)程序如下:
import java.io.*;public class PdfWin {
public PdfWin() {
}
public static void main(String args[]) throws Exception
{
String PATH_TO_XPDF="C:\\Documents and Settings\\Frank\\pdftotext.exe";
String filename="c:\\a.pdf";
String[] cmd = new String[] { PATH_TO_XPDF, "-enc", "UTF-8", "-q", filename, "-"};
Process p = Runtime.getRuntime().exec(cmd);
BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
InputStreamReader reader = new InputStreamReader(bis, "UTF-8");
PrintWriter resultFile = new PrintWriter(new FileOutputStream(".\\result.txt"));
char [] buf = new char[10000];
byte [] bytebuf = new byte[2];
char [] buf2 = new char[2];
String tempstring1 = null;
String tempstring2 = null;
int len;
int Unicode = 0;
try{
while((len = reader.read(buf))>= 0)
{
tempstring1 = null;
for(int i=0;i<len;i++)
{
bytebuf[0] = (byte)buf[i];
if((bytebuf[0]-160+256)>99)
{
tempstring2 = String.valueOf(buf[i]);
}
else
{
bytebuf[0] = (byte)buf[i];
bytebuf[1] = (byte)buf[i+1];
tempstring2 = new String(bytebuf);
i++;
}
tempstring1 +=tempstring2;
}
System.out.println(tempstring1);
resultFile.print(tempstring1);
resultFile.flush();
}
}catch(FileNotFoundException e1){
e1.printStackTrace();
}catch(IOException e2){
e2.printStackTrace();
}
reader.close();
}
}
在线等待!!!!!!!
如果能,再仔细看他的使用帮助
有人吗?:(
但还不太一样,我在将pdf格式的文档转化为txt文档,在txt中汉字显示有一半是乱码,而另一半则是正确的。
郁闷!
希望各位大侠能给个答案!
BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
InputStreamReader reader = new InputStreamReader(bis);//GBK这样的话。就可以解决中文乱码的问题了
http://www.seeitco.com
收集国内外IT公司相关信息,并且有相关的评论和排名,你也可以把自己的看法加进去,包括待遇、薪水、公司规模等等,对于找工作的各位很有帮助哦!自己先在心里有个底,至少不会被各家公司眼花缭乱的招聘广告所蒙骗。各位也可以往里面添加新的公司信息,使数据库进一步完善,以后就会越来越方便!
你的方法我试了,不行。
另外如果在windows的环境下该如何配置文件xpdfrc中语言包的路径呢?
可以根据相对应的内码来解释,就可以了。