Skip to content

Commit

Permalink
fix PDFParser
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyqus committed Aug 28, 2021
1 parent 56b247f commit 4847811
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions ToxyFramework/Parsers/PDFDocumentParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
using iText.Kernel.Pdf.Canvas.Parser.Listener;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -20,14 +21,13 @@ public ToxyDocument Parse()
throw new FileNotFoundException("File " + Context.Path + " is not found");

ToxyDocument rdoc = new ToxyDocument();
ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
ITextExtractionStrategy its = new LocationTextExtractionStrategy();

using (PdfReader reader = new PdfReader(this.Context.Path))
using (PdfDocument reader = new PdfDocument(new PdfReader(this.Context.Path)))
{

for (int i = 1; i <= reader.NumberOfPages; i++)
for (int i = 1; i <= reader.GetNumberOfPages(); i++)
{
string thePage = PdfTextExtractor.GetTextFromPage(reader, i, its);
string thePage = PdfTextExtractor.GetTextFromPage(reader.GetPage(i), its);
string[] theLines = thePage.Split('\n');
foreach (var theLine in theLines)
{
Expand Down
13 changes: 7 additions & 6 deletions ToxyFramework/Parsers/PDFTextParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
using iText.Kernel.Pdf.Canvas.Parser.Listener;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -18,14 +19,14 @@ public string Parse()
if (!File.Exists(Context.Path))
throw new FileNotFoundException("File " + Context.Path + " is not found");

using (PdfReader reader = new PdfReader(this.Context.Path))
using (PdfDocument reader = new PdfDocument(new PdfReader(this.Context.Path)))
{
StringBuilder text = new StringBuilder();

for (int i = 1; i <= reader.NumberOfPages; i++)
for (int i = 1; i <= reader.GetNumberOfPages(); i++)
{
ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
string thePage = PdfTextExtractor.GetTextFromPage(reader, i, its);
ITextExtractionStrategy its = new LocationTextExtractionStrategy();
string thePage = PdfTextExtractor.GetTextFromPage(reader.GetPage(i), its);
text.AppendLine(thePage);
}
return text.ToString();
Expand Down

0 comments on commit 4847811

Please sign in to comment.