/** * Gets a PDF Name from an array or returns the object that was passed. */ private PdfObject simplifyColorspace(final PdfArray obj) { if (obj == null) return obj; PdfName first = obj.getAsName(0); if (PdfName.CALGRAY.equals(first)) return PdfName.DEVICEGRAY; else if (PdfName.CALRGB.equals(first)) return PdfName.DEVICERGB; else return obj; }
/** * Gets a PDF Name from an array or returns the object that was passed. */ private PdfObject simplifyColorspace(final PdfArray obj) { if (obj == null) return obj; PdfName first = obj.getAsName(0); if (PdfName.CALGRAY.equals(first)) return PdfName.DEVICEGRAY; else if (PdfName.CALRGB.equals(first)) return PdfName.DEVICERGB; else return obj; }
private static int getComponentsPerPixel(PdfName colorSpaceName, PdfDictionary colorSpaceDic){ if (colorSpaceName == null) return 1; if (colorSpaceName.equals(PdfName.DEVICEGRAY)) return 1; if (colorSpaceName.equals(PdfName.DEVICERGB)) return 3; if (colorSpaceName.equals(PdfName.DEVICECMYK)) return 4; if (colorSpaceDic != null){ PdfArray colorSpace = colorSpaceDic.getAsArray(colorSpaceName); if (colorSpace != null){ if (PdfName.INDEXED.equals(colorSpace.getAsName(0))){ return 1; } } } throw new IllegalArgumentException("Unexpected color space " + colorSpaceName); }
PdfArray list = (PdfArray)image.get(PdfName.FILTER); for (int j = 0; j < list.size(); j++) { PdfName filter = list.getAsName(j); filterObject(image, filter, stream);
private static int getComponentsPerPixel(PdfName colorSpaceName, PdfDictionary colorSpaceDic){ if (colorSpaceName == null) return 1; if (colorSpaceName.equals(PdfName.DEVICEGRAY)) return 1; if (colorSpaceName.equals(PdfName.DEVICERGB)) return 3; if (colorSpaceName.equals(PdfName.DEVICECMYK)) return 4; if (colorSpaceDic != null){ PdfArray colorSpace = colorSpaceDic.getAsArray(colorSpaceName); if (colorSpace != null){ if (PdfName.INDEXED.equals(colorSpace.getAsName(0))){ return 1; } } /* Begin mod # */ else { PdfName tempName = colorSpaceDic.getAsName(colorSpaceName); if(tempName != null) return(getComponentsPerPixel(tempName, colorSpaceDic)); } /* End mod */ } throw new IllegalArgumentException("Unexpected color space " + colorSpaceName); }
PdfArray colorSpace = colorSpaceDic.getAsArray(colorSpaceName); if (colorSpace != null){ if (PdfName.INDEXED.equals(colorSpace.getAsName(0))){ return 1;
public void transformDestination(float a, float b, float c, float d, float e, float f) { if (!isInternal()) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("cannot.change.destination.of.external.link")); if (destination.getAsName(1).equals(PdfName.XYZ)) { float x = destination.getAsNumber(2).floatValue(); float y = destination.getAsNumber(3).floatValue(); float xx = x * a + y * c + e; float yy = x * b + y * d + f; destination.set(2, new PdfNumber(xx)); destination.set(3, new PdfNumber(yy)); } }
PdfArray colorSpace = colorSpaceDic.getAsArray(colorSpaceName); if (colorSpace != null){ if (PdfName.INDEXED.equals(colorSpace.getAsName(0))){ return 1;
public void transformDestination(float a, float b, float c, float d, float e, float f) { if (!isInternal()) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("cannot.change.destination.of.external.link")); if (destination.getAsName(1).equals(PdfName.XYZ)) { float x = destination.getAsNumber(2).floatValue(); float y = destination.getAsNumber(3).floatValue(); float xx = x * a + y * c + e; float yy = x * b + y * d + f; destination.set(2, new PdfNumber(xx)); destination.set(3, new PdfNumber(yy)); } }
/** * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. */ public void simplifyColorspace() { if (additional == null) return; PdfArray value = additional.getAsArray(PdfName.COLORSPACE); if (value == null) return; PdfObject cs = simplifyColorspace(value); PdfObject newValue; if (cs.isName()) newValue = cs; else { newValue = value; PdfName first = value.getAsName(0); if (PdfName.INDEXED.equals(first)) { if (value.size() >= 2) { PdfArray second = value.getAsArray(1); if (second != null) { value.set(1, simplifyColorspace(second)); } } } } additional.put(PdfName.COLORSPACE, newValue); }
@Override protected void checkInlineImage(PdfWriter writer, int key, Object obj1) { PdfImage pdfImage = (PdfImage) obj1; PdfBoolean interpolate = pdfImage.getAsBoolean(PdfName.INTERPOLATE); if (interpolate != null && interpolate.booleanValue()) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("the.value.of.interpolate.key.shall.not.be.true")); } PdfObject filter = pdfImage.getDirectObject(PdfName.FILTER); if (filter instanceof PdfName) { if (filter.equals(PdfName.LZWDECODE)) throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("lzwdecode.filter.is.not.permitted")); if (filter.equals(PdfName.CRYPT)) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("crypt.filter.is.not.permitted.inline.image")); } } else if (filter instanceof PdfArray) { for (int i = 0; i < ((PdfArray) filter).size(); i++) { PdfName f = ((PdfArray) filter).getAsName(i); if (f.equals(PdfName.LZWDECODE)) throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("lzwdecode.filter.is.not.permitted")); if (f.equals(PdfName.CRYPT)) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("crypt.filter.is.not.permitted.inline.image")); } } } }
/** * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. */ public void simplifyColorspace() { if (additional == null) return; PdfArray value = additional.getAsArray(PdfName.COLORSPACE); if (value == null) return; PdfObject cs = simplifyColorspace(value); PdfObject newValue; if (cs.isName()) newValue = cs; else { newValue = value; PdfName first = value.getAsName(0); if (PdfName.INDEXED.equals(first)) { if (value.size() >= 2) { PdfArray second = value.getAsArray(1); if (second != null) { value.set(1, simplifyColorspace(second)); } } } } additional.put(PdfName.COLORSPACE, newValue); }
PdfName f = ((PdfArray) filter).getAsName(i); if (f.equals(PdfName.LZWDECODE)) throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("lzwdecode.filter.is.not.permitted"));
PdfArray ar = (PdfArray)value; if (ar.size() == 4 && PdfName.INDEXED.equals(ar.getAsName(0)) && ar.getPdfObject(1).isName() && ar.getPdfObject(2).isNumber()
PdfArray ar = (PdfArray)value; if (ar.size() == 4 && PdfName.INDEXED.equals(ar.getAsName(0)) && ar.getPdfObject(1).isName() && ar.getPdfObject(2).isNumber()