Aboo Bolaky

{.NET, C#, Sitecore ...} Free your mind...

Indexing PDF documents with Lucene and Sitecore

clock January 13, 2010 21:32 by author Aboo Bolaky

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

   1:  private string ParsePDF(MediaItem mediaItem)
   2:          {
   3:              Stream stream = mediaItem.GetMediaStream();
   4:              ikvm.io.InputStreamWrapper wrapper = new ikvm.io.InputStreamWrapper(stream);
   5:              PDDocument doc = PDDocument.load(wrapper);
   6:              PDFTextStripper stripper = new PDFTextStripper();
   7:              return stripper.getText(doc);
   8:          }

 

Revised Code

   1:  private string ParsePDF(MediaItem mediaItem)
   2:          {
   3:              PDDocument doc = null;
   4:              ikvm.io.InputStreamWrapper wrapper = null;
   5:              try
   6:              {
   7:   
   8:                  Stream stream = mediaItem.GetMediaStream();
   9:                  wrapper = new ikvm.io.InputStreamWrapper(stream);
  10:                  doc = PDDocument.load(wrapper);
  11:                  PDFTextStripper stripper = new PDFTextStripper();
  12:                  
  13:                  return stripper.getText(doc);
  14:              }
  15:              catch (Exception Ex)
  16:              {
  17:                  //[some logging here] ..
  18:                  return String.Empty;
  19:              }
  20:              finally
  21:              {
  22:                  if ((doc != null) && (wrapper != null))
  23:                  {
  24:                      doc.close();
  25:                      wrapper.close();
  26:                  }
  27:              }
  28:          }

 

Rebuild the index and have a good night sleep :)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Playing God with Windows 7

clock January 6, 2010 23:52 by author Aboo Bolaky

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. 

 

Currently rated 3.3 by 6 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


A b o u t M e

Annoying

Brilliant

Open and

Objective

in every way..
Only Human >>
 
"First learn computer science and all the theory.

Next develop a programming style.

Then forget all that and just hack." Carrette (1990)