@Override public void createImageFormResources() { PDResources imageFormResources = new PDResources(); pdfStructure.setImageFormResources(imageFormResources); LOG.info("Created image form resources"); }
@Override public void createInnerFormResource() { PDResources innerFormResources = new PDResources(); pdfStructure.setInnerFormResources(innerFormResources); LOG.info("Resources of another form (inner form - it will be inside holder form)" + "have been created"); }
@Override public void createHolderFormResources() { PDResources holderFormResources = new PDResources(); pdfStructure.setHolderFormResources(holderFormResources); LOG.info("Holder form resources have been created"); }
/** * Returns the optional resources of the type3 stream. * * @return the resources bound to be used when parsing the type3 stream */ public PDResources getResources() { if (resources == null) { COSBase base = dict.getDictionaryObject(COSName.RESOURCES); if (base instanceof COSDictionary) { this.resources = new PDResources((COSDictionary) base); } } return resources; }
/** * A dictionary containing any resources required by the page. */ @Override public PDResources getResources() { if (pageResources == null) { COSBase base = PDPageTree.getInheritableAttribute(page, COSName.RESOURCES); // note: it's an error for resources to not be present if (base instanceof COSDictionary) { pageResources = new PDResources((COSDictionary) base, resourceCache); } } return pageResources; }
/** * This will get the default resources for the AcroForm. * * @return The default resources or null if their is none. */ public PDResources getDefaultResources() { PDResources retval = null; COSBase base = dictionary.getDictionaryObject(COSName.DR); if (base instanceof COSDictionary) { retval = new PDResources((COSDictionary) base, document.getResourceCache()); } return retval; }
/** * This will get the resources for this pattern. * This will return null if no resources are available at this level. * @return The resources for this pattern. */ @Override public PDResources getResources() { PDResources retval = null; COSBase base = getCOSObject().getDictionaryObject(COSName.RESOURCES); if (base instanceof COSDictionary) { retval = new PDResources((COSDictionary) base); } return retval; }
/** * This will get the resources for this Form XObject. * This will return null if no resources are available. * * @return The resources for this Form XObject. */ @Override public PDResources getResources() { COSDictionary resources = getCOSObject().getCOSDictionary(COSName.RESOURCES); if (resources != null) { return new PDResources(resources, cache); } if (getCOSObject().containsKey(COSName.RESOURCES)) { // PDFBOX-4372 if the resource key exists but has nothing, return empty resources, // to avoid a self-reference (xobject form Fm0 contains "/Fm0 Do") // See also the mention of PDFBOX-1359 in PDFStreamEngine return new PDResources(); } return null; }
/** * Pushes the given stream's resources, returning the previous resources. */ private PDResources pushResources(PDContentStream contentStream) { // resource lookup: first look for stream resources, then fallback to the current page PDResources parentResources = resources; PDResources streamResources = contentStream.getResources(); if (streamResources != null) { resources = streamResources; } else if (resources != null) { // inherit directly from parent stream, this is not in the PDF spec, but the file from // PDFBOX-1359 does this and works in Acrobat } else { resources = currentPage.getResources(); } // resources are required in PDF if (resources == null) { resources = new PDResources(); } return parentResources; }
/** * Create a new PDPage content stream. * * @param document The document the page is part of. * @param sourcePage The page to write the contents to. * @param appendContent Indicates whether content will be overwritten, appended or prepended. * @param compress Tell if the content stream should compress the page contents. * @param resetContext Tell if the graphic context should be reset. This is only relevant when * the appendContent parameter is set to {@link AppendMode#APPEND}. You should use this when * appending to an existing stream, because the existing stream may have changed graphic * properties (e.g. scaling, rotation). * @throws IOException If there is an error writing to the page contents. */ public PDPageContentStream(PDDocument document, PDPage sourcePage, AppendMode appendContent, boolean compress, boolean resetContext) throws IOException { this(document, sourcePage, appendContent, compress, resetContext, new PDStream(document), sourcePage.getResources() != null ? sourcePage.getResources() : new PDResources()); }
private void overlayPage(PDPage page, LayoutPage layoutPage, COSArray array) throws IOException { PDResources resources = page.getResources(); if (resources == null) { resources = new PDResources(); page.setResources(resources); } COSName xObjectId = createOverlayXObject(page, layoutPage, layoutPage.overlayContentStream); array.add(createOverlayStream(page, layoutPage, xObjectId)); }
private PDAppearanceContentStream getAppearanceEntryAsContentStream( PDAppearanceEntry appearanceEntry, boolean compress) throws IOException { PDAppearanceStream appearanceStream = appearanceEntry.getAppearanceStream(); setTransformationMatrix(appearanceStream); // ensure there are resources PDResources resources = appearanceStream.getResources(); if (resources == null) { resources = new PDResources(); appearanceStream.setResources(resources); } return new PDAppearanceContentStream(appearanceStream, compress); }
private COSName createOverlayXObject(PDPage page, LayoutPage layoutPage, COSStream contentStream) { PDFormXObject xobjForm = new PDFormXObject(contentStream); xobjForm.setResources(new PDResources(layoutPage.overlayResources)); xobjForm.setFormType(1); xobjForm.setBBox( layoutPage.overlayMediaBox.createRetranslatedRectangle()); xobjForm.setMatrix(new AffineTransform()); PDResources resources = page.getResources(); return resources.add(xobjForm, "OL"); }
/** * Constructor. * @param fontName COSName instance, Font name in the fonts dictionary. * @param dictionary COSDictionary instance for resources which resides the font. */ public FontEncodingPaneController(COSName fontName, COSDictionary dictionary) { PDResources resources = new PDResources(dictionary); try { PDFont font = resources.getFont(fontName); if (font instanceof PDType3Font) { fontPane = new Type3Font((PDType3Font) font, resources); } else if (font instanceof PDSimpleFont) { fontPane = new SimpleFont((PDSimpleFont) font); } else if (font instanceof PDType0Font) { fontPane = new Type0Font(((PDType0Font) font).getDescendantFont(), (PDType0Font) font); } } catch (IOException e) { e.printStackTrace(); } }
private Map<Integer,LayoutPage> getLayoutPages(PDDocument doc) throws IOException { int numberOfPages = doc.getNumberOfPages(); Map<Integer,LayoutPage> layoutPages = new HashMap<>(numberOfPages); for (int i=0;i<numberOfPages;i++) { PDPage page = doc.getPage(i); COSBase contents = page.getCOSObject().getDictionaryObject(COSName.CONTENTS); PDResources resources = page.getResources(); if (resources == null) { resources = new PDResources(); } layoutPages.put(i, new LayoutPage(page.getMediaBox(), createCombinedContentStream(contents), resources.getCOSObject())); } return layoutPages; }
@Override public void createBackgroundLayerForm(PDResources innerFormResource, PDRectangle bbox) throws IOException { // create blank n0 background layer form PDFormXObject n0Form = new PDFormXObject(pdfStructure.getTemplate().getDocument().createCOSStream()); n0Form.setBBox(bbox); n0Form.setResources(new PDResources()); n0Form.setFormType(1); innerFormResource.put(COSName.getPDFName("n0"), n0Form); LOG.info("Created background layer form"); }
/** * Creates a new tiling pattern. */ public PDTilingPattern() { super(new COSStream()); getCOSObject().setName(COSName.TYPE, COSName.PATTERN.getName()); getCOSObject().setInt(COSName.PATTERN_TYPE, PDAbstractPattern.TYPE_TILING_PATTERN); // Resources required per PDF specification; when missing, pattern is not displayed in Adobe Reader setResources(new PDResources()); }
/** * Copies any needed resources from the document’s DR dictionary into the stream’s Resources * dictionary. Resources with the same name shall be left intact. */ void copyNeededResourcesTo(PDAppearanceStream appearanceStream) throws IOException { // make sure we have resources PDResources streamResources = appearanceStream.getResources(); if (streamResources == null) { streamResources = new PDResources(); appearanceStream.setResources(streamResources); } if (streamResources.getFont(getFontName()) == null) { streamResources.put(fontName, getFont()); } // todo: other kinds of resource... } }
private LayoutPage getLayoutPage(PDDocument doc) throws IOException { PDPage page = doc.getPage(0); COSBase contents = page.getCOSObject().getDictionaryObject(COSName.CONTENTS); PDResources resources = page.getResources(); if (resources == null) { resources = new PDResources(); } return new LayoutPage(page.getMediaBox(), createCombinedContentStream(contents), resources.getCOSObject()); }
final PDResources resources = new PDResources(); acroForm.setDefaultResources(resources); final String fontName = resources.add(formFont).getName();