@Override protected void checkPdfStream(PdfStream stream) { if (stream.containsKey(PdfName.F) || stream.containsKey(PdfName.FFilter) || stream.containsKey(PdfName.FDecodeParams)) { throw new PdfAConformanceException(PdfAConformanceException.STREAM_OBJECT_DICTIONARY_SHALL_NOT_CONTAIN_THE_F_FFILTER_OR_FDECODEPARAMS_KEYS); } PdfObject filter = stream.get(PdfName.Filter); if (filter instanceof PdfName) { if (filter.equals(PdfName.LZWDecode)) throw new PdfAConformanceException(PdfAConformanceException.LZWDECODE_FILTER_IS_NOT_PERMITTED); } else if (filter instanceof PdfArray) { for (PdfObject f : ((PdfArray) filter)) { if (f.equals(PdfName.LZWDecode)) throw new PdfAConformanceException(PdfAConformanceException.LZWDECODE_FILTER_IS_NOT_PERMITTED); } } }
@Override protected void checkPdfStream(PdfStream stream) { if (stream.containsKey(PdfName.F) || stream.containsKey(PdfName.FFilter) || stream.containsKey(PdfName.FDecodeParams)) { throw new PdfAConformanceException(PdfAConformanceException.STREAM_OBJECT_DICTIONARY_SHALL_NOT_CONTAIN_THE_F_FFILTER_OR_FDECODEPARAMS_KEYS); } PdfObject filter = stream.get(PdfName.Filter); if (filter instanceof PdfName) { if (filter.equals(PdfName.LZWDecode)) throw new PdfAConformanceException(PdfAConformanceException.LZWDECODE_FILTER_IS_NOT_PERMITTED); } else if (filter instanceof PdfArray) { for (PdfObject f : ((PdfArray) filter)) { if (f.equals(PdfName.LZWDecode)) throw new PdfAConformanceException(PdfAConformanceException.LZWDECODE_FILTER_IS_NOT_PERMITTED); } } }
private static PdfStream getPageStream(PdfPage page) { PdfStream stream = page.getLastContentStream(); return stream == null || stream.getOutputStream() == null || stream.containsKey(PdfName.Filter) ? page.newContentStreamAfter() : stream; }
private PdfStream ensureStreamDataIsReadyToBeProcessed(PdfStream stream) { if (!stream.isFlushed()) { if (stream.getOutputStream() == null || stream.containsKey(PdfName.Filter)) { try { stream.setData(stream.getBytes()); } catch (Exception ex) { // ignore } } } return stream; }
@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)); }
if (!embeddedFile.containsKey(PdfName.Subtype)) { throw new PdfAConformanceException(PdfAConformanceException.MIME_TYPE_SHALL_BE_SPECIFIED_USING_THE_SUBTYPE_KEY_OF_THE_FILE_SPECIFICATION_STREAM_DICTIONARY); if (embeddedFile.containsKey(PdfName.Params)) { PdfObject params = embeddedFile.get(PdfName.Params); if (!params.isDictionary()) {
@Override protected void checkPdfStream(PdfStream stream) { if (stream.containsKey(PdfName.F) || stream.containsKey(PdfName.FFilter) || stream.containsKey(PdfName.FDecodeParams)) { throw new PdfAConformanceException(PdfAConformanceException.STREAM_OBJECT_DICTIONARY_SHALL_NOT_CONTAIN_THE_F_FFILTER_OR_FDECODEPARAMS_KEYS);
@Override protected void checkPdfStream(PdfStream stream) { if (stream.containsKey(PdfName.F) || stream.containsKey(PdfName.FFilter) || stream.containsKey(PdfName.FDecodeParams)) { throw new PdfAConformanceException(PdfAConformanceException.STREAM_OBJECT_DICTIONARY_SHALL_NOT_CONTAIN_THE_F_FFILTER_OR_FDECODEPARAMS_KEYS);
if (!embeddedFile.containsKey(PdfName.Subtype)) { throw new PdfAConformanceException(PdfAConformanceException.MIME_TYPE_SHALL_BE_SPECIFIED_USING_THE_SUBTYPE_KEY_OF_THE_FILE_SPECIFICATION_STREAM_DICTIONARY); if (embeddedFile.containsKey(PdfName.Params)) { PdfObject params = embeddedFile.get(PdfName.Params); if (!params.isDictionary()) {
@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)); }
/** * Copies page as FormXObject to the specified document. * * @param toDocument a document to copy to. * @return copied {@link PdfFormXObject} object. */ public PdfFormXObject copyAsFormXObject(PdfDocument toDocument) throws IOException { PdfFormXObject xObject = new PdfFormXObject(getCropBox()); List<PdfName> excludedKeys = new ArrayList<>(Arrays.asList(PdfName.MediaBox, PdfName.CropBox, PdfName.Contents) ); excludedKeys.addAll(this.excludedKeys); PdfDictionary dictionary = getPdfObject().copyTo(toDocument, excludedKeys, true); xObject.getPdfObject().getOutputStream().write(getContentBytes()); xObject.getPdfObject().mergeDifferent(dictionary); //Copy inherited resources if (!xObject.getPdfObject().containsKey(PdfName.Resources)) { PdfObject copyResource = getResources().getPdfObject().copyTo(toDocument, true); xObject.getPdfObject().put(PdfName.Resources, copyResource); } return xObject; }
outputStream.getOutputStream().flush(); bytes = ((ByteArrayOutputStream) outputStream.getOutputStream()).toByteArray(); if (decoded && containsKey(PdfName.Filter)) { bytes = PdfReader.decodeBytes(bytes, this);
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); if (image.containsKey(PdfName.SMaskInData) && image.getAsInt(PdfName.SMaskInData) > 0) { transparencyIsUsed = true;
Rectangle calculateViewPort(SvgDrawContext context){ float portX = 0f; float portY = 0f; float portWidth = 0f; float portHeight = 0f; PdfStream contentStream = context.getCurrentCanvas().getContentStream(); if ( ! contentStream.containsKey(PdfName.BBox) ) { throw new SvgProcessingException(SvgLogMessageConstant.ROOT_SVG_NO_BBOX); } PdfArray bboxArray = contentStream.getAsArray(PdfName.BBox); portX = bboxArray.getAsNumber(0).floatValue(); portY = bboxArray.getAsNumber(1).floatValue(); portWidth = bboxArray.getAsNumber(2).floatValue() - portX; portHeight = bboxArray.getAsNumber(3).floatValue() - portY; return new Rectangle(portX, portY, portWidth, portHeight); }
|| !outputStreamIsUninitialized && containsKey(PdfName.Filter)) {
boolean allowCompression = !pdfStream.containsKey(PdfName.Filter) && isNotMetadataPdfStream(pdfStream);