http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/core/com/itextpd f/text/pdf/DocumentFont.java?revision=4515&view=markup
> java.lang.NullPointerException > at com.itextpdf.text.pdf.DocumentFont.<init>(DocumentFont.java:114) 108 DocumentFont(PRIndirectReference refFont) { 109 encoding = ""; 110 fontSpecific = false; 111 this.refFont = refFont; 112 fontType = FONT_TYPE_DOCUMENT; 113 font = (PdfDictionary)PdfReader.getPdfObject(refFont); 114 PdfName baseFont = font.getAsName(PdfName.BASEFONT); <-- boom. That means PdfReader.getPdfObject(refFont) returned null. Having a look over there... http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/core/com/itextpd f/text/pdf/PdfReader.java?revision=4507&view=markup (lines 812 - 846, I'll let you look it up) If refFont == null, you get a null, and if if ref.getReader().getPdfObject(ref.getNumber) returns null, you get null (but that Should Not Happen). So someone passed in null. Which leads us up the call stack: > at com.itextpdf.text.pdf.CMapAwareDocumentFont.<init>(CMapAwareDocumentFont .java:79) 78 public CMapAwareDocumentFont(PRIndirectReference refFont) { 79 super(refFont); (I'll let you figure out the links too. Start at http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/core/com/itextpd f/text/pdf/ and work your way down from there). Again, looks like someone passed in a null to the constructor. > at > com.itextpdf.text.pdf.parser.PdfContentStreamProcessor$SetTextFont.invok e( > PdfContentStreamProcessor.java:591) (and I had to look at a previous revision of the file to get the line numbers to make sense: http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/core/com/itextpd f/text/pdf/parser/PdfContentStreamProcessor.java?revision=4410&view=mark up) 585 private static class SetTextFont implements ContentOperator{ 586 public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList<PdfObject> operands) { 587 PdfName fontResourceName = (PdfName)operands.get(0); 588 float size = ((PdfNumber)operands.get(1)).floatValue(); 589 590 PdfDictionary fontsDictionary = processor.resources.getAsDict(PdfName.FONT); 591 CMapAwareDocumentFont font = new CMapAwareDocumentFont((PRIndirectReference)fontsDictionary.get(fontResou rceName)); So fontsDictionary.get(fontResourceName) (in all probability) returned a null. Smells like a Bad PDF to me. May we see it? And hopefully folks will learn something from this byte-array-output-stream-of-consciousness debug session. In particular: 1) Use the Source, Luke. Reach out with your browser. 2) iText's source is available on the web at http://itext.svn.sourceforge.net/viewvc/itext/trunk/... 2.1) But adding the source to your classpath in Eclipse et al is better while you're debugging. Stepping into the code will TELL YOU whether something is null or not, instead of making an educated guess as I have here. --Mark Storer Senior Software Engineer Cardiff.com import legalese.Disclaimer; Disclaimer<Cardiff> DisCard = null; > -----Original Message----- > From: Ben Short [mailto:b...@benshort.co.uk] > Sent: Tuesday, June 15, 2010 1:36 PM > To: itext-questions@lists.sourceforge.net > Subject: [iText-questions] NPE while Extracting text > > Hi, > > I'm trying to use iText 5.0.2 to extract the text from a pdf file > using the following code... > > PdfReader reader = new PdfReader("C:/development/May.pdf"); > PdfReaderContentParser parser = new > PdfReaderContentParser(reader); > PrintWriter out = new PrintWriter(System.out); > TextExtractionStrategy strategy; > for (int i = 1; i <= reader.getNumberOfPages(); i++) { > strategy = parser.processContent(i, new > SimpleTextExtractionStrategy()); > out.println(strategy.getResultantText()); > } > > When I run this code I get the following exception. > > java.lang.NullPointerException > at com.itextpdf.text.pdf.DocumentFont.<init>(DocumentFont.java:114) > at > com.itextpdf.text.pdf.CMapAwareDocumentFont.<init>(CMapAwareDocumentFont .j > ava:79) > at > com.itextpdf.text.pdf.parser.PdfContentStreamProcessor$SetTextFont.invok e( > PdfContentStreamProcessor.java:591) > at > com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.invokeOperator(Pd fC > ontentStreamProcessor.java:226) > at > com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.processContent(Pd fC > ontentStreamProcessor.java:380) > at > com.itextpdf.text.pdf.parser.PdfReaderContentParser.processContent(PdfRe ad > erContentParser.java:41) > > I believe that this is something todo with the font not being available? > > I have used www.identifont.com and think that the font is Heldustry. > Should this not be available on my machine if acrobat reader can read > the file? > > Can anyone give me a some help making this text extraction work? > > Kind Regards > > Ben Short > > ------------------------------------------------------------------------ -- > ---- > ThinkGeek and WIRED's GeekDad team up for the Ultimate > GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the > lucky parental unit. See the prize list and enter to win: > http://p.sf.net/sfu/thinkgeek-promo > _______________________________________________ > iText-questions mailing list > iText-questions@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/itext-questions > > Buy the iText book: http://www.itextpdf.com/book/ > Check the site with examples before you ask questions: > http://www.1t3xt.info/examples/ > You can also search the keywords list: > http://1t3xt.info/tutorials/keywords/ > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 9.0.829 / Virus Database: 271.1.1/2937 - Release Date: 06/14/10 > 23:35:00 ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/