@SuppressWarnings("unchecked") public static void main_3(String[] args) throws IOException { PDDocument doc = PDDocument.load(iconFile); List<PDPage> pages = doc.getDocumentCatalog().getAllPages(); List<COSObject> objects = doc.getDocument().getObjects(); for (COSObject cosObject : objects) { COSBase cosbase = cosObject.getObject(); if (cosObject.getObject() instanceof COSStream) { COSStream cosstream = (COSStream) cosbase; COSBase filter = cosstream.getDictionaryObject(COSName.FILTER); COSBase subtype = cosstream.getDictionaryObject(COSName.SUBTYPE); if (subtype != null && subtype.equals(COSName.IMAGE)) { System.out.println(filter); InputStream filtered = cosstream.getFilteredStream(); // PDStream stream = new PDStream(costream); System.out.println(Hex.encodeHex(IOUtils.toByteArray(filtered))); } } } for (PDPage pdPage : pages) { PDResources resources = pdPage.getResources(); Map<String, PDXObject> images = resources.getXObjects(); Set<String> keys = images.keySet(); for (String key : keys) { PDXObject image = images.get(key); byte[] imgData = image.getPDStream().getByteArray(); System.out.println(Hex.encodeHex(imgData)); } } }
/** * Is the value changed? * * @param oldValue old value * @param newValue new value * @return <code>true</code> if the value is changed, <code>false</code> otherwise */ private boolean isValueChanged(COSBase oldValue, COSBase newValue) { if (oldValue == null) { return newValue != null; } return !oldValue.equals(newValue); }