List of usage examples for com.itextpdf.text.pdf PdfReader getPdfObjectRelease
public PdfObject getPdfObjectRelease(final int idx)
From source file:de.offis.health.icardea.cied.pdf.extractor.PDFiText5Extractor.java
License:GNU General Public License
@SuppressWarnings("unchecked") public java.util.List getBookmarkTitlesAsText() { java.util.List bookmarkContent = null; if (pdfReader != null) { //bookmarkContent = SimpleBookmark.getBookmark(pdfReader); PdfDictionary catalog = pdfReader.getCatalog(); if (catalog != null) { PdfObject rootPdfObject = PdfReader.getPdfObjectRelease(catalog.get(PdfName.OUTLINES)); if (rootPdfObject != null && rootPdfObject.isDictionary()) { PdfDictionary rootOutlinesPdfDictionary = (PdfDictionary) rootPdfObject; /*/*from www . j a va2s .c o m*/ * If it doesn't exist create the List and populate it, * otherwise just return the already existing List. */ if (bookmarkTextList == null) { bookmarkTextList = new ArrayList<String>(); // Populate the List populateBookmarkTextList(rootOutlinesPdfDictionary, ""); } // end if } } // end if } return bookmarkContent; }
From source file:de.offis.health.icardea.cied.pdf.extractor.PDFiText5Extractor.java
License:GNU General Public License
/** * This method will populate the text bookmark list. * /* w w w. j a v a2 s . com*/ * @param rootOutlinesPdfDictionary The node element for the bookmark item. * @param indentionString The base indention string to be used. */ @SuppressWarnings("unchecked") private void populateBookmarkTextList(PdfDictionary rootOutlinesPdfDictionary, String indentionString) { PdfDictionary outlineItemPdfDictionary = (PdfDictionary) PdfReader .getPdfObjectRelease(rootOutlinesPdfDictionary.get(PdfName.FIRST)); while (outlineItemPdfDictionary != null) { PdfString bookmarkTitle = (PdfString) PdfReader .getPdfObjectRelease(outlineItemPdfDictionary.get(PdfName.TITLE)); bookmarkTextList.add(indentionString + bookmarkTitle.toUnicodeString()); logger.trace(indentionString + bookmarkTitle.toUnicodeString()); /* * Recursive call to fill List */ populateBookmarkTextList(outlineItemPdfDictionary, indentionString + bookmarkIndentionString()); /* * Get next outline item */ outlineItemPdfDictionary = (PdfDictionary) PdfReader .getPdfObjectRelease(outlineItemPdfDictionary.get(PdfName.NEXT)); } // end while }
From source file:pl.edu.icm.cermine.structure.ITextCharacterExtractor.java
License:Open Source License
/** * Processes PDF's fonts dictionary. During the process alternative names * of Standard 14 Fonts are changed to the standard ones, provided that * the font definition doesn't include Widths array. * * Font dictionary in PDF file often includes an array of individual glyphs' widths. * Widths array is always required except for the Standard 14 Fonts, which widths * are kept by iText itself. Unfortunately, if the font uses alternative name instead of * standard one (see PDF Reference 1.7, table H.3), iText doesn't recognize the font as * one of the Standard 14 Fonts, and is unable to determine glyphs widths. In such cases * this method will change alternative names to standard ones before PDF's parsing process *//*from w ww .j av a 2 s .c o m*/ private void processAlternativeFontNames(PdfDictionary resources) { if (resources == null) { return; } PdfDictionary fontsDictionary = resources.getAsDict(PdfName.FONT); if (fontsDictionary == null) { return; } for (PdfName pdfFontName : fontsDictionary.getKeys()) { if (!(fontsDictionary.get(pdfFontName) instanceof PRIndirectReference)) { return; } PRIndirectReference indRef = (PRIndirectReference) fontsDictionary.get(pdfFontName); if (!(PdfReader.getPdfObjectRelease(indRef) instanceof PdfDictionary)) { return; } PdfDictionary fontDictionary = (PdfDictionary) PdfReader.getPdfObjectRelease(indRef); PdfName baseFont = fontDictionary.getAsName(PdfName.BASEFONT); if (baseFont != null) { String fontName = PdfName.decodeName(baseFont.toString()); if (fontDictionary.getAsArray(PdfName.WIDTHS) == null && ALT_TO_STANDART_FONTS.containsKey(fontName)) { fontDictionary.put(PdfName.BASEFONT, ALT_TO_STANDART_FONTS.get(fontName)); } } } }