public static PDRectangle getPDRectangleForField(PDField field) { COSBase rectArray = field.getDictionary().getDictionaryObject("Rect"); PDRectangle pdrect = new PDRectangle(0, 0); if (rectArray instanceof COSArray) { pdrect = new PDRectangle((COSArray) rectArray); } else if (rectArray != null && rectArray.getCOSObject() instanceof COSArray) { pdrect = new PDRectangle((COSArray) rectArray.getCOSObject()); } return pdrect; }
@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)); } } }
/** * @inheritDoc * <p><b>Note:</b> while non-terminal fields <b>do</b> inherit field values, this method * returns the local value, without inheritance. */ @Override public String getValueAsString() { COSBase fieldValue = getCOSObject().getDictionaryObject(COSName.V); return fieldValue != null ? fieldValue.toString() : ""; }
/** * 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); }