// create pdf to text converter
PdfToTextConverter pdfToTextConverter = new PdfToTextConverter();
// set converter options
pdfToTextConverter.Layout = layout;
pdfToTextConverter.MarkPageBreaks = markPageBreaks;
pdfToTextConverter.AddHtmlMetaTags = addHtmlMetaTags;
pdfToTextConverter.UserPassword = userPassword;
// get output file path
string outFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(srcPdfFile),
System.IO.Path.GetFileNameWithoutExtension(srcPdfFile));
if (addHtmlMetaTags)
outFileName += ".html";
else
outFileName += ".txt";
// extract text from PDF
string extractedText = pdfToTextConverter.ConvertToText(srcPdfFile);
// write the resulted string into an output file in the working directory
using UTF-8 encoding
System.IO.File.WriteAllText(outFileName, extractedText, System.Text.Encoding.UTF8);
|