-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
42 lines (35 loc) · 1.48 KB
/
Copy pathProgram.cs
File metadata and controls
42 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.IO;
using ImageGear.Formats;
using ImageGear.Formats.PDF;
namespace PDFContentExtractText
{
class Program
{
static void Main()
{
// Initialize common formats.
ImGearCommonFormats.Initialize();
// Add PDF format to filters list.
ImGearFileFormats.Filters.Add(ImGearPDF.CreatePDFFormat());
// Initialize PDF support. Initialize for each process or thread.
ImGearPDF.Initialize();
// Load a PDF document.
using (Stream stream = new FileStream(@"../../../../../../../Sample Input/multi-page.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (ImGearPDFDocument imGearPDFDocument = ImGearFileFormats.LoadDocument(stream) as ImGearPDFDocument)
{
// Create a memory stream to hold extracted text.
using (MemoryStream textFromPDF = new MemoryStream())
{
// Extract text from all pages.
imGearPDFDocument.ExtractText(0, imGearPDFDocument.Pages.Count, ImGearPDFContextFlags.PDF_ORDER, textFromPDF);
Console.WriteLine(System.Text.Encoding.GetEncoding(0).GetString(textFromPDF.ToArray()));
}
}
}
// Terminate PDF support once for each call to Initialize PDF support.
ImGearPDF.Terminate();
}
}
}