PDDocument doc = PDDocument.load("C:/mydoc3.pdf"); List<PDPage> pages = doc.getDocumentCatalog().getAllPages(); for(PDPage page:pages){ Map<String,PDFont> pageFonts=page.getResources().getFonts(); }
protected void validateResources(PreflightContext context, PDPage page) throws ValidationException { ContextHelper.validateElement(context, page.getResources(), RESOURCES_PROCESS); }
/** * 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()); }
@Override protected void endPage(PDPage page) throws IOException { try { writeParagraphEnd(); try { extractImages(page.getResources(), new HashSet<COSBase>()); } catch (IOException e) { handleCatchableIOE(e); } super.endPage(page); } catch (SAXException e) { throw new IOException("Unable to end a page", e); } catch (IOException e) { exceptions.add(e); } }
/** * 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; }
private boolean hasBlendMode(PDPage page) { // check the current resources for blend modes PDResources resources = page.getResources(); if (resources == null) { return false; } for (COSName name : resources.getExtGStateNames()) { PDExtendedGraphicsState extGState = resources.getExtGState(name); if (extGState == null) { // can happen if key exists but no value // see PDFBOX-3950-23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf continue; } BlendMode blendMode = extGState.getBlendMode(); if (blendMode != BlendMode.NORMAL) { return true; } } return false; }
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 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"); }
/** * Interface to start processing a new page. * * @param page The page that is about to get processed. * * @throws IOException If there is an error creating the new document. */ protected void processPage(PDPage page) throws IOException { createNewDocumentIfNecessary(); PDPage imported = getDestinationDocument().importPage(page); imported.setResources(page.getResources()); // remove page links to avoid copying not needed resources processAnnotations(imported); }
return; if (tag == null || getPage().getResources() == null) PDPropertyList propertyList = getPage().getResources().getProperties(tag); if (propertyList instanceof PDOptionalContentGroup)
PDResources resources = page.getResources();
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; }
PDResources resources = page.getResources(); if (resources != null)
writeTokensToStream(newContents, newTokens); page.setContents(newContents); processResources(page.getResources());
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()); }
public void run() throws IOException { PDPage page = getPage(); processPage(page); PDResources res = page.getResources(); for (COSName name : res.getExtGStateNames()) { PDSoftMask softMask = res.getExtGState(name).getSoftMask(); if (softMask != null) { PDTransparencyGroup group = softMask.getGroup(); if (group != null) { // PDFBOX-4327: without this line NPEs will occur res.getExtGState(name).copyIntoGraphicsState(getGraphicsState()); processSoftMask(group); } } } }
if (sourcePage.getResources() == null)
importedPage.setMediaBox(page.getMediaBox()); importedPage.setRotation(page.getRotation()); if (page.getResources() != null && !page.getCOSObject().containsKey(COSName.RESOURCES))
imported.setCropBox(page.getCropBox()); imported.setMediaBox(page.getMediaBox()); imported.setResources(page.getResources()); imported.setRotation(page.getRotation());
newPage.setMediaBox(page.getMediaBox()); newPage.setRotation(page.getRotation()); PDResources resources = page.getResources(); if (resources != null)