将PDF文件转换为TEXT文件 [英] Convert PDF file to TEXT file

查看:128
本文介绍了将PDF文件转换为TEXT文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想将PDF文件转换为TEXT文件.

这是我的代码:

Hi,
I want to convert PDF file to TEXT file.

This is my code:

String tempFolderPath = Path.GetTempPath();
                       StreamWriter writeTextFile = File.CreateText(tempFolderPath + "content.txt");
            writeTextFile.WriteLine(TransformPdfToText(tempFolderPath + "coalmar100604.pdf"));
            writeTextFile.Close();
 

private static string TransformPdfToText(string SourceFile)
        {
            string content = "";
            PDDocument doc = PDDocument.load(SourceFile);
            PDFTextStripper stripper = new PDFTextStripper();
         
            try
            {
                content = stripper.getText(doc);

                doc.close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                doc.close();
            }
            return content;
        }



粗体中的行显示错误:: 对象引用未设置为对象的实例.



the line in bold shows an error:: Object reference not set to an instance of an object.

推荐答案

Shruti Gargate写道:
Shruti Gargate wrote:

writeTextFile.WriteLine(TransformPdfToText(tempFolderPath +"coalmar100604.pdf"));

writeTextFile.WriteLine(TransformPdfToText(tempFolderPath + "coalmar100604.pdf"));



在上面提到的行中的代码中放置一个调试点,以查看pdf文件是否在tempFolderPath位置.



Put a debug point in the code at the line mentioned above to see if the pdf file exists at the tempFolderPath location.


当您调试并到达该行时,是否检查了剥离程序和doc ?

它们中的一个都为空吗?那是我唯一想到的就是问题.
When you debug and get to that line, have you checked stripper and doc?

Are either of them null? That would be the only thing that I could think of that would be the problem.


不,我没有检查汽提塔和doc都不为空


这是该pdf文件的链接.我想读取这些值.
我已将此pdf文件保存在指定位置.我可以从链接中获取价值吗?

http://tonto.eia.doe.gov/FTPROOT/coal/newsmarket/coalmar100611.pdf">


预先谢谢您.
No i have checked both the stripper and doc both are not null


This is the link of that pdf file. I want to read that values.
I have saved this pdf file on specified location. Can i get the value from the link?

http://tonto.eia.doe.gov/FTPROOT/coal/newsmarket/coalmar100611.pdf">


Thank you in advance.


这篇关于将PDF文件转换为TEXT文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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