Java Code Examples for com.lowagie.text.pdf.PdfDictionary#getAsDict()
The following examples show how to use
com.lowagie.text.pdf.PdfDictionary#getAsDict() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfContentStreamProcessor.java From gcs with Mozilla Public License 2.0 | 6 votes |
@Override public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfName dictionaryName = (PdfName) operands.get(0); PdfDictionary extGState = processor.resources.getAsDict(PdfName.EXTGSTATE); if (extGState == null) { throw new IllegalArgumentException("Resources do not contain ExtGState entry. Unable to process operator " + operator); } PdfDictionary gsDic = extGState.getAsDict(dictionaryName); if (gsDic == null) { throw new IllegalArgumentException(dictionaryName + " is an unknown graphics state dictionary"); } // at this point, all we care about is the FONT entry in the GS dictionary PdfArray fontParameter = gsDic.getAsArray(PdfName.FONT); if (fontParameter != null) { CMapAwareDocumentFont font = new CMapAwareDocumentFont((PRIndirectReference) fontParameter.getPdfObject(0)); float size = fontParameter.getAsNumber(1).floatValue(); processor.gs().font = font; processor.gs().fontSize = size; } }
Example 2
Source File: PdfTextExtractor.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Gets the text from a page. * @param page the page number of the page * @return a String with the content as plain text (without PDF syntax) * @throws IOException */ public String getTextFromPage(int page) throws IOException { int totalPages = reader.getNumberOfPages(); if (totalPages < page) { throw new IOException("indicated page does not exists, requested page " + page + " document pages " + totalPages); } if (page <= 0) { throw new IOException("page number must be postive:" + page); } PdfDictionary pageDic = reader.getPageN(page); if (pageDic == null) { return ""; } PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES); extractionProcessor.processContent(getContentBytesForPage(page), resourcesDic); return extractionProcessor.getResultantText(); }
Example 3
Source File: PdfContentStreamProcessor.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) { PdfName dictionaryName = (PdfName) operands.get(0); PdfDictionary extGState = processor.resources.getAsDict(PdfName.EXTGSTATE); if (extGState == null) { throw new IllegalArgumentException( "Resources do not contain ExtGState entry. Unable to process operator " + operator); } PdfDictionary gsDic = extGState.getAsDict(dictionaryName); if (gsDic == null) { throw new IllegalArgumentException(dictionaryName + " is an unknown graphics state dictionary"); } // at this point, all we care about is the FONT entry in the GS dictionary PdfArray fontParameter = gsDic.getAsArray(PdfName.FONT); if (fontParameter != null) { CMapAwareDocumentFont font = new CMapAwareDocumentFont( (PRIndirectReference) fontParameter.getPdfObject(0)); float size = fontParameter.getAsNumber(1).floatValue(); processor.gs().font = font; processor.gs().fontSize = size; } }
Example 4
Source File: Prd5873Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
private void runTest(MasterReport report) throws ResourceException, ReportProcessingException, IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); PdfReportUtil.createPDF(report, bout); PdfReader reader = new PdfReader(bout.toByteArray()); printPdfPage(reader); final PdfDictionary pageN = reader.getPageN(1); final PdfDictionary asDict = pageN.getAsDict(PdfName.RESOURCES); final byte[] pageContent = reader.getPageContent(1); PdfValidator pv = new PdfValidator(); pv.processContent(pageContent, asDict); }
Example 5
Source File: PdfTextExtractor.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Gets the text from a page. * @param page the page number of the page * @return a String with the content as plain text (without PDF syntax) * @throws IOException */ public String getTextFromPage(int page) throws IOException { PdfDictionary pageDic = reader.getPageN(page); PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES); extractionProcessor.processContent(getContentBytesForPage(page), resourcesDic); return extractionProcessor.getResultantText(); }
Example 6
Source File: PdfContentStreamProcessorTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
private void processBytes(final byte[] pdfBytes, final int pageNumber) throws IOException { final PdfReader pdfReader = new PdfReader(pdfBytes); final PdfDictionary pageDictionary = pdfReader.getPageN(pageNumber); final PdfDictionary resourceDictionary = pageDictionary.getAsDict(PdfName.RESOURCES); final PdfObject contentObject = pageDictionary.get(PdfName.CONTENTS); final byte[] contentBytes = readContentBytes(contentObject); _processor.processContent(contentBytes, resourceDictionary); }
Example 7
Source File: ITextDocumentReader.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
@Override public Map<PdfSignatureDictionary, List<String>> extractSigDictionaries() { if (signatureDictionaryMap == null) { AcroFields acroFields = pdfReader.getAcroFields(); Map<PdfSignatureDictionary, List<String>> pdfDictionaries = new LinkedHashMap<>(); Map<Integer, PdfSigDictWrapper> pdfObjectDictMap = new LinkedHashMap<>(); Map<String, Item> allFields = acroFields.getAllFields(); List<String> names = acroFields.getSignedFieldNames(); LOG.info("{} signature field(s) found", names.size()); for (String name : names) { PdfDictionary pdfField = allFields.get(name).getMerged(0); int refNumber = pdfField.getAsIndirectObject(PdfName.V).getNumber(); PdfSigDictWrapper signature = pdfObjectDictMap.get(refNumber); if (signature == null) { try { PdfDict dictionary = new ITextPdfDict(pdfField.getAsDict(PdfName.V)); signature = new PdfSigDictWrapper(dictionary); } catch (Exception e) { LOG.warn("Unable to create a PdfSignatureDictionary for field with name '{}'", name, e); continue; } List<String> fieldNames = new ArrayList<>(); fieldNames.add(name); pdfDictionaries.put(signature, fieldNames); pdfObjectDictMap.put(refNumber, signature); } else { List<String> fieldNameList = pdfDictionaries.get(signature); fieldNameList.add(name); LOG.warn("More than one field refers to the same signature dictionary: {}!", fieldNameList); } } signatureDictionaryMap = pdfDictionaries; } return signatureDictionaryMap; }