/** * Gets process color model of trap network appearance, {@link PdfName#PCM} key. * * @return a {@link PdfName} instance, possible values: {@link PdfName#DeviceGray}, * {@link PdfName#DeviceRGB}, {@link PdfName#DeviceCMYK}, {@link PdfName#DeviceCMY}, * {@link PdfName#DeviceRGBK}, and {@link PdfName#DeviceN}. */ public PdfName getProcessColorModel() { return getPdfObject().getAsName(PdfName.PCM); }
private boolean isXRefStream(PdfStream pdfStream) { return PdfName.XRef.equals(pdfStream.getAsName(PdfName.Type)); }
/** * Displays an XObject using the registered handler for this XObject's subtype * * @param resourceName the name of the XObject to retrieve from the resource dictionary */ private void displayXObject(PdfName resourceName) { PdfStream xobjectStream = getXObjectStream(resourceName); PdfName subType = xobjectStream.getAsName(PdfName.Subtype); IXObjectDoHandler handler = xobjectDoHandlers.get(subType); if (handler == null) { handler = xobjectDoHandlers.get(PdfName.Default); } handler.handleXObject(this, this.markedContentStack, xobjectStream, resourceName); }
/** * Create {@link PdfFormXObject} or {@link PdfImageXObject} by {@link PdfStream}. * * @param stream {@link PdfStream} with either {@link PdfName#Form} * or {@link PdfName#Image} {@link PdfName#Subtype} * @return either {@link PdfFormXObject} or {@link PdfImageXObject}. */ public static PdfXObject makeXObject(PdfStream stream) { if (PdfName.Form.equals(stream.getAsName(PdfName.Subtype))) { return new PdfFormXObject(stream); } else if (PdfName.Image.equals(stream.getAsName(PdfName.Subtype))) { return new PdfImageXObject(stream); } else { throw new UnsupportedOperationException(PdfException.UnsupportedXObjectType); } }
public PdfImageXObject getImage(PdfName name) { PdfStream image = getResource(PdfName.XObject).getAsStream(name); return image != null && PdfName.Image.equals(image.getAsName(PdfName.Subtype)) ? new PdfImageXObject(image) : null; }
public PdfFormXObject getForm(PdfName name) { PdfStream form = getResource(PdfName.XObject).getAsStream(name); return form != null && PdfName.Form.equals(form.getAsName(PdfName.Subtype)) ? new PdfFormXObject(form) : null; }
private static CMapEncoding createCMap(PdfObject cmap, String uniMap) { if (cmap.isStream()) { PdfStream cmapStream = (PdfStream) cmap; byte[] cmapBytes = cmapStream.getBytes(); return new CMapEncoding(cmapStream.getAsName(PdfName.CMapName).getValue(), cmapBytes); } else { String cmapName = ((PdfName) cmap).getValue(); if (PdfEncodings.IDENTITY_H.equals(cmapName) || PdfEncodings.IDENTITY_V.equals(cmapName)) { return new CMapEncoding(cmapName); } else { return new CMapEncoding(cmapName, uniMap); } } }
@Override protected void checkImage(PdfStream image, PdfDictionary currentColorSpaces) { PdfColorSpace colorSpace = null; if (isAlreadyChecked(image)) { colorSpace = checkedObjectsColorspace.get(image); checkColorSpace(colorSpace, currentColorSpaces, true, null); return; } PdfObject colorSpaceObj = image.get(PdfName.ColorSpace); if (colorSpaceObj != null) { colorSpace = PdfColorSpace.makeColorSpace(colorSpaceObj); checkColorSpace(colorSpace, currentColorSpaces, true, null); checkedObjectsColorspace.put(image, colorSpace); } if (image.containsKey(PdfName.Alternates)) { throw new PdfAConformanceException(PdfAConformanceException.AN_IMAGE_DICTIONARY_SHALL_NOT_CONTAIN_ALTERNATES_KEY); } if (image.containsKey(PdfName.OPI)) { throw new PdfAConformanceException(PdfAConformanceException.AN_IMAGE_DICTIONARY_SHALL_NOT_CONTAIN_OPI_KEY); } if (image.containsKey(PdfName.Interpolate) && (boolean) image.getAsBool(PdfName.Interpolate)) { throw new PdfAConformanceException(PdfAConformanceException.THE_VALUE_OF_INTERPOLATE_KEY_SHALL_BE_FALSE); } checkRenderingIntent(image.getAsName(PdfName.Intent)); if (image.containsKey(PdfName.SMask) && !PdfName.None.equals(image.getAsName(PdfName.SMask))) { throw new PdfAConformanceException(PdfAConformanceException.THE_SMASK_KEY_IS_NOT_ALLOWED_IN_XOBJECTS); } }
@Override protected void checkImage(PdfStream image, PdfDictionary currentColorSpaces) { PdfColorSpace colorSpace = null; if (isAlreadyChecked(image)) { colorSpace = checkedObjectsColorspace.get(image); checkColorSpace(colorSpace, currentColorSpaces, true, null); return; } PdfObject colorSpaceObj = image.get(PdfName.ColorSpace); if (colorSpaceObj != null) { colorSpace = PdfColorSpace.makeColorSpace(colorSpaceObj); checkColorSpace(colorSpace, currentColorSpaces, true, null); checkedObjectsColorspace.put(image, colorSpace); } if (image.containsKey(PdfName.Alternates)) { throw new PdfAConformanceException(PdfAConformanceException.AN_IMAGE_DICTIONARY_SHALL_NOT_CONTAIN_ALTERNATES_KEY); } if (image.containsKey(PdfName.OPI)) { throw new PdfAConformanceException(PdfAConformanceException.AN_IMAGE_DICTIONARY_SHALL_NOT_CONTAIN_OPI_KEY); } if (image.containsKey(PdfName.Interpolate) && (boolean) image.getAsBool(PdfName.Interpolate)) { throw new PdfAConformanceException(PdfAConformanceException.THE_VALUE_OF_INTERPOLATE_KEY_SHALL_BE_FALSE); } checkRenderingIntent(image.getAsName(PdfName.Intent)); if (image.containsKey(PdfName.SMask) && !PdfName.None.equals(image.getAsName(PdfName.SMask))) { throw new PdfAConformanceException(PdfAConformanceException.THE_SMASK_KEY_IS_NOT_ALLOWED_IN_XOBJECTS); } }
@Override protected void checkFormXObject(PdfStream form) { if (isAlreadyChecked(form)) return; if (form.containsKey(PdfName.OPI)) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_OPI_KEY); } if (form.containsKey(PdfName.PS)) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_PS_KEY); } if (PdfName.PS.equals(form.getAsName(PdfName.Subtype2))) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_SUBTYPE2_KEY_WITH_A_VALUE_OF_PS); } if (form.containsKey(PdfName.SMask) && !PdfName.None.equals(form.getAsName(PdfName.SMask))) { throw new PdfAConformanceException(PdfAConformanceException.THE_SMASK_KEY_IS_NOT_ALLOWED_IN_XOBJECTS); } if (form.containsKey(PdfName.Group) && PdfName.Transparency.equals(form.getAsDictionary(PdfName.Group).getAsName(PdfName.S))) { throw new PdfAConformanceException(PdfAConformanceException.A_GROUP_OBJECT_WITH_AN_S_KEY_WITH_A_VALUE_OF_TRANSPARENCY_SHALL_NOT_BE_INCLUDED_IN_A_FORM_XOBJECT); } checkResources(form.getAsDictionary(PdfName.Resources)); }
@Override protected void checkFormXObject(PdfStream form) { if (isAlreadyChecked(form)) return; if (form.containsKey(PdfName.OPI)) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_OPI_KEY); } if (form.containsKey(PdfName.PS)) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_PS_KEY); } if (PdfName.PS.equals(form.getAsName(PdfName.Subtype2))) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_SUBTYPE2_KEY_WITH_A_VALUE_OF_PS); } if (form.containsKey(PdfName.SMask) && !PdfName.None.equals(form.getAsName(PdfName.SMask))) { throw new PdfAConformanceException(PdfAConformanceException.THE_SMASK_KEY_IS_NOT_ALLOWED_IN_XOBJECTS); } if (form.containsKey(PdfName.Group) && PdfName.Transparency.equals(form.getAsDictionary(PdfName.Group).getAsName(PdfName.S))) { throw new PdfAConformanceException(PdfAConformanceException.A_GROUP_OBJECT_WITH_AN_S_KEY_WITH_A_VALUE_OF_TRANSPARENCY_SHALL_NOT_BE_INCLUDED_IN_A_FORM_XOBJECT); } checkResources(form.getAsDictionary(PdfName.Resources)); }
text.setText(""); if (PdfName.Image.equals(stream.getAsName(PdfName.Subtype))) { try {
throw new PdfAConformanceException(PdfAConformanceException.THE_VALUE_OF_INTERPOLATE_KEY_SHALL_BE_FALSE); checkRenderingIntent(image.getAsName(PdfName.Intent));
throw new PdfAConformanceException(PdfAConformanceException.THE_VALUE_OF_INTERPOLATE_KEY_SHALL_BE_FALSE); checkRenderingIntent(image.getAsName(PdfName.Intent));
@Override protected void checkFormXObject(PdfStream form) { if (isAlreadyChecked(form)) return; if (form.containsKey(PdfName.OPI)) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_OPI_KEY); } if (form.containsKey(PdfName.PS)) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_PS_KEY); } if (PdfName.PS.equals(form.getAsName(PdfName.Subtype2))) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_SUBTYPE2_KEY_WITH_A_VALUE_OF_PS); } if (form.containsKey(PdfName.Group) && PdfName.Transparency.equals(form.getAsDictionary(PdfName.Group).getAsName(PdfName.S))) { transparencyIsUsed = true; PdfObject cs = form.getAsDictionary(PdfName.Group).get(PdfName.CS); PdfDictionary resources = form.getAsDictionary(PdfName.Resources); if (cs != null && resources != null) { PdfDictionary currentColorSpaces = resources.getAsDictionary(PdfName.ColorSpace); checkColorSpace(PdfColorSpace.makeColorSpace(cs), currentColorSpaces, true, null); } } checkResources(form.getAsDictionary(PdfName.Resources)); }
@Override protected void checkFormXObject(PdfStream form) { if (isAlreadyChecked(form)) return; if (form.containsKey(PdfName.OPI)) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_OPI_KEY); } if (form.containsKey(PdfName.PS)) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_PS_KEY); } if (PdfName.PS.equals(form.getAsName(PdfName.Subtype2))) { throw new PdfAConformanceException(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_SUBTYPE2_KEY_WITH_A_VALUE_OF_PS); } if (form.containsKey(PdfName.Group) && PdfName.Transparency.equals(form.getAsDictionary(PdfName.Group).getAsName(PdfName.S))) { transparencyIsUsed = true; PdfObject cs = form.getAsDictionary(PdfName.Group).get(PdfName.CS); PdfDictionary resources = form.getAsDictionary(PdfName.Resources); if (cs != null && resources != null) { PdfDictionary currentColorSpaces = resources.getAsDictionary(PdfName.ColorSpace); checkColorSpace(PdfColorSpace.makeColorSpace(cs), currentColorSpaces, true, null); } } checkResources(form.getAsDictionary(PdfName.Resources)); }
PdfName type = stream.getAsName(PdfName.Type); if (!PdfName.XRefStm.equals(type) && !PdfName.ObjStm.equals(type)) checkPdfStreamLength(stream);