當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfDictionary.Contains方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfDictionary.Contains方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDictionary.Contains方法的具體用法?C# PdfDictionary.Contains怎麽用?C# PdfDictionary.Contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfDictionary的用法示例。


在下文中一共展示了PdfDictionary.Contains方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: FileEmbedded

        /**
        * Creates a file specification with the file embedded. The file may
        * come from the file system or from a byte array.
        * @param writer the <CODE>PdfWriter</CODE>
        * @param filePath the file path
        * @param fileDisplay the file information that is presented to the user
        * @param fileStore the byte array with the file. If it is not <CODE>null</CODE>
        * it takes precedence over <CODE>filePath</CODE>
        * @param mimeType the optional mimeType
        * @param fileParameter the optional extra file parameters such as the creation or modification date
        * @param compressionLevel the level of compression
        * @throws IOException on error
        * @return the file specification
        * @since   2.1.3
        */    
        public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel) {
            PdfFileSpecification fs = new PdfFileSpecification();
            fs.writer = writer;
            fs.Put(PdfName.F, new PdfString(fileDisplay));
            fs.SetUnicodeFileName(fileDisplay, false);
            PdfEFStream stream;
            Stream inp = null;
            PdfIndirectReference refi;
            PdfIndirectReference refFileLength = null;
            try {
                if (fileStore == null) {
                    refFileLength = writer.PdfIndirectReference;
                    if (File.Exists(filePath)) {
                        inp = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                    }
                    else {
                        if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://")) {
                            WebRequest wr = WebRequest.Create(filePath);
                            wr.Credentials = CredentialCache.DefaultCredentials;
                            inp = wr.GetResponse().GetResponseStream();
                        }
                        else {
                            inp = StreamUtil.GetResourceStream(filePath);
                            if (inp == null)
                                throw new IOException(MessageLocalization.GetComposedMessage("1.not.found.as.file.or.resource", filePath));
                        }
                    }
                    stream = new PdfEFStream(inp, writer);
                }
                else
                    stream = new PdfEFStream(fileStore);
                stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE);
                stream.FlateCompress(compressionLevel);

                PdfDictionary param = new PdfDictionary();
                if (fileParameter != null)
                    param.Merge(fileParameter);
                if (!param.Contains(PdfName.MODDATE)) {
                    param.Put(PdfName.MODDATE, new PdfDate());
                }
                if (fileStore != null) {
                    param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
                    stream.Put(PdfName.PARAMS, param);
                }
                else {
                    stream.Put(PdfName.PARAMS, refFileLength);
                }

                if (mimeType != null)
                    stream.Put(PdfName.SUBTYPE, new PdfName(mimeType));

                refi = writer.AddToBody(stream).IndirectReference;
                if (fileStore == null) {
                    stream.WriteLength();
                    param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
                    writer.AddToBody(param, refFileLength);
                }
            }
            finally {
                if (inp != null)
                    try{inp.Close();}catch{}
            }
            PdfDictionary f = new PdfDictionary();
            f.Put(PdfName.F, refi);
            f.Put(PdfName.UF, refi);
            fs.Put(PdfName.EF, f);
            return fs;
        }
開發者ID:,項目名稱:,代碼行數:83,代碼來源:

示例2: CopyDictionary

        /**
        * Translate a PRDictionary to a PdfDictionary. Also translate all of the
        * objects contained in it.
        */
        protected PdfDictionary CopyDictionary(PdfDictionary inp, bool keepStruct, bool directRootKids) {
            PdfDictionary outp = new PdfDictionary();
            PdfObject type = PdfReader.GetPdfObjectRelease(inp.Get(PdfName.TYPE));
            
             if (keepStruct)
            {
                if ((directRootKids) && (inp.Contains(PdfName.PG)))
                {
                    PdfObject curr = inp;
                    disableIndirects.Add(curr);
                    while (parentObjects.ContainsKey(curr) && !(disableIndirects.Contains(curr))) {
                        curr = parentObjects[curr];
                        disableIndirects.Add(curr);
                    }
                    return null;
                }
                    
                PdfName structType = inp.GetAsName(PdfName.S);
                structTreeController.AddRole(structType);
                structTreeController.AddClass(inp);
            }

            if (structTreeController != null && structTreeController.reader != null && (inp.Contains(PdfName.STRUCTPARENTS) || inp.Contains(PdfName.STRUCTPARENT))) {
                PdfName key = PdfName.STRUCTPARENT;
                if (inp.Contains(PdfName.STRUCTPARENTS)) {
                    key = PdfName.STRUCTPARENTS;
                }
                PdfObject value = inp.Get(key);
                outp.Put(key, new PdfNumber(currentStructArrayNumber));
                structTreeController.CopyStructTreeForPage((PdfNumber) value, currentStructArrayNumber++);
            }

            foreach (PdfName key in inp.Keys) {
                PdfObject value = inp.Get(key);
                if (structTreeController != null && structTreeController.reader != null &&
                    (key.Equals(PdfName.STRUCTPARENTS) || key.Equals(PdfName.STRUCTPARENT))) {
                    continue;
                }
                if (PdfName.PAGE.Equals(type))
                {
                    if (!key.Equals(PdfName.B) && !key.Equals(PdfName.PARENT))
                    {
                        parentObjects[value] = inp;
                        PdfObject res = CopyObject(value, keepStruct, directRootKids);
                        if ((res != null) && !(res is PdfNull))
                            outp.Put(key, res);
                    }
                }
                else
                {
                    PdfObject res;
                    if (tagged && value.IsIndirect() && IsStructTreeRootReference((PRIndirectReference) value))
                        res = structureTreeRoot.Reference;
                    else
                        res = CopyObject(value, keepStruct, directRootKids);
                    if ((res != null) && !(res is PdfNull))
                        outp.Put(key, res);
                }
            }
            return outp;
        }
