Skip to content

Instantly share code, notes, and snippets.

Created November 19, 2017 09:39
What would you like to do?
Basic PDFExtractor for Azure Data Lake Analytics
using System.Collections.Generic;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using Microsoft.Analytics.Interfaces;
namespace PDFExtractor
[SqlUserDefinedExtractor(AtomicFileProcessing = true)]
public class PDFExtractor : IExtractor
public override IEnumerable<IRow> Extract(IUnstructuredReader input, IUpdatableRow output)
var reader = new PdfReader(input.BaseStream);
for (var page = 1; page <= reader.NumberOfPages; page++)
output.Set(0, page);
output.Set(1, ExtractText(reader, page));
yield return output.AsReadOnly();
public string ExtractText(PdfReader pdfReader, int pageNum)
var text = PdfTextExtractor.GetTextFromPage(pdfReader, pageNum, new LocationTextExtractionStrategy());
return text.Replace("\r", "\\r").Replace("\n", "\\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment