Refine search
/** * This will get the transfer function of the /TR dictionary. * * @return The transfer function. According to the PDF specification, this is either a single * function (which applies to all process colorants) or an array of four functions (which apply * to the process colorants individually). The name Identity may be used to represent the * identity function. */ public COSBase getTransfer() { COSBase base = dict.getDictionaryObject(COSName.TR); if (base instanceof COSArray && ((COSArray) base).size() != 4) { return null; } return base; }
/** * This will take an COSArray of numbers and convert it to a float[]. * * @return This COSArray as an array of float numbers. */ public float[] toFloatArray() { float[] retval = new float[size()]; for (int i = 0; i < size(); i++) { COSBase base = getObject(i); retval[i] = base instanceof COSNumber ? ((COSNumber) base).floatValue() : 0; } return retval; }
/** * Returns the user properties. * * @return the user properties */ public List<PDUserProperty> getOwnerUserProperties() { COSArray p = (COSArray) this.getCOSObject() .getDictionaryObject(COSName.P); List<PDUserProperty> properties = new ArrayList<>(p.size()); for (int i = 0; i < p.size(); i++) { properties.add( new PDUserProperty((COSDictionary) p.getObject(i), this)); } return properties; }
/** * Returns the dictionary's "Doc" entry, that is, a map of key value pairs to be added to the document's JavaScript * name tree. * * @return Map of named "JavaScript" dictionaries. */ public Map<String, PDActionJavaScript> getDoc() { Map<String, PDActionJavaScript> map = new LinkedHashMap<>(); COSArray array = (COSArray) dictionary.getDictionaryObject(COSName.DOC); if (array == null) { return null; } for (int i = 0; i < array.size(); i++) { PDActionFactory.createAction((COSDictionary) array.getObject(i)); } return map; }
/** * This will get the transfer function of the /TR2 dictionary. * * @return The transfer function. According to the PDF specification, this is either a single * function (which applies to all process colorants) or an array of four functions (which apply * to the process colorants individually). The name Identity may be used to represent the * identity function, and the name Default denotes the transfer function that was in effect at * the start of the page. */ public COSBase getTransfer2() { COSBase base = dict.getDictionaryObject(COSName.TR2); if (base instanceof COSArray && ((COSArray) base).size() != 4) { return null; } return base; }
private byte[] getDocumentIDBytes(COSArray documentIDArray) { //some documents may not have document id, see //test\encryption\encrypted_doc_no_id.pdf byte[] documentIDBytes; if( documentIDArray != null && documentIDArray.size() >= 1 ) { COSString id = (COSString)documentIDArray.getObject( 0 ); documentIDBytes = id.getBytes(); } else { documentIDBytes = new byte[0]; } return documentIDBytes; }
/** * Gets an array of strings. * * @param name the attribute name * @return the array of strings */ protected String[] getArrayOfString(String name) { COSBase v = this.getCOSObject().getDictionaryObject(name); if (v instanceof COSArray) { COSArray array = (COSArray) v; String[] strings = new String[array.size()]; for (int i = 0; i < array.size(); i++) { strings[i] = ((COSName) array.getObject(i)).getName(); } return strings; } return null; }
/** * Read out the byterange from the file. * * @return a integer array with the byterange */ public int[] getByteRange() { COSArray byteRange = (COSArray)dictionary.getDictionaryObject(COSName.BYTERANGE); int[] ary = new int[byteRange.size()]; for (int i = 0; i<ary.length;++i) { ary[i] = byteRange.getInt(i); } return ary; }
/** * Update the P reference to the new parent dictionary. * * @param kArray the kids array * @param newParent the new parent */ private void updateParentEntry(COSArray kArray, COSDictionary newParent) { for (int i = 0; i < kArray.size(); i++) { COSBase subEntry = kArray.getObject(i); if (subEntry instanceof COSDictionary) { COSDictionary dictEntry = (COSDictionary) subEntry; if (dictEntry.getDictionaryObject(COSName.P) != null) { dictEntry.setItem(COSName.P, newParent); } } } }
/** * Returns true if this page has contents. */ public boolean hasContents() { COSBase contents = page.getDictionaryObject(COSName.CONTENTS); if (contents instanceof COSStream) { return ((COSStream) contents).size() > 0; } else if (contents instanceof COSArray) { return ((COSArray) contents).size() > 0; } return false; }
/** * This will get the page for this destination. A page destination can either reference a page * (for a local destination) or a page number (when doing a remote destination to another PDF). * If this object is referencing by page number then this method will return null and * {@link #getPageNumber()} should be used. * * @return The page for this destination. */ public PDPage getPage() { PDPage retval = null; if( array.size() > 0 ) { COSBase page = array.getObject( 0 ); if( page instanceof COSDictionary ) { retval = new PDPage( (COSDictionary)page ); } } return retval; }
/** * Returns the content streams which make up this page. * * @return content stream iterator */ public Iterator<PDStream> getContentStreams() { List<PDStream> streams = new ArrayList<>(); COSBase base = page.getDictionaryObject(COSName.CONTENTS); if (base instanceof COSStream) { streams.add(new PDStream((COSStream) base)); } else if (base instanceof COSArray && ((COSArray) base).size() > 0) { COSArray array = (COSArray)base; for (int i = 0; i < array.size(); i++) { COSStream stream = (COSStream) array.getObject(i); streams.add(new PDStream(stream)); } } return streams.iterator(); }
/** * This will retrieve the line ending style for the end point, possible values shown in the LE_ constants section. * * @return The ending style for the end point, LE_NONE if missing, never null. */ public String getEndPointEndingStyle() { COSBase base = getCOSObject().getDictionaryObject(COSName.LE); if (base instanceof COSArray && ((COSArray) base).size() >= 2) { return ((COSArray) base).getName(1, PDAnnotationLine.LE_NONE); } return PDAnnotationLine.LE_NONE; }
/** * This will get the page number for this destination. A page destination can either reference a * page (for a local destination) or a page number (when doing a remote destination to another * PDF). If this object is referencing by page number then this method will return that number, * otherwise -1 will be returned. * * @return The zero-based page number for this destination. */ public int getPageNumber() { int retval = -1; if( array.size() > 0 ) { COSBase page = array.getObject( 0 ); if( page instanceof COSNumber ) { retval = ((COSNumber)page).intValue(); } } return retval; }
/** * Get the viewports. * * @return a list of viewports or null if there is no /VP entry. */ public List<PDViewportDictionary> getViewports() { COSBase base = page.getDictionaryObject(COSName.VP); if (!(base instanceof COSArray)) { return null; } COSArray array = (COSArray) base; List<PDViewportDictionary> viewports = new ArrayList<>(); for (int i = 0; i < array.size(); ++i) { COSBase base2 = array.getObject(i); if (base2 instanceof COSDictionary) { viewports.add(new PDViewportDictionary((COSDictionary) base2)); } else { LOG.warn("Array element " + base2 + " is skipped, must be a (viewport) dictionary"); } } return viewports; }
/** * This will retrieve the line ending style for the start point, possible values shown in the LE_ constants section. * * @return The ending style for the start point, LE_NONE if missing, never null. */ public String getStartPointEndingStyle() { COSBase base = getCOSObject().getDictionaryObject(COSName.LE); if (base instanceof COSArray && ((COSArray) base).size() >= 2) { return ((COSArray) base).getName(0, LE_NONE); } return LE_NONE; }
private static byte[] getBytesFromPacket(final COSArray cosArray) throws IOException { try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { for (int i = 1; i < cosArray.size(); i += 2) { COSBase cosObj = cosArray.getObject(i); if (cosObj instanceof COSStream) { baos.write(getBytesFromStream((COSStream) cosObj.getCOSObject())); } } return baos.toByteArray(); } }
/** * Get one or more disjoint paths that make this annotation. * * @return An array of arrays, each representing a stroked path. Each array shall be a series of * alternating horizontal and vertical coordinates. */ public float[][] getInkList() { COSBase base = getCOSObject().getDictionaryObject(COSName.INKLIST); if (base instanceof COSArray) { COSArray array = (COSArray) base; float[][] inkList = new float[array.size()][]; for (int i = 0; i < array.size(); ++i) { COSBase base2 = array.getObject(i); if (base2 instanceof COSArray) { inkList[i] = ((COSArray) array.getObject(i)).toFloatArray(); } else { inkList[i] = new float[0]; } } return inkList; } return new float[0][0]; }
/** * This will retrieve the line ending style for the start point, possible values shown in the LE_ constants section. * * @return The ending style for the start point, LE_NONE if missing, never null. */ public String getStartPointEndingStyle() { COSBase base = getCOSObject().getDictionaryObject(COSName.LE); if (base instanceof COSArray && ((COSArray) base).size() >= 2) { return ((COSArray) base).getName(0, PDAnnotationLine.LE_NONE); } return PDAnnotationLine.LE_NONE; }