開發者ID:,項目名稱:,代碼行數:65,代碼來源:

示例3: ExtractLocationsFromRedactAnnots

        /**
         * Extracts locations from the redact annotations contained in the document and applied to the given page.
         */
        private IList<PdfCleanUpLocation> ExtractLocationsFromRedactAnnots(int page, PdfDictionary pageDict) {
            List<PdfCleanUpLocation> locations = new List<PdfCleanUpLocation>();

            if (pageDict.Contains(PdfName.ANNOTS)) {
                PdfArray annotsArray = pageDict.GetAsArray(PdfName.ANNOTS);

                for (int i = 0; i < annotsArray.Size; ++i) {
                    PdfIndirectReference annotIndirRef = annotsArray.GetAsIndirectObject(i);
                    PdfDictionary annotDict = annotsArray.GetAsDict(i);
                    PdfName annotSubtype = annotDict.GetAsName(PdfName.SUBTYPE);

                    if (annotSubtype.Equals(PdfName.REDACT)) {
                        SaveRedactAnnotIndirRef(page, annotIndirRef.ToString());
                        locations.AddRange(ExtractLocationsFromRedactAnnot(page, i, annotDict));
                    }
                }
            }

            return locations;
        }
開發者ID:yu0410aries,項目名稱:itextsharp,代碼行數:23,代碼來源:PdfCleanUpProcessor.cs

示例4: ParseUnfilteredSamples

        /**
         * Parses the samples of the image from the underlying content parser, ignoring all filters.
         * The parser must be positioned immediately after the ID operator that ends the inline image's dictionary.
         * The parser will be left positioned immediately following the EI operator.
         * This is primarily useful if no filters have been applied.
         * @param imageDictionary the dictionary of the inline image
         * @param ps the content parser
         * @return the samples of the image
         * @throws IOException if anything bad happens during parsing
         */
        private static byte[] ParseUnfilteredSamples(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic, PdfContentParser ps)
        {
            // special case:  when no filter is specified, we just read the number of bits
            // per component, multiplied by the width and height.
            if (imageDictionary.Contains(PdfName.FILTER))
                throw new ArgumentException("Dictionary contains filters");

            PdfNumber h = imageDictionary.GetAsNumber(PdfName.HEIGHT);

            int bytesToRead = ComputeBytesPerRow(imageDictionary, colorSpaceDic) * h.IntValue;
            byte[] bytes = new byte[bytesToRead];
            PRTokeniser tokeniser = ps.GetTokeniser();

            int shouldBeWhiteSpace = tokeniser.Read(); // skip next character (which better be a whitespace character - I suppose we could check for this)
            // from the PDF spec:  Unless the image uses ASCIIHexDecode or ASCII85Decode as one of its filters, the ID operator shall be followed by a single white-space character, and the next character shall be interpreted as the first byte of image data.
            // unfortunately, we've seen some PDFs where there is no space following the ID, so we have to capture this case and handle it
            int startIndex = 0;
            if (!PRTokeniser.IsWhitespace(shouldBeWhiteSpace) || shouldBeWhiteSpace == 0){ // tokeniser treats 0 as whitespace, but for our purposes, we shouldn't)
                bytes[0] = (byte)shouldBeWhiteSpace;
                startIndex++;
            }
            for (int i = startIndex; i < bytesToRead; i++){
                int ch = tokeniser.Read();
                if (ch == -1)
                    throw new InlineImageParseException("End of content stream reached before end of image data");

                bytes[i] = (byte)ch;
            }
            PdfObject ei = ps.ReadPRObject();
            if (!ei.ToString().Equals("EI"))
                throw new InlineImageParseException("EI not found after end of image data");

            return bytes;
        }
