本文介绍了将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.




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

09-05 18:33