Indexing PDF documents with Lucene and Sitecore

by aboo bolaky 14. January 2010 06:32

Getting Lucene to index pdf document is a doddle, thanks to the document published on SDN. if you follow the instructions to the letter, you will be able to make Lucene index pdf documents in no time

HOWEVER, please be aware that you have to properly dispose the objects (to name a few... PDDocument and Ikvm.io.InputStreamWrapper objects) after you parsed the document(s).

If you forget to do so, you will soon notice that your temp folder (c:\windows\temp) will be filled with pdfbox temp files (e.g pdfbox124bb19809ftmp). In the worst case scenario, the C drive runs out of disk space => no website.

Original Code Published on SDN

private string ParsePDF(MediaItem mediaItem)
    {
        Stream stream = mediaItem.GetMediaStream();
        ikvm.io.InputStreamWrapper wrapper = new ikvm.io.InputStreamWrapper(stream);
        PDDocument doc = PDDocument.load(wrapper);
        PDFTextStripper stripper = new PDFTextStripper();
        return stripper.getText(doc);

    }

Revised Code

private string ParsePDF(MediaItem mediaItem)
    {
        PDDocument doc = null;
        ikvm.io.InputStreamWrapper wrapper = null;

        try
        {
            Stream stream = mediaItem.GetMediaStream();
            wrapper = new ikvm.io.InputStreamWrapper(stream);
            doc = PDDocument.load(wrapper);
            PDFTextStripper stripper = new PDFTextStripper();
            return stripper.getText(doc);
        }
        catch (Exception Ex)
        {
            //[some logging here] ..
            return String.Empty;
        }
        finally
        {
            if ((doc != null) && (wrapper != null))
            {
                doc.close();
                wrapper.close();
            }
        }
    }


 

Rebuild the index and have a good night sleep :)

Tags:

Playing God with Windows 7

by aboo bolaky 7. January 2010 08:52

This is going to be a quick one.

To enable "GodMode" on Windows 7, create a folder on your desktop and rename it to the following:

GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}

The icon for the folder automatically changes to a "system-settings-like" icon. From there, you can basically manage EVERYTHING on your pc..

Go on...Give it a try.

Thanks Bro. 

Tags:

OS

Tag cloud

Flash Player 9 required.

About Me

I wish I could write something here..
//TODO: ElaborateMe