Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法通过C中的ITextSharp从pdf中读取文本#_C#_Pdf_Itextsharp - Fatal编程技术网

C# 无法通过C中的ITextSharp从pdf中读取文本#

C# 无法通过C中的ITextSharp从pdf中读取文本#,c#,pdf,itextsharp,C#,Pdf,Itextsharp,我有两个pdf文件。在Sercurity选项卡上,两个文件都设置了安全方法:无安全性,文档程序集:不允许,页面提取:不允许。其他项目是允许的。 我使用standart ITextSharp方法从pdf检索文本: PdfReader pdfReader = new PdfReader(fileName); for (int page = 1; page <= pdfReader.NumberOfPages; page++) {

我有两个pdf文件。在Sercurity选项卡上,两个文件都设置了安全方法:无安全性,文档程序集:不允许,页面提取:不允许。其他项目是允许的。 我使用standart ITextSharp方法从pdf检索文本:

PdfReader pdfReader = new PdfReader(fileName);

                for (int page = 1; page <= pdfReader.NumberOfPages; page++)
                {
                    ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); //LocationTextExtractionStrategy();
                    string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);

                    currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
                    text.Append(currentText);
PdfReader PdfReader=新的PdfReader(文件名);

对于(int page=1;page可能有很多实际上是图像的pdf。正如Bruno Lowagie所说,您无法从图像pdf中提取文本。为此,您需要使用第三方OCR


您可以使用Adobe Acrobat将pdf转换为word、html等可编辑格式。

我在Aspose担任社交媒体开发人员。我建议您下载并尝试将pdf转换为文本文件。如果您的文件包含图像,并且您需要从这些图像中提取文本,则可以使用Aspose.pdf将pdf文件转换为图像,然后使用使用计算机执行OCR

下面是使用Aspose.PDf for.NET将PDf转换为文本的示例代码

//open document
Document pdfDocument = new Document("input.pdf");
//create TextAbsorber object to extract text
TextAbsorber textAbsorber = new TextAbsorber();
//accept the absorber for all the pages
pdfDocument.Pages.Accept(textAbsorber);
//get the extracted text
string extractedText = textAbsorber.Text;
// create a writer and open the file
TextWriter tw = new StreamWriter("extracted-text.txt");
// write a line of text to the file
tw.WriteLine(extractedText);
// close the stream
tw.Close();

请下载一个免费试用版并试用。

如果可能,请提供这两个文件,以便人们可以查看它们。您可以从Adobe Reader复制/粘贴文本吗?如果不可以,文本无法用任何软件提取,除非您使用OCR it.Pdf文件。我认为您是对的,我认为在这个Pdf文件中是图像。我无法复制文本,我可以复制ly图像。我尝试使用OCR,但效果很差。我下载了免费的OCR版本。也许任何共享软件版本都会更好。如果我购买Adobe Acrobat,我转换为html时不会出现问题?大多数时候Acrobat会将pdf图像转换为html或word格式。但我不能向你保证。我使用Acrobat进行类似的转换大部分时间都有效。我已经使用acrobat将您的ulotkacarefore.pdf转换为ulotkacarefore.doc,看起来很好,但不是转换后的html文件。但文件大小为62 MB。请通过hotmail.com的robbienvz与我联系。我可以将文件发送给您。非常感谢,我向您发送电子邮件。OCR有错误:无法nd文件“C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\2011.07.02 v1.0 Aspose.OCR.Resources.zip”。您可以从以下链接下载资源文件。尝试一下,如果遇到任何问题,请告诉我