I used the following code to read the content of html media item, check if it works for pdf media item:
Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem("/sitecore/media library/Files/yourfile");
Sitecore.Data.Items.Item mediaItem = new Sitecore.Data.Items.MediaItem(sampleItem);
using(var reader = new StreamReader(MediaManager.GetMedia(mediaItem).GetStream().Stream))
{
string text = reader.ReadToEnd();
}
If didn't work you may need something like adobe PDF IFilter:
Adobe PDF IFilter is a free downloadable Dynamic Link Library (DLL)
file that provides a bridge between a Microsoft indexing client and a
library of Adobe PDF files. It consists of code that understands the
Adobe Portable Document Format as well as code that can interface with
the indexing client. When an indexing client needs to index content
from PDF files, it will look in its registry for an appropriate DLL
and will find the Adobe PDF IFilter. Adobe PDF IFilter will return
text to the indexing client. The indexing client will then index the
results and return the appropriate results to the user.
Code example of using IFilter can be found here
or something like itextsharp, following is a code sample:
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
namespace PdfParser
{
public static class PdfTextExtractor
{
public static string pdfText(string path)
{
PdfReader reader = new PdfReader(path);
string text = string.Empty;
for(int page = 1; page <= reader.NumberOfPages; page++)
{
text += PdfTextExtractor.GetTextFromPage(reader,page);
}
reader.Close();
return text;
}
}
}