開發者ID:medvedttn,項目名稱:itextsharp_mod-src,代碼行數:44,代碼來源:InlineImageUtils.cs

示例5: ParseInlineImageSamples

        /**
         * Parses the samples of the image from the underlying content parser, accounting for filters
         * The parser must be positioned immediately after the ID operator that ends the inline image's dictionary.
         * The parser will be left positioned immediately following the EI operator.
         * <b>Note:</b>This implementation does not actually apply the filters at this time
         * @param imageDictionary the dictionary of the inline image
         * @param ps the content parser
         * @return the samples of the image
         * @throws IOException if anything bad happens during parsing
         */
        private static byte[] ParseInlineImageSamples(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic, PdfContentParser ps)
        {
            // by the time we get to here, we have already parsed the ID operator

            if (!imageDictionary.Contains(PdfName.FILTER)){
                return ParseUnfilteredSamples(imageDictionary, colorSpaceDic, ps);
            }

            // read all content until we reach an EI operator surrounded by whitespace.
            // The following algorithm has two potential issues: what if the image stream
            // contains <ws>EI<ws> ?
            // Plus, there are some streams that don't have the <ws> before the EI operator
            // it sounds like we would have to actually decode the content stream, which
            // I'd rather avoid right now.
            MemoryStream baos = new MemoryStream();
            MemoryStream accumulated = new MemoryStream();
            int ch;
            int found = 0;
            PRTokeniser tokeniser = ps.GetTokeniser();
            byte[] ff = null;

            while ((ch = tokeniser.Read()) != -1){
                if (found == 0 && PRTokeniser.IsWhitespace(ch)){
                    found++;
                    accumulated.WriteByte((byte)ch);
                } else if (found == 1 && ch == 'E'){
                    found++;
                    accumulated.WriteByte((byte)ch);
                } else if (found == 1 && PRTokeniser.IsWhitespace(ch)){
                    // this clause is needed if we have a white space character that is part of the image data
                    // followed by a whitespace character that precedes the EI operator.  In this case, we need
                    // to flush the first whitespace, then treat the current whitespace as the first potential
                    // character for the end of stream check.  Note that we don't increment 'found' here.
                    baos.Write(ff = accumulated.ToArray(), 0, ff.Length);
                    accumulated.SetLength(0);
                    accumulated.WriteByte((byte)ch);
                } else if (found == 2 && ch == 'I'){
                    found++;
                    accumulated.WriteByte((byte)ch);
                } else if (found == 3 && PRTokeniser.IsWhitespace(ch)){
                    return baos.ToArray();
                } else {
                    baos.Write(ff = accumulated.ToArray(), 0, ff.Length);
                    accumulated.SetLength(0);

                    baos.WriteByte((byte)ch);
                    found = 0;
                }
            }
            throw new InlineImageParseException("Could not find image data or EI");
        }
開發者ID:medvedttn,項目名稱:itextsharp_mod-src,代碼行數:61,代碼來源:InlineImageUtils.cs

示例6: ParseUnfilteredSamples

 /**
  * Parses the samples of the image from the underlying content parser, ignoring all filters.
  * The parser must be positioned immediately after the ID operator that ends the inline image's dictionary.
  * The parser will be left positioned immediately following the EI operator.
  * This is primarily useful if no filters have been applied. 
  * @param imageDictionary the dictionary of the inline image
  * @param ps the content parser
  * @return the samples of the image
  * @throws IOException if anything bad happens during parsing
  */
 private static byte[] ParseUnfilteredSamples(PdfDictionary imageDictionary, PdfContentParser ps) {
     // special case:  when no filter is specified, we just read the number of bits
     // per component, multiplied by the width and height.
     if (imageDictionary.Contains(PdfName.FILTER))
         throw new ArgumentException("Dictionary contains filters");
     
     PdfNumber h = imageDictionary.GetAsNumber(PdfName.HEIGHT);
     
     int bytesToRead = ComputeBytesPerRow(imageDictionary) * h.IntValue;
     byte[] bytes = new byte[bytesToRead];
     PRTokeniser tokeniser = ps.GetTokeniser();
     
     tokeniser.Read(); // skip next character (which better be a whitespace character - I suppose we could check for this)
     for (int i = 0; i < bytesToRead; i++){
         int ch = tokeniser.Read();
         if (ch == -1)
             throw new InlineImageParseException("End of content stream reached before end of image data");
         
         bytes[i] = (byte)ch;
     }
     PdfObject ei = ps.ReadPRObject();
     if (!ei.ToString().Equals("EI"))
         throw new InlineImageParseException("EI not found after end of image data");
     
     return bytes;
 }
開發者ID:,項目名稱:,代碼行數:36,代碼來源:


注:本文中的iTextSharp.text.pdf.PdfDictionary.Contains方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。