/// <summary>PDF 2.0.</summary> /// <remarks> /// PDF 2.0. Sets an array of names of Viewer preference settings that /// shall be enforced by PDF processors and that shall not be overridden by /// subsequent selections in the application user interface /// </remarks> /// <param name="enforce">array of names specifying settings to enforce in the PDF processors</param> /// <returns> /// this /// <see cref="PdfViewerPreferences"/> /// instance /// </returns> public virtual iText.Kernel.Pdf.PdfViewerPreferences SetEnforce(PdfArray enforce) { for (int i = 0; i < enforce.Size(); i++) { PdfName curEnforce = enforce.GetAsName(i); if (curEnforce == null) { throw new ArgumentException("Enforce array shall contain PdfName entries"); } else { if (PdfName.PrintScaling.Equals(curEnforce)) { // This name may appear in the Enforce array only if the corresponding entry in // the viewer preferences dictionary specifies a valid value other than AppDefault PdfName curPrintScaling = GetPdfObject().GetAsName(PdfName.PrintScaling); if (curPrintScaling == null || PdfName.AppDefault.Equals(curPrintScaling)) { throw new PdfException(PdfException.PrintScalingEnforceEntryInvalid); } } } } return(Put(PdfName.Enforce, enforce)); }
/// <summary> /// Performs a check if the /// <see cref="PdfStream"/> /// with provided setup of the filters requires /// memory limits awareness during decompression. /// </summary> /// <param name="filters"> /// is an /// <see cref="PdfArray"/> /// of names of filters /// </param> /// <returns>true if PDF stream is suspicious and false otherwise</returns> public virtual bool IsMemoryLimitsAwarenessRequiredOnDecompression(PdfArray filters) { HashSet <PdfName> filterSet = new HashSet <PdfName>(); for (int index = 0; index < filters.Size(); index++) { PdfName filterName = filters.GetAsName(index); if (!filterSet.Add(filterName)) { return(true); } } return(false); }
protected internal virtual byte[] DecodeFlateBytes(PdfStream stream, byte[] bytes) { PdfObject filterObject = stream.Get(PdfName.Filter); if (filterObject == null) { return(bytes); } // check if flateDecode filter is on top PdfName filterName; PdfArray filtersArray = null; if (filterObject is PdfName) { filterName = (PdfName)filterObject; } else { if (filterObject is PdfArray) { filtersArray = (PdfArray)filterObject; filterName = filtersArray.GetAsName(0); } else { throw new PdfException(PdfException.FilterIsNotANameOrArray); } } if (!PdfName.FlateDecode.Equals(filterName)) { return(bytes); } // get decode params if present PdfDictionary decodeParams; PdfArray decodeParamsArray = null; PdfObject decodeParamsObject = stream.Get(PdfName.DecodeParms); if (decodeParamsObject == null) { decodeParams = null; } else { if (decodeParamsObject.GetObjectType() == PdfObject.DICTIONARY) { decodeParams = (PdfDictionary)decodeParamsObject; } else { if (decodeParamsObject.GetObjectType() == PdfObject.ARRAY) { decodeParamsArray = (PdfArray)decodeParamsObject; decodeParams = decodeParamsArray.GetAsDictionary(0); } else { throw new PdfException(PdfException.DecodeParameterType1IsNotSupported).SetMessageParams(decodeParamsObject .GetType().ToString()); } } } // decode byte[] res = FlateDecodeFilter.FlateDecode(bytes, true); if (res == null) { res = FlateDecodeFilter.FlateDecode(bytes, false); } bytes = FlateDecodeFilter.DecodePredictor(res, decodeParams); //remove filter and decode params filterObject = null; if (filtersArray != null) { filtersArray.Remove(0); if (filtersArray.Size() == 1) { filterObject = filtersArray.Get(0); } else { if (!filtersArray.IsEmpty()) { filterObject = filtersArray; } } } decodeParamsObject = null; if (decodeParamsArray != null) { decodeParamsArray.Remove(0); if (decodeParamsArray.Size() == 1 && decodeParamsArray.Get(0).GetObjectType() != PdfObject.NULL) { decodeParamsObject = decodeParamsArray.Get(0); } else { if (!decodeParamsArray.IsEmpty()) { decodeParamsObject = decodeParamsArray; } } } if (filterObject == null) { stream.Remove(PdfName.Filter); } else { stream.Put(PdfName.Filter, filterObject); } if (decodeParamsObject == null) { stream.Remove(PdfName.DecodeParms); } else { stream.Put(PdfName.DecodeParms, decodeParamsObject); } return(bytes); }