I've got a project that involves reading pdf files and it is turning out to be more difficult than I had anticipated. Is there a library I can use to convert the pdf to docx so I can use the OpenXml SDK to parse it?
2 Answers
AbleWord (for Windows):
AbleWord is a very capable word processing application that can read and write most popular document formats including PDF's. It is fully featured, supporting image formatting, tables, headers & footers and includes spell checking and print preview functions. Best of all it is totally free even for commercial use.
Instructions for convert PDF to Word (including docx) can be found here.
-
I'm looking for code libraries that I can do this with, not an application. I want the program to do it automatically, not require another step for the user to follow before parsing the data. Jun 22, 2018 at 14:45
-
@emsimpson92 You can execute it from your program and retrieve the result.– AFractJun 30, 2018 at 18:21
It appears you might achieve your requirement by parsing the contents of PDF using C#. If that's true, and what you need is mainly text, the following article discusses some free (and not so free) options for getting text from PDF: https://www.codeproject.com/Articles/12445/Converting-PDF-to-Text-in-C
If you don't simply need text, but require different contents of PDF like text, images and annotations, you might have to use a professional SDK such as LEADTOOLS. (Disclaimer: I am an employee of this library's vendor). The code to extract text is this:
StringBuilder sb;
sb = new StringBuilder();
PDFDocument document = new PDFDocument("filename.pdf");
PDFParsePagesOptions options = PDFParsePagesOptions.Objects;
document.ParsePages(options, 1, -1);
foreach (PDFDocumentPage page in document.Pages)
{
Console.WriteLine("Page #" + page.PageNumber.ToString() + " Started");
foreach (PDFObject obj in page.Objects)
{
if (obj.ObjectType == PDFObjectType.Text)
{
if (obj.TextProperties.IsEndOfLine)
sb.AppendLine(obj.Code.ToString());
else
sb.Append(obj.Code);
}
}
Console.WriteLine("Page #" + page.PageNumber.ToString() + " finished");
}
this.Text = "Finished";
textBox1.Text = sb.ToString();
Similar code (but using different flags), can be used to obtain images and other object types.
If you don't wish to parse the PDF but only convert it to DOCX, LEADTOOLS also has a DocumentConverter class that can do that.
The toolkit has a free evaluation edition that you can try before you decide whether to purchase or not.
exec()
something else?