protected void parseTag(PdfMcr kid) { int mcid = kid.getMcid(); PdfDictionary pageDic = kid.getPageObject(); String tagContent = ""; if (mcid != -1) { if (!parsedTags.containsKey(pageDic)) { MarkedContentEventListener listener = new MarkedContentEventListener(); PdfCanvasProcessor processor = new PdfCanvasProcessor(listener); PdfPage page = document.getPage(pageDic); processor.processContent(page.getContentBytes(), page.getResources()); parsedTags.put(pageDic, listener.getMcidContent()); } if (parsedTags.get(pageDic).containsKey(mcid)) tagContent = parsedTags.get(pageDic).get(mcid); } else { PdfObjRef objRef = (PdfObjRef) kid; PdfObject object = objRef.getReferencedObject(); if (object.isDictionary()) { PdfName subtype = ((PdfDictionary) object).getAsName(PdfName.Subtype); tagContent = subtype.toString(); } } try { out.write(escapeXML(tagContent, true)); } catch (java.io.IOException e) { throw new com.itextpdf.io.IOException(com.itextpdf.io.IOException.UnknownIOException, e); } }
/** * Processes PDF syntax. * * <strong>Note:</strong> If you re-use a given {@link PdfCanvasProcessor}, you must call {@link PdfCanvasProcessor#reset()} * * @param page the page to process */ public void processPageContent(PdfPage page) { initClippingPath(page); ParserGraphicsState gs = getGraphicsState(); eventOccurred(new ClippingPathInfo(gs, gs.getClippingPath(), gs.getCtm()), EventType.CLIP_PATH_CHANGED); processContent(page.getContentBytes(), page.getResources()); }
/** * Copies page as FormXObject to the specified document. * * @param toDocument a document to copy to. * @return copied {@link PdfFormXObject} object. */ public PdfFormXObject copyAsFormXObject(PdfDocument toDocument) throws IOException { PdfFormXObject xObject = new PdfFormXObject(getCropBox()); List<PdfName> excludedKeys = new ArrayList<>(Arrays.asList(PdfName.MediaBox, PdfName.CropBox, PdfName.Contents) ); excludedKeys.addAll(this.excludedKeys); PdfDictionary dictionary = getPdfObject().copyTo(toDocument, excludedKeys, true); xObject.getPdfObject().getOutputStream().write(getContentBytes()); xObject.getPdfObject().mergeDifferent(dictionary); //Copy inherited resources if (!xObject.getPdfObject().containsKey(PdfName.Resources)) { PdfObject copyResource = getResources().getPdfObject().copyTo(toDocument, true); xObject.getPdfObject().put(PdfName.Resources, copyResource); } return xObject; }
/** * Creates form XObject from page content. * The page shall be from the document, to which FormXObject will be added. * * @param page an instance of {@link PdfPage} */ public PdfFormXObject(PdfPage page) { this(page.getCropBox()); getPdfObject().getOutputStream().writeBytes(page.getContentBytes()); resources = new PdfResources((PdfDictionary) page.getResources().getPdfObject().clone()); getPdfObject().put(PdfName.Resources, resources.getPdfObject()); }