page = PdfTextExtractor.GetTextFromPage(r, i, Strategy);
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.IO; using System.Text; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace test { public partial class Form1 : Form { string filename; string path; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.CheckFileExists = true; openFileDialog.AddExtension = true; openFileDialog.Filter = "PDF files (*.pdf)|*.pdf"; DialogResult result = openFileDialog.ShowDialog(); if (result == DialogResult.OK) { //data1 = openFileDialog.FileNames.Select(x => new FileInfo(x)).ToArray(); filename = Path.GetFileName(openFileDialog.FileName); path = Path.GetDirectoryName(openFileDialog.FileName); textBox1.Text = path + "\\" + filename; } } private void button3_Click(object sender, EventArgs e) { string s= Form1.ExtractTextFromPdf(textBox1.Text); string reverseValue = new string(s.Select((c, index) => new { c, index }) .OrderByDescending(x => x.index) .Select(x => x.c) .ToArray()); richTextBox1.Text = reverseValue; } public static string ExtractTextFromPdf(string filename) { using (PdfReader r = new PdfReader(filename)) { StringBuilder text = new StringBuilder(); ITextExtractionStrategy Strategy = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy(); for (int i = 1; i <= r.NumberOfPages; i++) { //string first; string page = ""; page = PdfTextExtractor.GetTextFromPage(r, i, Strategy); string[] lines = page.Split('\n'); foreach (string line in lines) { text.Append(line); } } string first = text.ToString(); return first; } } } }
LocationTextExtractionStrategy
SimpleTextExtractionStrategy
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)