Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Test()
- {
- var sb = SBReadPdfToOutputFile(@"C:\Users\Global\Downloads\LA30AA(US).pdf");
- ReadPdfToOutputFile(@"C:\Users\Global\Downloads\LA30AA(US).pdf");
- var nonSb = File.ReadAllText(System.IO.Path.GetDirectoryName(@"C:\Users\Global\Downloads\LA30AA(US).pdf") + "\\output.txt");
- if (sb.Equals(nonSb))
- MessageBox.Show("They're the same");
- }
- public static void ReadPdfToOutputFile(string fileName)
- {
- string testFilePath = System.IO.Path.GetDirectoryName(fileName) + "\\output.txt";
- if (System.IO.File.Exists(fileName))
- {
- PdfReader pdfReader = new PdfReader(fileName);
- for (int page = 1; page <= pdfReader.NumberOfPages; page++)
- {
- //We can change out the Type of extraction We use when getting Text from PDF
- ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); //TopToBottomTextExtractionStrategy() or SimpleTextExtractionStrategy();
- string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
- currentText = Encoding.Default.GetString(Encoding.ASCII.GetBytes(currentText));
- using (StreamWriter sr = File.AppendText(testFilePath))
- {
- sr.Write(currentText);
- }
- }
- pdfReader.Close();
- }
- }
- public static String SBReadPdfToOutputFile(string fileName)
- {
- string testFilePath = System.IO.Path.GetDirectoryName(fileName) + "\\SBoutput.txt";
- if (System.IO.File.Exists(fileName))
- {
- PdfReader pdfReader = new PdfReader(fileName);
- StringBuilder sb = new StringBuilder();
- for (int page = 1; page <= pdfReader.NumberOfPages; page++)
- {
- //We can change out the Type of extraction We use when getting Text from PDF
- ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); //TopToBottomTextExtractionStrategy() or SimpleTextExtractionStrategy();
- var text = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
- sb.Append(Encoding.Default.GetString(Encoding.ASCII.GetBytes(text)));
- }
- pdfReader.Close();
- return sb.ToString();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement