Java Code Examples for org.apache.pdfbox.cos.COSName#getName()
The following examples show how to use
org.apache.pdfbox.cos.COSName#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PDInlineImage.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Returns a list of filters applied to this stream, or null if there are none. * * @return a list of filters applied to this stream */ // TODO return an empty list if there are none? public List<String> getFilters() { List<String> names = null; COSBase filters = parameters.getDictionaryObject(COSName.F, COSName.FILTER); if (filters instanceof COSName) { COSName name = (COSName) filters; names = new COSArrayList<String>(name.getName(), name, parameters, COSName.FILTER); } else if (filters instanceof COSArray) { names = COSArrayList.convertCOSNameCOSArrayToList((COSArray) filters); } return names; }
Example 2
Source File: CryptFilter.java From gcs with Mozilla Public License 2.0 | 6 votes |
@Override protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters) throws IOException { COSName encryptionName = (COSName) parameters.getDictionaryObject(COSName.NAME); if(encryptionName == null || encryptionName.equals(COSName.IDENTITY)) { // currently the only supported implementation is the Identity crypt filter Filter identityFilter = new IdentityFilter(); identityFilter.encode(input, encoded, parameters); } else { throw new IOException("Unsupported crypt filter " + encryptionName.getName()); } }
Example 3
Source File: PDSeedValue.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * <p>(Optional, PDF 1.7) An array of names indicating acceptable digest * algorithms to use when signing. The value shall be one of <b>SHA1</b>, * <b>SHA256</b>, <b>SHA384</b>, <b>SHA512</b>, <b>RIPEMD160</b>. The default * value is implementation-specific.</p> * * <p>This property is only applicable if the digital credential signing contains RSA * public/privat keys</p> * * @param digestMethod is a list of possible names of the digests, that should be * used for signing. */ public void setDigestMethod(List<COSName> digestMethod) { // integrity check for ( COSName cosName : digestMethod ) { if (!(cosName.equals(COSName.DIGEST_SHA1) || cosName.equals(COSName.DIGEST_SHA256) || cosName.equals(COSName.DIGEST_SHA384) || cosName.equals(COSName.DIGEST_SHA512) || cosName.equals(COSName.DIGEST_RIPEMD160))) { throw new IllegalArgumentException("Specified digest " + cosName.getName() + " isn't allowed."); } } dictionary.setItem(COSName.DIGEST_METHOD, COSArrayList.converterToCOSArray(digestMethod)); }
Example 4
Source File: PDVisibleSigBuilder.java From gcs with Mozilla Public License 2.0 | 6 votes |
@Override public void injectAppearanceStreams(PDStream holderFormStream, PDStream innerFormStream, PDStream imageFormStream, COSName imageFormName, COSName imageName, COSName innerFormName, PDVisibleSignDesigner properties) throws IOException { // Use width and height of BBox as values for transformation matrix. int width = (int) this.getStructure().getFormatterRectangle().getWidth(); int height = (int) this.getStructure().getFormatterRectangle().getHeight(); String imgFormContent = "q " + width + " 0 0 " + height + " 0 0 cm /" + imageName.getName() + " Do Q\n"; String holderFormContent = "q 1 0 0 1 0 0 cm /" + innerFormName.getName() + " Do Q\n"; String innerFormContent = "q 1 0 0 1 0 0 cm /n0 Do Q q 1 0 0 1 0 0 cm /" + imageFormName.getName() + " Do Q\n"; appendRawCommands(pdfStructure.getHolderFormStream().createOutputStream(), holderFormContent); appendRawCommands(pdfStructure.getInnerFormStream().createOutputStream(), innerFormContent); appendRawCommands(pdfStructure.getImageFormStream().createOutputStream(), imgFormContent); LOG.info("Injected appearance stream to pdf"); }
Example 5
Source File: PDCheckBox.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Get the value which sets the check box to the On state. * * <p>The On value should be 'Yes' but other values are possible * so we need to look for that. On the other hand the Off value shall * always be 'Off'. If not set or not part of the normal appearance keys * 'Off' is the default</p> * * @return the value setting the check box to the On state. * If an empty string is returned there is no appearance definition. */ public String getOnValue() { PDAnnotationWidget widget = this.getWidgets().get(0); PDAppearanceDictionary apDictionary = widget.getAppearance(); String onValue = ""; if (apDictionary != null) { PDAppearanceEntry normalAppearance = apDictionary.getNormalAppearance(); if (normalAppearance != null) { Set<COSName> entries = normalAppearance.getSubDictionary().keySet(); for (COSName entry : entries) { if (COSName.Off.compareTo(entry) != 0) { onValue = entry.getName(); } } } } return onValue; }
Example 6
Source File: PDButton.java From gcs with Mozilla Public License 2.0 | 6 votes |
private String getOnValueForWidget(PDAnnotationWidget widget) { PDAppearanceDictionary apDictionary = widget.getAppearance(); if (apDictionary != null) { PDAppearanceEntry normalAppearance = apDictionary.getNormalAppearance(); if (normalAppearance != null) { Set<COSName> entries = normalAppearance.getSubDictionary().keySet(); for (COSName entry : entries) { if (COSName.Off.compareTo(entry) != 0) { return entry.getName(); } } } } return ""; }
Example 7
Source File: PDStream.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * This will get the list of filters that are associated with this stream. * Or null if there are none. * * @return A list of all encoding filters to apply to this stream. */ public List<String> getFileFilters() { List<String> retval = null; COSBase filters = stream.getDictionaryObject(COSName.F_FILTER); if (filters instanceof COSName) { COSName name = (COSName) filters; retval = new COSArrayList<String>(name.getName(), name, stream, COSName.F_FILTER); } else if (filters instanceof COSArray) { retval = COSArrayList .convertCOSNameCOSArrayToList((COSArray) filters); } return retval; }
Example 8
Source File: PDFontFactory.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Creates a new PDCIDFont instance with the appropriate subclass. * * @param dictionary descendant font dictionary * @return a PDCIDFont instance, based on the SubType entry of the dictionary * @throws IOException if something goes wrong */ static PDCIDFont createDescendantFont(COSDictionary dictionary, PDType0Font parent) throws IOException { COSName type = dictionary.getCOSName(COSName.TYPE, COSName.FONT); if (!COSName.FONT.equals(type)) { throw new IllegalArgumentException("Expected 'Font' dictionary but found '" + type.getName() + "'"); } COSName subType = dictionary.getCOSName(COSName.SUBTYPE); if (COSName.CID_FONT_TYPE0.equals(subType)) { return new PDCIDFontType0(dictionary, parent); } else if (COSName.CID_FONT_TYPE2.equals(subType)) { return new PDCIDFontType2(dictionary, parent); } else { throw new IOException("Invalid font type: " + type); } }
Example 9
Source File: PDType0Font.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Fetches the corresponding UCS2 CMap if the font's CMap is predefined. */ private void fetchCMapUCS2() throws IOException { // if the font is composite and uses a predefined cmap (excluding Identity-H/V) // or whose descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or // Adobe-Korea1 character collection: COSName name = dict.getCOSName(COSName.ENCODING); if (isCMapPredefined && !(name == COSName.IDENTITY_H || name == COSName.IDENTITY_V) || isDescendantCJK) { // a) Map the character code to a CID using the font's CMap // b) Obtain the ROS from the font's CIDSystemInfo // c) Construct a second CMap name by concatenating the ROS in the format "R-O-UCS2" // d) Obtain the CMap with the constructed name // e) Map the CID according to the CMap from step d), producing a Unicode value // todo: not sure how to interpret the PDF spec here, do we always override? or only when Identity-H/V? String strName = null; if (isDescendantCJK) { strName = descendantFont.getCIDSystemInfo().getRegistry() + "-" + descendantFont.getCIDSystemInfo().getOrdering() + "-" + descendantFont.getCIDSystemInfo().getSupplement(); } else if (name != null) { strName = name.getName(); } // try to find the corresponding Unicode (UC2) CMap if (strName != null) { CMap prdCMap = CMapManager.getPredefinedCMap(strName); String ucs2Name = prdCMap.getRegistry() + "-" + prdCMap.getOrdering() + "-UCS2"; cMapUCS2 = CMapManager.getPredefinedCMap(ucs2Name); } } }
Example 10
Source File: PDDefaultAppearanceString.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Process the set font and font size operator. * * @param operands the font name and size * @throws IOException in case there are missing operators or the font is not within the resources */ private void processSetFont(List<COSBase> operands) throws IOException { if (operands.size() < 2) { throw new IOException("Missing operands for set font operator " + Arrays.toString(operands.toArray())); } COSBase base0 = operands.get(0); COSBase base1 = operands.get(1); if (!(base0 instanceof COSName)) { return; } if (!(base1 instanceof COSNumber)) { return; } COSName fontName = (COSName) base0; PDFont font = defaultResources.getFont(fontName); float fontSize = ((COSNumber) base1).floatValue(); // todo: handle cases where font == null with special mapping logic (see PDFBOX-2661) if (font == null) { throw new IOException("Could not find font: /" + fontName.getName()); } setFontName(fontName); setFont(font); setFontSize(fontSize); }
Example 11
Source File: PDFontDescriptor.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * A string representing the preferred font stretch. * According to the PDF Spec: * The font stretch value; it must be one of the following (ordered from * narrowest to widest): UltraCondensed, ExtraCondensed, Condensed, SemiCondensed, * Normal, SemiExpanded, Expanded, ExtraExpanded or UltraExpanded. * * @return The stretch of the font. */ public String getFontStretch() { String retval = null; COSName name = (COSName)dic.getDictionaryObject( COSName.FONT_STRETCH ); if( name != null ) { retval = name.getName(); } return retval; }
Example 12
Source File: PDMarkedContent.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Creates a new marked content object. * * @param tag the tag * @param properties the properties */ public PDMarkedContent(COSName tag, COSDictionary properties) { this.tag = tag == null ? null : tag.getName(); this.properties = properties; this.contents = new ArrayList<Object>(); }
Example 13
Source File: CryptFilter.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public DecodeResult decode(InputStream encoded, OutputStream decoded, COSDictionary parameters, int index) throws IOException { COSName encryptionName = (COSName) parameters.getDictionaryObject(COSName.NAME); if(encryptionName == null || encryptionName.equals(COSName.IDENTITY)) { // currently the only supported implementation is the Identity crypt filter Filter identityFilter = new IdentityFilter(); identityFilter.decode(encoded, decoded, parameters, index); return new DecodeResult(parameters); } throw new IOException("Unsupported crypt filter " + encryptionName.getName()); }
Example 14
Source File: DrawObject.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public void process(Operator operator, List<COSBase> operands) throws IOException { if (operands.isEmpty()) { throw new MissingOperandException(operator, operands); } COSBase base0 = operands.get(0); if (!(base0 instanceof COSName)) { return; } COSName objectName = (COSName) base0; PDXObject xobject = context.getResources().getXObject(objectName); if (xobject == null) { throw new MissingResourceException("Missing XObject: " + objectName.getName()); } else if (xobject instanceof PDImageXObject) { PDImageXObject image = (PDImageXObject)xobject; context.drawImage(image); } else if (xobject instanceof PDTransparencyGroup) { getContext().showTransparencyGroup((PDTransparencyGroup) xobject); } else if (xobject instanceof PDFormXObject) { getContext().showForm((PDFormXObject) xobject); } }
Example 15
Source File: PdfBoxDict.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public String[] list() { final Set<COSName> cosNames = wrapped.keySet(); List<String> result = new ArrayList<>(cosNames.size()); for (final COSName cosName : cosNames) { final String name = cosName.getName(); result.add(name); } return result.toArray(new String[result.size()]); }
Example 16
Source File: PDDestination.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * This will create a new destination depending on the type of COSBase * that is passed in. * * @param base The base level object. * * @return A new destination. * * @throws IOException If the base cannot be converted to a Destination. */ public static PDDestination create( COSBase base ) throws IOException { PDDestination retval = null; if( base == null ) { //this is ok, just return null. } else if (base instanceof COSArray && ((COSArray) base).size() > 1 && ((COSArray) base).getObject(1) instanceof COSName) { COSArray array = (COSArray)base; COSName type = (COSName) array.getObject(1); String typeString = type.getName(); if( typeString.equals( PDPageFitDestination.TYPE ) || typeString.equals( PDPageFitDestination.TYPE_BOUNDED )) { retval = new PDPageFitDestination( array ); } else if( typeString.equals( PDPageFitHeightDestination.TYPE ) || typeString.equals( PDPageFitHeightDestination.TYPE_BOUNDED )) { retval = new PDPageFitHeightDestination( array ); } else if( typeString.equals( PDPageFitRectangleDestination.TYPE ) ) { retval = new PDPageFitRectangleDestination( array ); } else if( typeString.equals( PDPageFitWidthDestination.TYPE ) || typeString.equals( PDPageFitWidthDestination.TYPE_BOUNDED )) { retval = new PDPageFitWidthDestination( array ); } else if( typeString.equals( PDPageXYZDestination.TYPE ) ) { retval = new PDPageXYZDestination( array ); } else { throw new IOException( "Unknown destination type: " + type.getName() ); } } else if( base instanceof COSString ) { retval = new PDNamedDestination( (COSString)base ); } else if( base instanceof COSName ) { retval = new PDNamedDestination( (COSName)base ); } else { throw new IOException( "Error: can't convert to Destination " + base ); } return retval; }
Example 17
Source File: PDSeparation.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * Returns the colorant name. * @return the name of the colorant */ public String getColorantName() { COSName name = (COSName)array.getObject(COLORANT_NAMES); return name.getName(); }
Example 18
Source File: PDTargetDirectory.java From gcs with Mozilla Public License 2.0 | 3 votes |
/** * Set the relationship between the current document and the target (which may be an * intermediate target). * * @param relationship Valid values are P (the target is the parent of the current document) and * C (the target is a child of the current document). * * throws IllegalArgumentException if the parameter is not P or C. */ public void setRelationship(COSName relationship) { if (!COSName.P.equals(relationship) && !COSName.C.equals(relationship)) { throw new IllegalArgumentException("The only valid are P or C, not " + relationship.getName()); } dict.setItem(COSName.R, relationship); }