private void checkPage(PdfPage page) { PdfDictionary pageDict = page.getPdfObject(); if (isAlreadyChecked(pageDict)) return; checkPageObject(pageDict, page.getResources().getPdfObject()); PdfDictionary pageResources = page.getResources().getPdfObject(); checkResources(pageResources); checkAnnotations(pageDict); checkPageSize(pageDict); int contentStreamCount = page.getContentStreamCount(); for (int j = 0; j < contentStreamCount; ++j) { checkedObjects.add(page.getContentStream(j)); } }
private void checkPage(PdfPage page) { PdfDictionary pageDict = page.getPdfObject(); if (isAlreadyChecked(pageDict)) return; checkPageObject(pageDict, page.getResources().getPdfObject()); PdfDictionary pageResources = page.getResources().getPdfObject(); checkResources(pageResources); checkAnnotations(pageDict); checkPageSize(pageDict); int contentStreamCount = page.getContentStreamCount(); for (int j = 0; j < contentStreamCount; ++j) { checkedObjects.add(page.getContentStream(j)); } }
@Override public void handleEvent(Event event) { PdfDocumentEvent docEvent = (PdfDocumentEvent) event; PdfDocument pdfDoc = docEvent.getDocument(); PdfPage page = docEvent.getPage(); PdfCanvas canvas = new PdfCanvas(page.newContentStreamBefore(), page.getResources(), pdfDoc); Rectangle area = page.getPageSize(); new Canvas(canvas, pdfDoc, area) .add(images.get(offset)); offset++; } }
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); } }
private void flushResourcesContentStreams() { flushResourcesContentStreams(getResources().getPdfObject()); PdfArray annots = getAnnots(false); if (annots != null) { for (int i = 0; i < annots.size(); ++i) { PdfDictionary apDict = annots.getAsDictionary(i).getAsDictionary(PdfName.AP); if (apDict != null) { flushAppearanceStreams(apDict); } } } }
/** * 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()); }
/** * Convenience method for fast PdfCanvas creation by a certain page. * * @param page page to create canvas from. * @param wrapOldContent true to wrap all old content streams into q/Q operators so that the state of old * content streams would not affect the new one */ public PdfCanvas(PdfPage page, boolean wrapOldContent) { this(getPageStream(page), page.getResources(), page.getDocument()); if (wrapOldContent) { // Wrap old content in q/Q in order not to get unexpected results because of the CTM page.newContentStreamBefore().getOutputStream().writeBytes(ByteUtils.getIsoBytes("q\n")); contentStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("Q\n")); } if (page.getRotation() != 0 && page.isIgnorePageRotationForContent() && (wrapOldContent || !page.isPageRotationInverseMatrixWritten())) { applyRotation(page); page.setPageRotationInverseMatrixWritten(); } }
PdfObject pageResources = page.getResources().getPdfObject(); if (xObjectResources != null && pageResources != null && xObjectResources == pageResources) {
PdfObject pageResources = page.getResources().getPdfObject(); if (xObjectResources != null && pageResources != null && xObjectResources == pageResources) {
private void copyInheritedProperties(PdfPage copyPdfPage, PdfDocument pdfDocument) { if (copyPdfPage.getPdfObject().get(PdfName.Resources) == null) { PdfObject copyResource = pdfDocument.getWriter().copyObject(getResources().getPdfObject(), pdfDocument, false); copyPdfPage.getPdfObject().put(PdfName.Resources, copyResource); } if (copyPdfPage.getPdfObject().get(PdfName.MediaBox) == null) { //media box shall be in any case copyPdfPage.setMediaBox(getMediaBox()); } if (copyPdfPage.getPdfObject().get(PdfName.CropBox) == null) { //original pdfObject don't have CropBox, otherwise copyPdfPage will contain it PdfArray cropBox = (PdfArray) getInheritedValue(PdfName.CropBox, PdfObject.ARRAY); //crop box is optional, we shall not set default value. if (cropBox != null) { copyPdfPage.put(PdfName.CropBox, cropBox.copyTo(pdfDocument)); } } if (copyPdfPage.getPdfObject().get(PdfName.Rotate) == null) { //original pdfObject don't have Rotate, otherwise copyPdfPage will contain it PdfNumber rotate = (PdfNumber) getInheritedValue(PdfName.Rotate, PdfObject.NUMBER); //rotate is optional, we shall not set default value. if (rotate != null) { copyPdfPage.put(PdfName.Rotate, rotate.copyTo(pdfDocument)); } } }
getResources(); if (resources != null && resources.isModified() && !resources.isReadOnly()) { getPdfObject().put(PdfName.Resources, resources.getPdfObject());