/**
  * Gets the content bytes from a content object, which may be a reference
  * a stream or an array.
  * @param contentObject the object to read bytes from
  * @return the content bytes
  * @throws IOException
  */
 public static byte[] GetContentBytesFromContentObject(PdfObject contentObject) {
     byte[] result;
     switch (contentObject.Type)
     {
         case PdfObject.INDIRECT:
             PRIndirectReference refi = (PRIndirectReference) contentObject;
             PdfObject directObject = PdfReader.GetPdfObjectRelease(refi);
             result = GetContentBytesFromContentObject(directObject);
             break;
         case PdfObject.STREAM:
             PRStream stream = (PRStream) PdfReader.GetPdfObjectRelease(contentObject);
             result = PdfReader.GetStreamBytes(stream);
             break;
         case PdfObject.ARRAY:
             // Stitch together all content before calling ProcessContent(), because
             // ProcessContent() resets state.
             MemoryStream allBytes = new MemoryStream();
             PdfArray contentArray = (PdfArray) contentObject;
             ListIterator<PdfObject> iter = contentArray.GetListIterator();
             while (iter.HasNext()) {
                 PdfObject element = iter.Next();
                 byte[] b;
                 allBytes.Write(b = GetContentBytesFromContentObject(element), 0, b.Length);
                 allBytes.WriteByte((byte)' ');
             }
             result = allBytes.ToArray();
             break;
         default:
             String msg = "Unable to handle Content of type " + contentObject.GetType();
         throw new InvalidOperationException(msg);
     }
     return result;
 }
            public void Invoke(PdfContentStreamProcessor processor,
                               PdfLiteral oper, List <iTextSharp.text.pdf.PdfObject> operands)
            {
                iTextSharp.text.pdf.PdfObject properties = operands[1];

                processor.BeginMarkedContent((PdfName)operands[0], GetPropertiesDictionary(properties, processor.resources));
            }
Exemple #3
0
 internal void AddRange(PdfString from, PdfString to, PdfObject code) {
     byte[] a1 = DecodeStringToByte(from);
     byte[] a2 = DecodeStringToByte(to);
     if (a1.Length != a2.Length || a1.Length == 0)
         throw new ArgumentException("Invalid map.");
     byte[] sout = null;
     if (code is PdfString)
         sout = DecodeStringToByte((PdfString)code);
     int start = a1[a1.Length - 1] & 0xff;
     int end = a2[a2.Length - 1] & 0xff;
     for (int k = start; k <= end; ++k) {
         a1[a1.Length - 1] = (byte)k;
         PdfString s = new PdfString(a1);
         s.SetHexWriting(true);
         if (code is PdfArray) {
             AddChar(s, ((PdfArray)code)[k - start]);
         }
         else if (code is PdfNumber) {
             int nn = ((PdfNumber)code).IntValue + k - start;
             AddChar(s, new PdfNumber(nn));
         }
         else if (code is PdfString) {
             PdfString s1 = new PdfString(sout);
             s1.SetHexWriting(true);
             ++sout[sout.Length - 1];
             AddChar(s, s1);
         }
     }
 }
Exemple #4
0
 internal bool SetField(String field, PdfObject value) {
     Dictionary<String, Object> map = fields;
     StringTokenizer tk = new StringTokenizer(field, ".");
     if (!tk.HasMoreTokens())
         return false;
     while (true) {
         String s = tk.NextToken();
         Object obj;
         map.TryGetValue(s, out obj);
         if (tk.HasMoreTokens()) {
             if (obj == null) {
                 obj = new Dictionary<String, Object>();
                 map[s] = obj;
                 map = (Dictionary<string,object>)obj;
                 continue;
             }
             else if (obj is Dictionary<String, Object>)
                 map = (Dictionary<String, Object>)obj;
             else
                 return false;
         }
         else {
             if (!(obj is Dictionary<String, Object>)) {
                 map[s] = value;
                 return true;
             }
             else
                 return false;
         }
     }
 }
Exemple #5
0
 public static PdfObject GetDirectObject(PdfObject obj) {
     if (obj == null)
         return null;
     while (obj.IsIndirect())
         obj = PdfReader.GetPdfObjectRelease(obj);
     return obj;
 }
 internal bool SetField(String field, PdfObject value) {
     Hashtable map = fields;
     StringTokenizer tk = new StringTokenizer(field, ".");
     if (!tk.HasMoreTokens())
         return false;
     while (true) {
         String s = tk.NextToken();
         Object obj = map[s];
         if (tk.HasMoreTokens()) {
             if (obj == null) {
                 obj = new Hashtable();
                 map[s] = obj;
                 map = (Hashtable)obj;
                 continue;
             }
             else if (obj is Hashtable)
                 map = (Hashtable)obj;
             else
                 return false;
         }
         else {
             if (!(obj is Hashtable)) {
                 map[s] = value;
                 return true;
             }
             else
                 return false;
         }
     }
 }
            private PdfDictionary GetPropertiesDictionary(iTextSharp.text.pdf.PdfObject operand1, ResourceDictionary resources)
            {
                if (operand1.IsDictionary())
                {
                    return((PdfDictionary)operand1);
                }

                PdfName dictionaryName = ((PdfName)operand1);

                return(resources.GetAsDict(dictionaryName));
            }
 internal override void AddChar(PdfString mark, PdfObject code) {
     if (!(code is PdfNumber))
         return;
     int codepoint;
     String s = DecodeStringToUnicode(mark);
     if (Utilities.IsSurrogatePair(s, 0))
         codepoint = Utilities.ConvertToUtf32(s, 0);
     else
         codepoint = (int)s[0];
     map[((PdfNumber)code).IntValue] = codepoint;
 }
 public override iTextSharp.text.pdf.PdfObject GetDirectObject(PdfName key)
 {
     for (int i = resourcesStack.Count - 1; i >= 0; i--)
     {
         PdfDictionary subResource = resourcesStack[i];
         if (subResource != null)
         {
             iTextSharp.text.pdf.PdfObject obj = subResource.GetDirectObject(key);
             if (obj != null)
             {
                 return(obj);
             }
         }
     }
     return(base.GetDirectObject(key)); // shouldn't be necessary, but just in case we've done something crazy
 }
Exemple #10
0
        private static List <System.Drawing.Image> ExtractImages(byte[] PDFSourcePath)
        {
            List <System.Drawing.Image> ImgList = new List <System.Drawing.Image>();

            iTextSharp.text.pdf.PdfReader PDFReaderObj = null;
            iTextSharp.text.pdf.PdfObject PDFObj       = null;
            iTextSharp.text.pdf.PdfStream PDFStremObj  = null;

            try
            {
                PDFReaderObj = new iTextSharp.text.pdf.PdfReader(PDFSourcePath, null);

                for (int i = 0; i <= PDFReaderObj.XrefSize - 1; i++)
                {
                    PDFObj = PDFReaderObj.GetPdfObject(i);

                    if ((PDFObj != null) && PDFObj.IsStream())
                    {
                        PDFStremObj = (iTextSharp.text.pdf.PdfStream)PDFObj;
                        iTextSharp.text.pdf.PdfObject subtype = PDFStremObj.Get(iTextSharp.text.pdf.PdfName.SUBTYPE);

                        if ((subtype != null) && subtype.ToString() == iTextSharp.text.pdf.PdfName.IMAGE.ToString())
                        {
                            try
                            {
                                iTextSharp.text.pdf.parser.PdfImageObject PdfImageObj =
                                    new iTextSharp.text.pdf.parser.PdfImageObject((iTextSharp.text.pdf.PRStream)PDFStremObj);

                                System.Drawing.Image ImgPDF = PdfImageObj.GetDrawingImage();


                                ImgList.Add(ImgPDF);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
                PDFReaderObj.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(ImgList);
        }
Exemple #11
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static List <System.Drawing.Image> ExtractImages(string PDFSourcePath)
        {
            List <System.Drawing.Image> imgList = new List <System.Drawing.Image>();

            RandomAccessFileOrArray RAFObj = null;
            PdfReader PDFReaderObj         = null;
            PdfObject PDFObj      = null;
            PdfStream PDFStremObj = null;

            try
            {
                RAFObj       = new RandomAccessFileOrArray(PDFSourcePath);
                PDFReaderObj = new PdfReader(RAFObj, null);
                for (int i = 0; i <= PDFReaderObj.XrefSize - 1; i++)
                {
                    PDFObj = PDFReaderObj.GetPdfObject(i);

                    if ((PDFObj != null) && PDFObj.IsStream())
                    {
                        PDFStremObj = (PdfStream)PDFObj;
                        iTextSharp.text.pdf.PdfObject subtype = PDFStremObj.Get(PdfName.SUBTYPE);

                        if ((subtype != null) && subtype.ToString() == PdfName.IMAGE.ToString())
                        {
                            try
                            {
                                PdfImageObject PdfImageObj = new PdfImageObject((PRStream)PDFStremObj);

                                System.Drawing.Image ImgPDF = PdfImageObj.GetDrawingImage();


                                imgList.Add(ImgPDF);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
                PDFReaderObj.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(imgList);
        }
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <iTextSharp.text.pdf.PdfObject> operands)
            {
                PdfName fontResourceName = (PdfName)operands[0];
                float   size             = ((PdfNumber)operands[1]).FloatValue;

                PdfDictionary         fontsDictionary = processor.resources.GetAsDict(PdfName.FONT);
                CMapAwareDocumentFont font;

                iTextSharp.text.pdf.PdfObject fontObject = fontsDictionary.Get(fontResourceName);
                if (fontObject is PdfDictionary)
                {
                    font = processor.GetFont((PdfDictionary)fontObject);
                }
                else
                {
                    font = processor.GetFont((PRIndirectReference)fontObject);
                }

                processor.Gs().font     = font;
                processor.Gs().fontSize = size;
            }
        /**
         * Displays an XObject using the registered handler for this XObject's subtype
         * @param xobjectName the name of the XObject to retrieve from the resource dictionary
         */
        private void DisplayXObject(PdfName xobjectName)
        {
            PdfDictionary xobjects = resources.GetAsDict(PdfName.XOBJECT);

            iTextSharp.text.pdf.PdfObject xobject = xobjects.GetDirectObject(xobjectName);
            PdfStream xobjectStream = (PdfStream)xobject;

            PdfName subType = xobjectStream.GetAsName(PdfName.SUBTYPE);

            if (xobject.IsStream())
            {
                IXObjectDoHandler handler;
                xobjectDoHandlers.TryGetValue(subType, out handler);
                if (handler == null)
                {
                    handler = xobjectDoHandlers[PdfName.DEFAULT];
                }
                handler.HandleXObject(this, xobjectStream, xobjects.GetAsIndirectObject(xobjectName));
            }
            else
            {
                throw new InvalidOperationException(MessageLocalization.GetComposedMessage("XObject.1.is.not.a.stream", xobjectName));
            }
        }
 virtual public void MarkUsed(PdfObject obj) {
     if (append && obj != null) {
         PRIndirectReference ref_p = null;
         if (obj.Type == PdfObject.INDIRECT)
             ref_p = (PRIndirectReference)obj;
         else
             ref_p = obj.IndRef;
         if (ref_p != null)
             marked[ref_p.Number] = 1;
     }
 }
Exemple #15
0
 virtual public void SetAccessibleAttribute(PdfName key, PdfObject value) {
     if (accessibleAttributes == null)
         accessibleAttributes = new Dictionary<PdfName, PdfObject>();
     accessibleAttributes[key] = value;
 }
 /** @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#addViewerPreference(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject) */
 internal void AddViewerPreference(PdfName key, PdfObject value) {
     this.viewerPreferences.AddViewerPreference(key, value);
 }
 internal void SweepKids(PdfObject obj) {
     PdfObject oo = PdfReader.KillIndirect(obj);
     if (oo == null || !oo.IsDictionary())
         return;
     PdfDictionary dic = (PdfDictionary)oo;
     PdfArray kids = (PdfArray)PdfReader.KillIndirect(dic.Get(PdfName.KIDS));
     if (kids == null)
         return;
     for (int k = 0; k < kids.Size; ++k) {
         SweepKids(kids.GetPdfObject(k));
     }
 }
        /**
         * Overrides the <CODE>add</CODE>-method in <CODE>PdfArray</CODE> in order to prevent the adding of extra object to the array.
         *
         * @param       object          <CODE>PdfObject</CODE> to add (will not be added here)
         * @return      <CODE>false</CODE>
         */

        public override bool Add(PdfObject obj)
        {
            return(false);
        }
            private void SerObject(PdfObject obj, int level, ByteBuffer bb, Dictionary <RefKey, int> serialized)
            {
                if (level <= 0)
                {
                    return;
                }
                if (obj == null)
                {
                    bb.Append("$Lnull");
                    return;
                }

                PdfIndirectReference refe    = null;
                ByteBuffer           savedBb = null;

                if (obj.IsIndirect())
                {
                    refe = (PdfIndirectReference)obj;
                    RefKey key = new RefKey(refe);
                    if (serialized.ContainsKey(key))
                    {
                        bb.Append(serialized[key]);
                        return;
                    }
                    else
                    {
                        savedBb = bb;
                        bb      = new ByteBuffer();
                    }
                }
                obj = PdfReader.GetPdfObject(obj);
                if (obj.IsStream())
                {
                    bb.Append("$B");
                    SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                    if (level > 0)
                    {
                        bb.Append(DigestAlgorithms.Digest("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
                    }
                }
                else if (obj.IsDictionary())
                {
                    SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                }
                else if (obj.IsArray())
                {
                    SerArray((PdfArray)obj, level - 1, bb, serialized);
                }
                else if (obj.IsString())
                {
                    bb.Append("$S").Append(obj.ToString());
                }
                else if (obj.IsName())
                {
                    bb.Append("$N").Append(obj.ToString());
                }
                else
                {
                    bb.Append("$L").Append(obj.ToString());
                }

                if (savedBb != null)
                {
                    RefKey key = new RefKey(refe);
                    if (!serialized.ContainsKey(key))
                    {
                        serialized[key] = CalculateHash(bb.Buffer);
                    }
                    savedBb.Append(bb);
                }
            }
        internal PdfStream getFormXObject(int pageNumber)
        {
            PdfDictionary page     = pages[pageNumber - 1];
            PdfObject     contents = reader.getPdfObject(page.get(PdfName.CONTENTS));
            int           length   = 0;
            int           offset   = 0;
            PdfDictionary dic      = new PdfDictionary();
            MemoryStream  bout     = null;
            ArrayList     filters  = null;

            if (contents != null)
            {
                if (contents.Type == PdfObject.STREAM)
                {
                    PRStream stream = (PRStream)contents;
                    length = stream.Length;
                    offset = stream.Offset;
                    dic.putAll(stream);
                }
                else
                {
                    PdfArray  array = (PdfArray)contents;
                    ArrayList list  = array.ArrayList;
                    bout = new MemoryStream();
                    for (int k = 0; k < list.Count; ++k)
                    {
                        PRStream  stream = (PRStream)reader.getPdfObject((PdfObject)list[k]);
                        PdfObject filter = stream.get(PdfName.FILTER);
                        byte[]    b      = new byte[stream.Length];
                        file.seek(stream.Offset);
                        file.readFully(b);
                        filters = new ArrayList();
                        if (filter != null)
                        {
                            if (filter.Type == PdfObject.NAME)
                            {
                                filters.Add(filter);
                            }
                            else if (filter.Type == PdfObject.ARRAY)
                            {
                                filters = ((PdfArray)filter).ArrayList;
                            }
                        }
                        string name;
                        for (int j = 0; j < filters.Count; ++j)
                        {
                            name = ((PdfName)filters[j]).ToString();
                            if (name.Equals("/FlateDecode") || name.Equals("/Fl"))
                            {
                                b = PdfReader.FlateDecode(b);
                            }
                            else if (name.Equals("/ASCIIHexDecode") || name.Equals("/AHx"))
                            {
                                b = PdfReader.ASCIIHexDecode(b);
                            }
                            else if (name.Equals("/ASCII85Decode") || name.Equals("/A85"))
                            {
                                b = PdfReader.ASCII85Decode(b);
                            }
                            else if (name.Equals("/LZWDecode"))
                            {
                                b = PdfReader.LZWDecode(b);
                            }
                            else
                            {
                                throw new IOException("The filter " + name + " is not supported.");
                            }
                        }
                        bout.Write(b, 0, b.Length);
                        if (k != list.Count - 1)
                        {
                            bout.WriteByte((byte)'\n');
                        }
                    }
                }
            }
            dic.put(PdfName.RESOURCES, reader.getPdfObject(page.get(PdfName.RESOURCES)));
            dic.put(PdfName.TYPE, PdfName.XOBJECT);
            dic.put(PdfName.SUBTYPE, PdfName.FORM);
            dic.put(PdfName.BBOX, new PdfRectangle(((PdfImportedPage)importedPages[pageNumber]).BoundingBox));
            dic.put(PdfName.MATRIX, IDENTITYMATRIX);
            dic.put(PdfName.FORMTYPE, ONE);
            PRStream str;

            if (bout == null)
            {
                str = new PRStream(reader, offset);
                str.putAll(dic);
                str.Length = length;
            }
            else
            {
                str = new PRStream(reader, bout.ToArray());
                str.putAll(dic);
            }
            return(str);
        }
Exemple #21
0
 /**
 * Adds a <CODE>PdfObject</CODE> to the body.
 * <P>
 * This methods creates a <CODE>PdfIndirectObject</CODE> with a
 * certain number, containing the given <CODE>PdfObject</CODE>.
 * It also adds a <CODE>PdfCrossReference</CODE> for this object
 * to an <CODE>List</CODE> that will be used to build the
 * Cross-reference Table.
 *
 * @param        object          a <CODE>PdfObject</CODE>
 * @return       a <CODE>PdfIndirectObject</CODE>
 * @throws IOException
 */
 
 internal PdfIndirectObject Add(PdfObject objecta) {
     return Add(objecta, IndirectReferenceNumber);
 }
        /**
         * Compresses the stream.
         * @param compressionLevel the compression level (0 = best speed, 9 = best compression, -1 is default)
         * @since   2.1.3
         */
        public void FlateCompress(int compressionLevel)
        {
            if (!Document.Compress)
            {
                return;
            }
            // check if the flateCompress-method has already been used
            if (compressed)
            {
                return;
            }
            this.compressionLevel = compressionLevel;
            if (inputStream != null)
            {
                compressed = true;
                return;
            }
            // check if a filter already exists
            PdfObject filter = PdfReader.GetPdfObject(Get(PdfName.FILTER));

            if (filter != null)
            {
                if (filter.IsName())
                {
                    if (PdfName.FLATEDECODE.Equals(filter))
                    {
                        return;
                    }
                }
                else if (filter.IsArray())
                {
                    if (((PdfArray)filter).Contains(PdfName.FLATEDECODE))
                    {
                        return;
                    }
                }
                else
                {
                    throw new PdfException(MessageLocalization.GetComposedMessage("stream.could.not.be.compressed.filter.is.not.a.name.or.array"));
                }
            }
            // compress
            MemoryStream          stream = new MemoryStream();
            ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, compressionLevel);

            if (streamBytes != null)
            {
                streamBytes.WriteTo(zip);
            }
            else
            {
                zip.Write(bytes, 0, bytes.Length);
            }
            //zip.Close();
            zip.Finish();
            // update the object
            streamBytes = stream;
            bytes       = null;
            Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length));
            if (filter == null)
            {
                Put(PdfName.FILTER, PdfName.FLATEDECODE);
            }
            else
            {
                PdfArray filters = new PdfArray(filter);
                filters.Add(PdfName.FLATEDECODE);
                Put(PdfName.FILTER, filters);
            }
            compressed = true;
        }
        public override void ToPdf(PdfWriter writer, Stream os)
        {
            if (inputStream != null && compressed)
            {
                Put(PdfName.FILTER, PdfName.FLATEDECODE);
            }
            PdfEncryption crypto = null;

            if (writer != null)
            {
                crypto = writer.Encryption;
            }
            if (crypto != null)
            {
                PdfObject filter = Get(PdfName.FILTER);
                if (filter != null)
                {
                    if (PdfName.CRYPT.Equals(filter))
                    {
                        crypto = null;
                    }
                    else if (filter.IsArray())
                    {
                        PdfArray a = ((PdfArray)filter);
                        if (a.Size > 0 && PdfName.CRYPT.Equals(a[0]))
                        {
                            crypto = null;
                        }
                    }
                }
            }
            PdfObject nn = Get(PdfName.LENGTH);

            if (crypto != null && nn != null && nn.IsNumber())
            {
                int sz = ((PdfNumber)nn).IntValue;
                Put(PdfName.LENGTH, new PdfNumber(crypto.CalculateStreamSize(sz)));
                SuperToPdf(writer, os);
                Put(PdfName.LENGTH, nn);
            }
            else
            {
                SuperToPdf(writer, os);
            }
            PdfWriter.CheckPdfIsoConformance(writer, PdfIsoKeys.PDFISOKEY_STREAM, this);
            os.Write(STARTSTREAM, 0, STARTSTREAM.Length);
            if (inputStream != null)
            {
                rawLength = 0;
                ZDeflaterOutputStream  def = null;
                OutputStreamCounter    osc = new OutputStreamCounter(os);
                OutputStreamEncryption ose = null;
                Stream fout = osc;
                if (crypto != null && !crypto.IsEmbeddedFilesOnly())
                {
                    fout = ose = crypto.GetEncryptionStream(fout);
                }
                if (compressed)
                {
                    fout = def = new ZDeflaterOutputStream(fout, compressionLevel);
                }

                byte[] buf = new byte[4192];
                while (true)
                {
                    int n = inputStream.Read(buf, 0, buf.Length);
                    if (n <= 0)
                    {
                        break;
                    }
                    fout.Write(buf, 0, n);
                    rawLength += n;
                }
                if (def != null)
                {
                    def.Finish();
                }
                if (ose != null)
                {
                    ose.Finish();
                }
                inputStreamLength = (int)osc.Counter;
            }
            else
            {
                if (crypto != null && !crypto.IsEmbeddedFilesOnly())
                {
                    byte[] b;
                    if (streamBytes != null)
                    {
                        b = crypto.EncryptByteArray(streamBytes.ToArray());
                    }
                    else
                    {
                        b = crypto.EncryptByteArray(bytes);
                    }
                    os.Write(b, 0, b.Length);
                }
                else
                {
                    if (streamBytes != null)
                    {
                        streamBytes.WriteTo(os);
                    }
                    else
                    {
                        os.Write(bytes, 0, bytes.Length);
                    }
                }
            }
            os.Write(ENDSTREAM, 0, ENDSTREAM.Length);
        }
        internal void Propagate(PdfObject obj, PdfIndirectReference refo, bool restricted)
        {
            if (obj == null)
            {
                return;
            }
            //        if (refo != null)
            //            AddToBody(obj, refo);
            if (obj is PdfIndirectReference)
            {
                return;
            }

            switch (obj.Type)
            {
            case PdfObject.DICTIONARY:
            case PdfObject.STREAM:
            {
                var dic = (PdfDictionary)obj;
                foreach (PdfName key in dic.Keys)
                {
                    if (restricted && (key.Equals(PdfName.Parent) || key.Equals(PdfName.Kids)))
                    {
                        continue;
                    }

                    var ob = dic.Get(key);
                    if (ob != null && ob.IsIndirect())
                    {
                        var ind = (PrIndirectReference)ob;
                        if (!SetVisited(ind) && !IsPage(ind))
                        {
                            var refi = GetNewReference(ind);
                            Propagate(PdfReader.GetPdfObjectRelease(ind), refi, restricted);
                        }
                    }
                    else
                    {
                        Propagate(ob, null, restricted);
                    }
                }
                break;
            }

            case PdfObject.ARRAY:
            {
                //PdfArray arr = new PdfArray();
                for (var it = ((PdfArray)obj).GetListIterator(); it.HasNext();)
                {
                    var ob = (PdfObject)it.Next();
                    if (ob != null && ob.IsIndirect())
                    {
                        var ind = (PrIndirectReference)ob;
                        if (!IsVisited(ind) && !IsPage(ind))
                        {
                            var refi = GetNewReference(ind);
                            Propagate(PdfReader.GetPdfObjectRelease(ind), refi, restricted);
                        }
                    }
                    else
                    {
                        Propagate(ob, null, restricted);
                    }
                }
                break;
            }

            case PdfObject.INDIRECT:
            {
                throw new Exception("Reference pointing to reference.");
            }
            }
        }
Exemple #25
0
 /**
  * @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#addViewerPreference(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject)
  */
 virtual public void AddViewerPreference(PdfName key, PdfObject value)
 {
     fc.AddViewerPreference(key, value);
 }
        /**
         * Block changes to the underlying PdfArray
         * @param object Ignored.
         * @since 2.1.5
         */

        public override void AddFirst(PdfObject obj)
        {
        }
Exemple #27
0
 internal PdfObject[] AddSimpleExtGState(PdfDictionary gstate) {
     if (!documentExtGState.ContainsKey(gstate)) {
         PdfWriter.CheckPdfIsoConformance(this, PdfIsoKeys.PDFISOKEY_GSTATE, gstate);
         documentExtGState[gstate] = new PdfObject[]{new PdfName("GS" + (documentExtGState.Count + 1)), PdfIndirectReference};
     }
     return documentExtGState[gstate];
 }
Exemple #28
0
        /**
         * @see com.lowagie.text.pdf.PdfDictionary#toPdf(com.lowagie.text.pdf.PdfWriter, java.io.OutputStream)
         */
        public override void ToPdf(PdfWriter writer, Stream os)
        {
            if (inputStream != null && compressed)
            {
                Put(PdfName.FILTER, PdfName.FLATEDECODE);
            }
            PdfEncryption crypto = null;

            if (writer != null)
            {
                crypto = writer.Encryption;
            }
            if (crypto != null)
            {
                PdfObject filter = Get(PdfName.FILTER);
                if (filter != null)
                {
                    if (PdfName.CRYPT.Equals(filter))
                    {
                        crypto = null;
                    }
                    else if (filter.IsArray())
                    {
                        PdfArray a = (PdfArray)filter;
                        if (!a.IsEmpty() && PdfName.CRYPT.Equals(a[0]))
                        {
                            crypto = null;
                        }
                    }
                }
            }
            if (crypto != null && crypto.IsEmbeddedFilesOnly())
            {
                PdfArray      filter      = new PdfArray();
                PdfArray      decodeparms = new PdfArray();
                PdfDictionary crypt       = new PdfDictionary();
                crypt.Put(PdfName.NAME, PdfName.STDCF);
                filter.Add(PdfName.CRYPT);
                decodeparms.Add(crypt);
                if (compressed)
                {
                    filter.Add(PdfName.FLATEDECODE);
                    decodeparms.Add(new PdfNull());
                }
                Put(PdfName.FILTER, filter);
                Put(PdfName.DECODEPARMS, decodeparms);
            }
            PdfObject nn = Get(PdfName.LENGTH);

            if (crypto != null && nn != null && nn.IsNumber())
            {
                int sz = ((PdfNumber)nn).IntValue;
                Put(PdfName.LENGTH, new PdfNumber(crypto.CalculateStreamSize(sz)));
                SuperToPdf(writer, os);
                Put(PdfName.LENGTH, nn);
            }
            else
            {
                SuperToPdf(writer, os);
            }

            os.Write(STARTSTREAM, 0, STARTSTREAM.Length);
            if (inputStream != null)
            {
                rawLength = 0;
                ZDeflaterOutputStream  def = null;
                OutputStreamCounter    osc = new OutputStreamCounter(os);
                OutputStreamEncryption ose = null;
                Stream fout = osc;
                if (crypto != null)
                {
                    fout = ose = crypto.GetEncryptionStream(fout);
                }
                if (compressed)
                {
                    fout = def = new ZDeflaterOutputStream(fout, compressionLevel);
                }

                byte[] buf = new byte[4192];
                while (true)
                {
                    int n = inputStream.Read(buf, 0, buf.Length);
                    if (n <= 0)
                    {
                        break;
                    }
                    fout.Write(buf, 0, n);
                    rawLength += n;
                }
                if (def != null)
                {
                    def.Finish();
                }
                if (ose != null)
                {
                    ose.Finish();
                }
                inputStreamLength = (int)osc.Counter;
            }
            else
            {
                if (crypto == null)
                {
                    if (streamBytes != null)
                    {
                        streamBytes.WriteTo(os);
                    }
                    else
                    {
                        os.Write(bytes, 0, bytes.Length);
                    }
                }
                else
                {
                    byte[] b;
                    if (streamBytes != null)
                    {
                        b = crypto.EncryptByteArray(streamBytes.ToArray());
                    }
                    else
                    {
                        b = crypto.EncryptByteArray(bytes);
                    }
                    os.Write(b, 0, b.Length);
                }
            }
            os.Write(ENDSTREAM, 0, ENDSTREAM.Length);
        }
Exemple #29
0
 protected PdfWriter.PdfBody.PdfCrossReference AddToObjStm(PdfObject obj, int nObj) {
     if (numObj >= OBJSINSTREAM)
         FlushObjStm();
     if (index == null) {
         index = new ByteBuffer();
         streamObjects = new ByteBuffer();
         currentObjNum = IndirectReferenceNumber;
         numObj = 0;
     }
     int p = streamObjects.Size;
     int idx = numObj++;
     PdfEncryption enc = writer.crypto;
     writer.crypto = null;
     obj.ToPdf(writer, streamObjects);
     writer.crypto = enc;
     streamObjects.Append(' ');
     index.Append(nObj).Append(' ').Append(p).Append(' ');
     return new PdfWriter.PdfBody.PdfCrossReference(2, nObj, currentObjNum, idx);
 }
        private ReturnType FindAndCopyMarks(PdfArray pages, int arrayNumber, int newArrayNumber)
        {
            if (pages.GetAsNumber(0).IntValue > arrayNumber)
            {
                return(ReturnType.BELOW);
            }
            if (pages.GetAsNumber(pages.Size - 2).IntValue < arrayNumber)
            {
                return(ReturnType.ABOVE);
            }
            int cur   = pages.Size / 4;
            int begin = 0;
            int curNumber;

            while (true)
            {
                curNumber = pages.GetAsNumber((begin + cur) * 2).IntValue;
                if (curNumber == arrayNumber)
                {
                    PdfObject obj  = pages[(begin + cur) * 2 + 1];
                    PdfObject obj1 = obj;
                    while (obj.IsIndirect())
                    {
                        obj = PdfReader.GetPdfObjectRelease(obj);
                    }
                    //invalid Nums
                    if (obj.IsArray())
                    {
                        PdfObject firstNotNullKid = null;
                        foreach (PdfObject numObj in (PdfArray)obj)
                        {
                            if (numObj.IsNull())
                            {
                                if (nullReference == null)
                                {
                                    nullReference = writer.AddToBody(new PdfNull()).IndirectReference;
                                }
                                structureTreeRoot.SetPageMark(newArrayNumber, nullReference);
                            }
                            else
                            {
                                PdfObject res = writer.CopyObject(numObj, true, false);
                                if (firstNotNullKid == null)
                                {
                                    firstNotNullKid = res;
                                }
                                structureTreeRoot.SetPageMark(newArrayNumber, (PdfIndirectReference)res);
                            }
                        }
                        //Add kid to structureTreeRoot from structTreeRoot
                        PdfObject structKids = structTreeRoot.Get(PdfName.K);
                        if (structKids == null || (!structKids.IsArray() && !structKids.IsIndirect()))
                        {
                            // incorrect syntax of tags
                            AddKid(structureTreeRoot, firstNotNullKid);
                        }
                        else
                        {
                            if (structKids.IsIndirect())
                            {
                                AddKid(structKids);
                            }
                            else
                            { //structKids.isArray()
                                foreach (PdfObject kid in (PdfArray)structKids)
                                {
                                    AddKid(kid);
                                }
                            }
                        }
                    }
                    else if (obj.IsDictionary())
                    {
                        PdfDictionary k = GetKDict((PdfDictionary)obj);
                        if (k == null)
                        {
                            return(ReturnType.NOTFOUND);
                        }
                        PdfObject res = writer.CopyObject(obj1, true, false);
                        structureTreeRoot.SetAnnotationMark(newArrayNumber, (PdfIndirectReference)res);
                    }
                    else
                    {
                        return(ReturnType.NOTFOUND);
                    }
                    return(ReturnType.FOUND);
                }
                if (curNumber < arrayNumber)
                {
                    begin += cur;
                    cur   /= 2;
                    if (cur == 0)
                    {
                        cur = 1;
                    }
                    if (cur + begin == pages.Size)
                    {
                        return(ReturnType.NOTFOUND);
                    }
                    continue;
                }
                if (cur + begin == 0)
                {
                    return(ReturnType.BELOW);
                }
                if (cur == 0)
                {
                    return(ReturnType.NOTFOUND);
                }
                cur /= 2;
            }
        }
Exemple #31
0
 internal PdfIndirectObject Add(PdfObject objecta, PdfIndirectReference refa, bool inObjStm) {
     return Add(objecta, refa.Number, inObjStm);
 }
        public static bool CompareObjects(PdfObject value1, PdfObject value2)
        {
            value2 = GetDirectObject(value2);
            if (value2 == null)
            {
                return(false);
            }
            if (value1.Type != value2.Type)
            {
                return(false);
            }

            if (value1.IsBoolean())
            {
                if (value1 == value2)
                {
                    return(true);
                }
                if (value2 is PdfBoolean)
                {
                    return(((PdfBoolean)value1).BooleanValue == ((PdfBoolean)value2).BooleanValue);
                }
                return(false);
            }
            else if (value1.IsName())
            {
                return(value1.Equals(value2));
            }
            else if (value1.IsNumber())
            {
                if (value1 == value2)
                {
                    return(true);
                }
                if (value2 is PdfNumber)
                {
                    return(((PdfNumber)value1).DoubleValue == ((PdfNumber)value2).DoubleValue);
                }
                return(false);
            }
            else if (value1.IsNull())
            {
                if (value1 == value2)
                {
                    return(true);
                }
                if (value2 is PdfNull)
                {
                    return(true);
                }
                return(false);
            }
            else if (value1.IsString())
            {
                if (value1 == value2)
                {
                    return(true);
                }
                if (value2 is PdfString)
                {
                    return((value2 == null && value1.ToString() == null) ||
                           value1.ToString() == value2.ToString());
                }
                return(false);
            }
            if (value1.IsArray())
            {
                PdfArray array1 = (PdfArray)value1;
                PdfArray array2 = (PdfArray)value2;
                if (array1.Size != array2.Size)
                {
                    return(false);
                }
                for (int i = 0; i < array1.Size; ++i)
                {
                    if (!CompareObjects(array1[i], array2[i]))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            if (value1.IsDictionary())
            {
                PdfDictionary first  = (PdfDictionary)value1;
                PdfDictionary second = (PdfDictionary)value2;
                if (first.Size != second.Size)
                {
                    return(false);
                }
                foreach (PdfName name in first.hashMap.Keys)
                {
                    if (!CompareObjects(first.Get(name), second.Get(name)))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
        /**
         * Translate a PRIndirectReference to a PdfIndirectReference
         * In addition, translates the object numbers, and copies the
         * referenced object to the output file if it wasn't available
         * in the cache yet. If it's in the cache, the reference to
         * the already used stream is returned.
         *
         * NB: PRIndirectReferences (and PRIndirectObjects) really need to know what
         * file they came from, because each file has its own namespace. The translation
         * we do from their namespace to ours is *at best* heuristic, and guaranteed to
         * fail under some circumstances.
         */
        protected override PdfIndirectReference CopyIndirect(PRIndirectReference inp)
        {
            PdfObject srcObj      = PdfReader.GetPdfObjectRelease(inp);
            ByteStore streamKey   = null;
            bool      validStream = false;

            if (srcObj.IsStream())
            {
                streamKey   = new ByteStore((PRStream)srcObj, serialized);
                validStream = true;
                PdfIndirectReference streamRef;
                if (streamMap.TryGetValue(streamKey, out streamRef))
                {
                    return(streamRef);
                }
            }
            else if (srcObj.IsDictionary())
            {
                streamKey   = new ByteStore((PdfDictionary)srcObj, serialized);
                validStream = true;
                PdfIndirectReference streamRef;
                if (streamMap.TryGetValue(streamKey, out streamRef))
                {
                    return(streamRef);
                }
            }

            PdfIndirectReference theRef;
            RefKey             key = new RefKey(inp);
            IndirectReferences iRef;

            indirects.TryGetValue(key, out iRef);
            if (iRef != null)
            {
                theRef = iRef.Ref;
                if (iRef.Copied)
                {
                    return(theRef);
                }
            }
            else
            {
                theRef         = body.PdfIndirectReference;
                iRef           = new IndirectReferences(theRef);
                indirects[key] = iRef;
            }
            if (srcObj.IsDictionary())
            {
                PdfObject type = PdfReader.GetPdfObjectRelease(((PdfDictionary)srcObj).Get(PdfName.TYPE));
                if (type != null)
                {
                    if ((PdfName.PAGE.Equals(type)))
                    {
                        return(theRef);
                    }
                    if ((PdfName.CATALOG.Equals(type)))
                    {
                        LOGGER.Warn(MessageLocalization.GetComposedMessage("make.copy.of.catalog.dictionary.is.forbidden"));
                        return(null);
                    }
                }
            }
            iRef.SetCopied();

            if (validStream)
            {
                streamMap[streamKey] = theRef;
            }

            PdfObject obj = CopyObject(srcObj);

            AddToBody(obj, theRef);
            return(theRef);
        }
 internal void AddClass(PdfObject obj)
 {
     obj = GetDirectObject(obj);
     if (obj.IsDictionary())
     {
         PdfObject curClass = ((PdfDictionary)obj).Get(PdfName.C);
         if (curClass == null)
         {
             return;
         }
         if (curClass.IsArray())
         {
             PdfArray array = (PdfArray)curClass;
             for (int i = 0; i < array.Size; ++i)
             {
                 AddClass(array[i]);
             }
         }
         else if (curClass.IsName())
         {
             AddClass(curClass);
         }
     }
     else if (obj.IsName())
     {
         PdfName name = (PdfName)obj;
         if (sourceClassMap == null)
         {
             obj = GetDirectObject(structTreeRoot.Get(PdfName.CLASSMAP));
             if (obj == null || !obj.IsDictionary())
             {
                 return;
             }
             sourceClassMap = (PdfDictionary)obj;
         }
         obj = GetDirectObject(sourceClassMap.Get(name));
         if (obj == null)
         {
             return;
         }
         PdfObject put = structureTreeRoot.GetMappedClass(name);
         if (put != null)
         {
             if (!CompareObjects(put, obj))
             {
                 throw new BadPdfFormatException(MessageLocalization.GetComposedMessage("conflict.in.classmap", name));
             }
         }
         else
         {
             if (obj.IsDictionary())
             {
                 structureTreeRoot.MapClass(name, GetDirectDict((PdfDictionary)obj));
             }
             else if (obj.IsArray())
             {
                 structureTreeRoot.MapClass(name, GetDirectArray((PdfArray)obj));
             }
         }
     }
 }
        private ReturnType FindAndCopyMarks(PdfArray pages, int arrayNumber, int newArrayNumber)
        {
            if (pages.GetAsNumber(0).IntValue > arrayNumber)
            {
                return(ReturnType.BELOW);
            }
            if (pages.GetAsNumber(pages.Size - 2).IntValue < arrayNumber)
            {
                return(ReturnType.ABOVE);
            }
            int cur   = pages.Size / 4;
            int begin = 0;
            int curNumber;

            while (true)
            {
                curNumber = pages.GetAsNumber((begin + cur) * 2).IntValue;
                if (curNumber == arrayNumber)
                {
                    PdfObject obj  = pages.GetPdfObject((begin + cur) * 2 + 1);
                    PdfObject obj1 = obj;
                    while (obj.IsIndirect())
                    {
                        obj = PdfReader.GetPdfObjectRelease(obj);
                    }
                    //invalid Nums
                    if (obj.IsArray())
                    {
                        PdfObject firstNotNullKid = null;
                        foreach (PdfObject numObj in (PdfArray)obj)
                        {
                            if (numObj.IsNull())
                            {
                                if (nullReference == null)
                                {
                                    nullReference = writer.AddToBody(new PdfNull()).IndirectReference;
                                }
                                structureTreeRoot.SetPageMark(newArrayNumber, nullReference);
                            }
                            else
                            {
                                PdfObject res = writer.CopyObject(numObj, true, false);
                                if (firstNotNullKid == null)
                                {
                                    firstNotNullKid = res;
                                }
                                structureTreeRoot.SetPageMark(newArrayNumber, (PdfIndirectReference)res);
                            }
                        }
                        AttachStructTreeRootKids(firstNotNullKid);
                    }
                    else if (obj.IsDictionary())
                    {
                        PdfDictionary k = GetKDict((PdfDictionary)obj);
                        if (k == null)
                        {
                            return(ReturnType.NOTFOUND);
                        }
                        PdfObject res = writer.CopyObject(obj1, true, false);
                        structureTreeRoot.SetAnnotationMark(newArrayNumber, (PdfIndirectReference)res);
                    }
                    else
                    {
                        return(ReturnType.NOTFOUND);
                    }
                    return(ReturnType.FOUND);
                }
                if (curNumber < arrayNumber)
                {
                    if (cur == 0)
                    {
                        return(ReturnType.NOTFOUND);
                    }
                    begin += cur;
                    if (cur != 1)
                    {
                        cur /= 2;
                    }
                    if (cur + begin == pages.Size)
                    {
                        return(ReturnType.NOTFOUND);
                    }
                    continue;
                }
                if (cur + begin == 0)
                {
                    return(ReturnType.BELOW);
                }
                if (cur == 0)
                {
                    return(ReturnType.NOTFOUND);
                }
                cur /= 2;
            }
        }
Exemple #36
0
        private void WriteAttributes(Paragraph paragraph)
        {
            if (paragraph != null)
            {
                this.SetAttribute(PdfName.O, PdfName.LAYOUT);
                // Setting non-inheritable attributes
                if (paragraph.SpacingBefore.CompareTo(0f) != 0)
                {
                    this.SetAttribute(PdfName.SPACEBEFORE, new PdfNumber(paragraph.SpacingBefore));
                }
                if (paragraph.SpacingAfter.CompareTo(0f) != 0)
                {
                    this.SetAttribute(PdfName.SPACEAFTER, new PdfNumber(paragraph.SpacingAfter));
                }

                // Setting inheritable attributes
                IPdfStructureElement parent = (IPdfStructureElement)this.GetParent(true);
                PdfObject            obj    = parent.GetAttribute(PdfName.COLOR);
                if ((paragraph.Font != null) && (paragraph.Font.Color != null))
                {
                    BaseColor c = paragraph.Font.Color;
                    SetColorAttribute(c, obj, PdfName.COLOR);
                }
                obj = parent.GetAttribute(PdfName.TEXTINDENT);
                if (paragraph.FirstLineIndent.CompareTo(0f) != 0)
                {
                    bool writeIndent = true;
                    if (obj is PdfNumber)
                    {
                        if (((PdfNumber)obj).FloatValue.CompareTo(paragraph.FirstLineIndent) == 0)
                        {
                            writeIndent = false;
                        }
                    }
                    if (writeIndent)
                    {
                        this.SetAttribute(PdfName.TEXTINDENT, new PdfNumber(paragraph.FirstLineIndent));
                    }
                }
                obj = parent.GetAttribute(PdfName.STARTINDENT);
                if (obj is PdfNumber)
                {
                    float startIndent = ((PdfNumber)obj).FloatValue;
                    if (startIndent.CompareTo(paragraph.IndentationLeft) != 0)
                    {
                        this.SetAttribute(PdfName.STARTINDENT, new PdfNumber(paragraph.IndentationLeft));
                    }
                }
                else
                {
                    if (Math.Abs(paragraph.IndentationLeft) > float.Epsilon)
                    {
                        this.SetAttribute(PdfName.STARTINDENT, new PdfNumber(paragraph.IndentationLeft));
                    }
                }

                obj = parent.GetAttribute(PdfName.ENDINDENT);
                if (obj is PdfNumber)
                {
                    float endIndent = ((PdfNumber)obj).FloatValue;
                    if (endIndent.CompareTo(paragraph.IndentationRight) != 0)
                    {
                        this.SetAttribute(PdfName.ENDINDENT, new PdfNumber(paragraph.IndentationRight));
                    }
                }
                else
                {
                    if (paragraph.IndentationRight.CompareTo(0) != 0)
                    {
                        this.SetAttribute(PdfName.ENDINDENT, new PdfNumber(paragraph.IndentationRight));
                    }
                }

                SetTextAlignAttribute(paragraph.Alignment);
            }
        }
 /**
 * @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#addViewerPreference(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject)
 */
 public void AddViewerPreference(PdfName key, PdfObject value) {
     fc.AddViewerPreference(key, value); 
 }
Exemple #38
0
 virtual internal protected PdfIndirectObject Add(PdfObject objecta, int refNumber, bool inObjStm) {
     if (inObjStm && objecta.CanBeInObjStm() && writer.FullCompression) {
         PdfCrossReference pxref = AddToObjStm(objecta, refNumber);
         PdfIndirectObject indirect = new PdfIndirectObject(refNumber, objecta, writer);
         xrefs.Remove(pxref);
         xrefs[pxref] = null;
         return indirect;
     }
     else {
         PdfIndirectObject indirect = new PdfIndirectObject(refNumber, objecta, writer);
         Write(indirect, refNumber);
         return indirect;
     }
 }
 /** Adds a viewer preference
 * @param preferences the viewer preferences
 * @see PdfViewerPreferences#addViewerPreference
 */
 public override void AddViewerPreference(PdfName key, PdfObject value) {
     useVp = true;
     this.viewerPreferences.AddViewerPreference(key, value);
 }
Exemple #40
0
 // constructors
 
 /**
 * Constructs a PDF-Trailer.
 *
 * @param        size        the number of entries in the <CODE>PdfCrossReferenceTable</CODE>
 * @param        offset      offset of the <CODE>PdfCrossReferenceTable</CODE>
 * @param        root        an indirect reference to the root of the PDF document
 * @param        info        an indirect reference to the info object of the PDF document
 * @param encryption
 * @param fileID
 * @param prevxref
 */
 
 public PdfTrailer(int size, long offset, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, long prevxref) {
     this.offset = offset;
     Put(PdfName.SIZE, new PdfNumber(size));
     Put(PdfName.ROOT, root);
     if (info != null) {
         Put(PdfName.INFO, info);
     }
     if (encryption != null)
         Put(PdfName.ENCRYPT, encryption);
     if (fileID != null)
         Put(PdfName.ID, fileID);
     if (prevxref > 0)
         Put(PdfName.PREV, new PdfNumber(prevxref));
 }
 internal static void FindAllObjects(PdfReader reader, PdfObject obj, IntHashtable hits) {
     if (obj == null)
         return;
     switch (obj.Type) {
         case PdfObject.INDIRECT:
             PRIndirectReference iref = (PRIndirectReference)obj;
             if (reader != iref.Reader)
                 return;
             if (hits.ContainsKey(iref.Number))
                 return;
             hits[iref.Number] = 1;
             FindAllObjects(reader, PdfReader.GetPdfObject(obj), hits);
             return;
         case PdfObject.ARRAY:
             PdfArray a = (PdfArray)obj;
             for (int k = 0; k < a.Size; ++k) {
                 FindAllObjects(reader, a[k], hits);
             }
             return;
         case PdfObject.DICTIONARY:
         case PdfObject.STREAM:
             PdfDictionary dic = (PdfDictionary)obj;
             foreach (PdfName name in dic.Keys) {
                 FindAllObjects(reader, dic.Get(name), hits);
             }
             return;
     }
 }
Exemple #42
0
 /**
 * Adds an object to the PDF body.
 * @param object
 * @param ref
 * @return a PdfIndirectObject
 * @throws IOException
 */
 public virtual PdfIndirectObject AddToBody(PdfObject objecta, PdfIndirectReference refa) {
     PdfIndirectObject iobj = body.Add(objecta, refa);
     return iobj;
 }
Exemple #43
0
 /** Adds a viewer preference
 * @param preferences the viewer preferences
 * @see PdfViewerPreferences#addViewerPreference
 */
 public virtual void AddViewerPreference(PdfName key, PdfObject value) {
     pdf.AddViewerPreference(key, value);
 }
Exemple #44
0
 /**
 * Adds an object to the PDF body.
 * @param object
 * @param refNumber
 * @param inObjStm
 * @return a PdfIndirectObject
 * @throws IOException
 */
 public PdfIndirectObject AddToBody(PdfObject objecta, int refNumber, bool inObjStm) {
     PdfIndirectObject iobj = body.Add(objecta, refNumber, inObjStm);
     return iobj;
 }
Exemple #45
0
 internal PdfObject[] AddSimpleProperty(Object prop, PdfIndirectReference refi) {
     if (!documentProperties.ContainsKey(prop)) {
         if (prop is IPdfOCG)
             PdfWriter.CheckPdfIsoConformance(this, PdfIsoKeys.PDFISOKEY_LAYER, null);
         documentProperties[prop] = new PdfObject[]{new PdfName("Pr" + (documentProperties.Count + 1)), refi};
     }
     return documentProperties[prop];
 }
Exemple #46
0
        internal PdfObject GetResources(int pageNumber)
        {
            PdfObject obj = PdfReader.GetPdfObjectRelease(reader.GetPageNRelease(pageNumber).Get(PdfName.RESOURCES));

            return(obj);
        }
Exemple #47
0
 /**
 * Sets the default colorspace that will be applied to all the document.
 * The colorspace is only applied if another colorspace with the same name
 * is not present in the content.
 * <p>
 * The colorspace is applied immediately when creating templates and at the page
 * end for the main document content.
 * @param key the name of the colorspace. It can be <CODE>PdfName.DEFAULTGRAY</CODE>, <CODE>PdfName.DEFAULTRGB</CODE>
 * or <CODE>PdfName.DEFAULTCMYK</CODE>
 * @param cs the colorspace. A <CODE>null</CODE> or <CODE>PdfNull</CODE> removes any colorspace with the same name
 */    
 public void SetDefaultColorspace(PdfName key, PdfObject cs) {
     if (cs == null || cs.IsNull())
         defaultColorspace.Remove(key);
     defaultColorspace.Put(key, cs);
 }
Exemple #48
0
        /**
         * A constructor from a <CODE>PdfReader</CODE>. It basically does everything
         * from finding the XFA stream to the XML parsing.
         * @param reader the reader
         * @throws java.io.IOException on error
         * @throws javax.xml.parsers.ParserConfigurationException on error
         * @throws org.xml.sax.SAXException on error
         */
        public XfaForm(PdfReader reader)
        {
            this.reader = reader;
            PdfDictionary af = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM));

            if (af == null)
            {
                xfaPresent = false;
                return;
            }
            PdfObject xfa = PdfReader.GetPdfObjectRelease(af.Get(PdfName.XFA));

            if (xfa == null)
            {
                xfaPresent = false;
                return;
            }
            xfaPresent = true;
            MemoryStream bout = new MemoryStream();

            if (xfa.IsArray())
            {
                ArrayList ar = ((PdfArray)xfa).ArrayList;
                for (int k = 1; k < ar.Count; k += 2)
                {
                    PdfObject ob = PdfReader.GetPdfObject((PdfObject)ar[k]);
                    if (ob != null && ob is PRStream)
                    {
                        byte[] b = PdfReader.GetStreamBytes((PRStream)ob);
                        bout.Write(b, 0, b.Length);
                    }
                }
            }
            else if (xfa is PRStream)
            {
                byte[] b = PdfReader.GetStreamBytes((PRStream)xfa);
                bout.Write(b, 0, b.Length);
            }
            bout.Seek(0, SeekOrigin.Begin);
            XmlTextReader xtr = new XmlTextReader(bout);

            domDocument = new XmlDocument();
            domDocument.Load(xtr);
            XmlNode n = domDocument.FirstChild;

            while (n.NodeType != XmlNodeType.Element)
            {
                n = n.NextSibling;
            }
            n = n.FirstChild;
            while (n != null)
            {
                if (n.NodeType == XmlNodeType.Element)
                {
                    String s = n.LocalName;
                    if (s.Equals("template"))
                    {
                        templateNode = n;
                        templateSom  = new Xml2SomTemplate(n);
                    }
                    else if (s.Equals("datasets"))
                    {
                        datasetsNode = n;
                        datasetsSom  = new Xml2SomDatasets(n.FirstChild);
                    }
                }
                n = n.NextSibling;
            }
        }
Exemple #49
0
 /**
 * Adds a <CODE>PdfObject</CODE> to the body given an already existing
 * PdfIndirectReference.
 * <P>
 * This methods creates a <CODE>PdfIndirectObject</CODE> with the number given by
 * <CODE>ref</CODE>, containing the given <CODE>PdfObject</CODE>.
 * It also adds a <CODE>PdfCrossReference</CODE> for this object
 * to an <CODE>List</CODE> that will be used to build the
 * Cross-reference Table.
 *
 * @param        object          a <CODE>PdfObject</CODE>
 * @param        ref             a <CODE>PdfIndirectReference</CODE>
 * @return       a <CODE>PdfIndirectObject</CODE>
 * @throws IOException
 */
 
 internal PdfIndirectObject Add(PdfObject objecta, PdfIndirectReference refa) {
     return Add(objecta, refa.Number);
 }
Exemple #50
0
        private void WriteAttributes(Chunk chunk)
        {
            if (chunk != null)
            {
                if (chunk.GetImage() != null)
                {
                    WriteAttributes(chunk.GetImage());
                }
                else
                {
                    Dictionary <String, Object> attr = chunk.Attributes;
                    if (attr != null)
                    {
                        this.SetAttribute(PdfName.O, PdfName.LAYOUT);
                        // Setting non-inheritable attributes
                        if (attr.ContainsKey(Chunk.UNDERLINE))
                        {
                            this.SetAttribute(PdfName.TEXTDECORATIONTYPE, PdfName.UNDERLINE);
                        }
                        if (attr.ContainsKey(Chunk.BACKGROUND))
                        {
                            Object[]  back  = (Object[])attr[Chunk.BACKGROUND];
                            BaseColor color = (BaseColor)back[0];
                            this.SetAttribute(PdfName.BACKGROUNDCOLOR,
                                              new PdfArray(new float[] { color.R / 255f, color.G / 255f, color.B / 255f }));
                        }

                        // Setting inheritable attributes
                        IPdfStructureElement parent = (IPdfStructureElement)this.GetParent(true);
                        PdfObject            obj    = parent.GetAttribute(PdfName.COLOR);
                        if ((chunk.Font != null) && (chunk.Font.Color != null))
                        {
                            BaseColor c = chunk.Font.Color;
                            SetColorAttribute(c, obj, PdfName.COLOR);
                        }
                        PdfObject decorThickness = parent.GetAttribute(PdfName.TEXTDECORATIONTHICKNESS);
                        PdfObject decorColor     = parent.GetAttribute(PdfName.TEXTDECORATIONCOLOR);
                        if (attr.ContainsKey(Chunk.UNDERLINE))
                        {
                            Object[][] unders    = (Object[][])attr[Chunk.UNDERLINE];
                            Object[]   arr       = unders[unders.Length - 1];
                            BaseColor  color     = (BaseColor)arr[0];
                            float[]    floats    = (float[])arr[1];
                            float      thickness = floats[0];
                            // Setting thickness
                            if (decorThickness is PdfNumber)
                            {
                                float t = ((PdfNumber)decorThickness).FloatValue;
                                if (thickness.CompareTo(t) != 0)
                                {
                                    this.SetAttribute(PdfName.TEXTDECORATIONTHICKNESS, new PdfNumber(thickness));
                                }
                            }
                            else
                            {
                                this.SetAttribute(PdfName.TEXTDECORATIONTHICKNESS, new PdfNumber(thickness));
                            }

                            // Setting decoration color
                            if (color != null)
                            {
                                SetColorAttribute(color, decorColor, PdfName.TEXTDECORATIONCOLOR);
                            }
                        }

                        if (attr.ContainsKey(Chunk.LINEHEIGHT))
                        {
                            float     height   = (float)attr[Chunk.LINEHEIGHT];
                            PdfObject parentLH = parent.GetAttribute(PdfName.LINEHEIGHT);
                            if (parentLH is PdfNumber)
                            {
                                float pLH = ((PdfNumber)parentLH).FloatValue;
                                if (pLH.CompareTo(height) != 0)
                                {
                                    this.SetAttribute(PdfName.LINEHEIGHT, new PdfNumber(height));
                                }
                            }
                            else
                            {
                                this.SetAttribute(PdfName.LINEHEIGHT, new PdfNumber(height));
                            }
                        }
                    }
                }
            }
        }
Exemple #51
0
 internal PdfIndirectObject Add(PdfObject objecta, int refNumber) {
     return Add(objecta, refNumber, true); // to false
 }
Exemple #52
0
        private void WriteAttributes(List list)
        {
            if (list != null)
            {
                this.SetAttribute(PdfName.O, PdfName.LIST);
                if (list.Autoindent)
                {
                    if (list.Numbered)
                    {
                        if (list.Lettered)
                        {
                            if (list.IsLowercase)
                            {
                                this.SetAttribute(PdfName.LISTNUMBERING, PdfName.LOWERROMAN);
                            }
                            else
                            {
                                this.SetAttribute(PdfName.LISTNUMBERING, PdfName.UPPERROMAN);
                            }
                        }
                        else
                        {
                            this.SetAttribute(PdfName.LISTNUMBERING, PdfName.DECIMAL);
                        }
                    }
                    else if (list.Lettered)
                    {
                        if (list.IsLowercase)
                        {
                            this.SetAttribute(PdfName.LISTNUMBERING, PdfName.LOWERALPHA);
                        }
                        else
                        {
                            this.SetAttribute(PdfName.LISTNUMBERING, PdfName.UPPERALPHA);
                        }
                    }
                }
                PdfObject obj = parent.GetAttribute(PdfName.STARTINDENT);
                if (obj is PdfNumber)
                {
                    float startIndent = ((PdfNumber)obj).FloatValue;
                    if (startIndent != list.IndentationLeft)
                    {
                        this.SetAttribute(PdfName.STARTINDENT, new PdfNumber(list.IndentationLeft));
                    }
                }
                else
                {
                    if (Math.Abs(list.IndentationLeft) > float.Epsilon)
                    {
                        this.SetAttribute(PdfName.STARTINDENT, new PdfNumber(list.IndentationLeft));
                    }
                }

                obj = parent.GetAttribute(PdfName.ENDINDENT);
                if (obj is PdfNumber)
                {
                    float endIndent = ((PdfNumber)obj).FloatValue;
                    if (endIndent != list.IndentationRight)
                    {
                        this.SetAttribute(PdfName.ENDINDENT, new PdfNumber(list.IndentationRight));
                    }
                }
                else
                {
                    if (list.IndentationRight > float.Epsilon)
                    {
                        this.SetAttribute(PdfName.ENDINDENT, new PdfNumber(list.IndentationRight));
                    }
                }
            }
        }
Exemple #53
0
 /**
 * Returns the CrossReferenceTable of the <CODE>Body</CODE>.
 * @param os
 * @param root
 * @param info
 * @param encryption
 * @param fileID
 * @param prevxref
 * @throws IOException
 */
 virtual public void WriteCrossReferenceTable(Stream os, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, long prevxref) {
     int refNumber = 0;
     if (writer.FullCompression) {
         FlushObjStm();
         refNumber = IndirectReferenceNumber;
         xrefs[new PdfCrossReference(refNumber, position)] = null;
     }
     int first = ((PdfCrossReference)xrefs.GetMinKey()).Refnum;
     int len = 0;
     List<int> sections = new List<int>();
     foreach (PdfCrossReference entry in xrefs.Keys) {
         if (first + len == entry.Refnum)
             ++len;
         else {
             sections.Add(first);
             sections.Add(len);
             first = entry.Refnum;
             len = 1;
         }
     }
     sections.Add(first);
     sections.Add(len);
     if (writer.FullCompression) {
         int mid = 5;
         long mask = 0xff00000000L;
         for (; mid > 1; --mid) {
             if ((mask & position) != 0)
                 break;
             mask >>= 8;
         }
         ByteBuffer buf = new ByteBuffer();
         
         foreach (PdfCrossReference entry in xrefs.Keys) {
             entry.ToPdf(mid, buf);
         }
         PdfStream xr = new PdfStream(buf.ToByteArray());
         buf = null;
         xr.FlateCompress(writer.CompressionLevel);
         xr.Put(PdfName.SIZE, new PdfNumber(Size));
         xr.Put(PdfName.ROOT, root);
         if (info != null) {
             xr.Put(PdfName.INFO, info);
         }
         if (encryption != null)
             xr.Put(PdfName.ENCRYPT, encryption);
         if (fileID != null)
             xr.Put(PdfName.ID, fileID);
         xr.Put(PdfName.W, new PdfArray(new int[]{1, mid, 2}));
         xr.Put(PdfName.TYPE, PdfName.XREF);
         PdfArray idx = new PdfArray();
         for (int k = 0; k < sections.Count; ++k)
             idx.Add(new PdfNumber(sections[k]));
         xr.Put(PdfName.INDEX, idx);
         if (prevxref > 0)
             xr.Put(PdfName.PREV, new PdfNumber(prevxref));
         PdfEncryption enc = writer.crypto;
         writer.crypto = null;
         PdfIndirectObject indirect = new PdfIndirectObject(refNumber, xr, writer);
         indirect.WriteTo(writer.Os);
         writer.crypto = enc;
     }
     else {
         byte[] tmp = GetISOBytes("xref\n");
         os.Write(tmp, 0, tmp.Length);
         System.Collections.IEnumerator i = xrefs.Keys;
         i.MoveNext();
         for (int k = 0; k < sections.Count; k += 2) {
             first = sections[k];
             len = sections[k + 1];
             tmp = GetISOBytes(first.ToString());
             os.Write(tmp, 0, tmp.Length);
             os.WriteByte((byte)' ');
             tmp = GetISOBytes(len.ToString());
             os.Write(tmp, 0, tmp.Length);
             os.WriteByte((byte)'\n');
             while (len-- > 0) {
                 ((PdfCrossReference)i.Current).ToPdf(os);
                 i.MoveNext();
             }
         }
     }
 }
Exemple #54
0
 public byte[] Decode(byte[] b, PdfName filterName, iTextSharp.text.pdf.PdfObject decodeParams, PdfDictionary streamDictionary)
 {
     lastFilterName = filterName;
     return(b);
 }
Exemple #55
0
 /**
 * Adds an object to the PDF body.
 * @param object
 * @return a PdfIndirectObject
 * @throws IOException
 */
 public virtual PdfIndirectObject AddToBody(PdfObject objecta) {
     PdfIndirectObject iobj = body.Add(objecta);
     return iobj;
 }
Exemple #56
0
 /**
  * Sets state of this object according to the color space
  * @param colorspace the colorspace to use
  * @param allowIndexed whether indexed color spaces will be resolved (used for recursive call)
  * @throws IOException if there is a problem with reading from the underlying stream
  */
 private void FindColorspace(iTextSharp.text.pdf.PdfObject colorspace, bool allowIndexed)
 {
     if (colorspace == null && bpc == 1)  // handle imagemasks
     {
         stride       = (width * bpc + 7) / 8;
         pngColorType = 0;
     }
     else if (PdfName.DEVICEGRAY.Equals(colorspace))
     {
         stride       = (width * bpc + 7) / 8;
         pngColorType = 0;
     }
     else if (PdfName.DEVICERGB.Equals(colorspace))
     {
         if (bpc == 8 || bpc == 16)
         {
             stride       = (width * bpc * 3 + 7) / 8;
             pngColorType = 2;
         }
     }
     else if (colorspace is PdfArray)
     {
         PdfArray ca = (PdfArray)colorspace;
         iTextSharp.text.pdf.PdfObject tyca = ca.GetDirectObject(0);
         if (PdfName.CALGRAY.Equals(tyca))
         {
             stride       = (width * bpc + 7) / 8;
             pngColorType = 0;
         }
         else if (PdfName.CALRGB.Equals(tyca))
         {
             if (bpc == 8 || bpc == 16)
             {
                 stride       = (width * bpc * 3 + 7) / 8;
                 pngColorType = 2;
             }
         }
         else if (PdfName.ICCBASED.Equals(tyca))
         {
             PRStream pr = (PRStream)ca.GetDirectObject(1);
             int      n  = pr.GetAsNumber(PdfName.N).IntValue;
             if (n == 1)
             {
                 stride       = (width * bpc + 7) / 8;
                 pngColorType = 0;
                 icc          = iTextSharp.text.pdf.PdfReader.GetStreamBytes(pr);
             }
             else if (n == 3)
             {
                 stride       = (width * bpc * 3 + 7) / 8;
                 pngColorType = 2;
                 icc          = iTextSharp.text.pdf.PdfReader.GetStreamBytes(pr);
             }
         }
         else if (allowIndexed && PdfName.INDEXED.Equals(tyca))
         {
             FindColorspace(ca.GetDirectObject(1), false);
             if (pngColorType == 2)
             {
                 iTextSharp.text.pdf.PdfObject id2 = ca.GetDirectObject(3);
                 if (id2 is PdfString)
                 {
                     palette = ((PdfString)id2).GetBytes();
                 }
                 else if (id2 is PRStream)
                 {
                     palette = iTextSharp.text.pdf.PdfReader.GetStreamBytes(((PRStream)id2));
                 }
                 stride       = (width * bpc + 7) / 8;
                 pngColorType = 3;
             }
         }
     }
 }
Exemple #57
0
 /**
 * Adds an object to the PDF body.
 * @param object
 * @param ref
 * @param inObjStm
 * @return a PdfIndirectObject
 * @throws IOException
 */
 public PdfIndirectObject AddToBody(PdfObject objecta, PdfIndirectReference refa, bool inObjStm) {
     PdfIndirectObject iobj = body.Add(objecta, refa, inObjStm);
     return iobj;
 }
Exemple #58
0
        /**
         * decodes the bytes currently captured in the streamBytes and replaces it with an image representation of the bytes
         * (this will either be a png or a tiff, depending on the color depth of the image)
         * @throws IOException
         */
        private void DecodeImageBytes()
        {
            if (streamContentType != null)
            {
                throw new ArgumentException(MessageLocalization.GetComposedMessage("Decoding.can't.happen.on.this.type.of.stream.(.1.)", streamContentType.FileExtension));
            }
            pngColorType = -1;
            PdfArray decode = dictionary.GetAsArray(PdfName.DECODE);

            width       = dictionary.GetAsNumber(PdfName.WIDTH).IntValue;
            height      = dictionary.GetAsNumber(PdfName.HEIGHT).IntValue;
            bpc         = dictionary.GetAsNumber(PdfName.BITSPERCOMPONENT).IntValue;
            pngBitDepth = bpc;
            iTextSharp.text.pdf.PdfObject colorspace = dictionary.GetDirectObject(PdfName.COLORSPACE);
            if (colorspace is PdfName && colorSpaceDic != null)
            {
                iTextSharp.text.pdf.PdfObject csLookup = colorSpaceDic.GetDirectObject((PdfName)colorspace);
                if (csLookup != null)
                {
                    colorspace = csLookup;
                }
            }

            palette = null;
            icc     = null;
            stride  = 0;
            FindColorspace(colorspace, true);
            MemoryStream ms = new MemoryStream();

            if (pngColorType < 0)
            {
                if (bpc != 8)
                {
                    throw new UnsupportedPdfException(MessageLocalization.GetComposedMessage("the.color.depth.1.is.not.supported", bpc));
                }
                if (PdfName.DEVICECMYK.Equals(colorspace))
                {
                }
                else if (colorspace is PdfArray)
                {
                    PdfArray ca = (PdfArray)colorspace;
                    iTextSharp.text.pdf.PdfObject tyca = ca.GetDirectObject(0);
                    if (!PdfName.ICCBASED.Equals(tyca))
                    {
                        throw new UnsupportedPdfException(MessageLocalization.GetComposedMessage("the.color.space.1.is.not.supported", colorspace));
                    }
                    PRStream pr = (PRStream)ca.GetDirectObject(1);
                    int      n  = pr.GetAsNumber(PdfName.N).IntValue;
                    if (n != 4)
                    {
                        throw new UnsupportedPdfException(MessageLocalization.GetComposedMessage("N.value.1.is.not.supported", n));
                    }
                    icc = iTextSharp.text.pdf.PdfReader.GetStreamBytes(pr);
                }
                else
                {
                    throw new UnsupportedPdfException(MessageLocalization.GetComposedMessage("the.color.space.1.is.not.supported", colorspace));
                }
                stride = 4 * width;
                TiffWriter wr = new TiffWriter();
                wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_SAMPLESPERPIXEL, 4));
                wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_BITSPERSAMPLE, new int[] { 8, 8, 8, 8 }));
                wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_PHOTOMETRIC, TIFFConstants.PHOTOMETRIC_SEPARATED));
                wr.AddField(new TiffWriter.FieldLong(TIFFConstants.TIFFTAG_IMAGEWIDTH, width));
                wr.AddField(new TiffWriter.FieldLong(TIFFConstants.TIFFTAG_IMAGELENGTH, height));
                wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_COMPRESSION, TIFFConstants.COMPRESSION_LZW));
                wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_PREDICTOR, TIFFConstants.PREDICTOR_HORIZONTAL_DIFFERENCING));
                wr.AddField(new TiffWriter.FieldLong(TIFFConstants.TIFFTAG_ROWSPERSTRIP, height));
                wr.AddField(new TiffWriter.FieldRational(TIFFConstants.TIFFTAG_XRESOLUTION, new int[] { 300, 1 }));
                wr.AddField(new TiffWriter.FieldRational(TIFFConstants.TIFFTAG_YRESOLUTION, new int[] { 300, 1 }));
                wr.AddField(new TiffWriter.FieldShort(TIFFConstants.TIFFTAG_RESOLUTIONUNIT, TIFFConstants.RESUNIT_INCH));
                wr.AddField(new TiffWriter.FieldAscii(TIFFConstants.TIFFTAG_SOFTWARE, iTextSharp.text.Version.GetInstance().GetVersion));
                MemoryStream comp = new MemoryStream();
                TiffWriter.CompressLZW(comp, 2, imageBytes, height, 4, stride);
                byte[] buf = comp.ToArray();
                wr.AddField(new TiffWriter.FieldImage(buf));
                wr.AddField(new TiffWriter.FieldLong(TIFFConstants.TIFFTAG_STRIPBYTECOUNTS, buf.Length));
                if (icc != null)
                {
                    wr.AddField(new TiffWriter.FieldUndefined(TIFFConstants.TIFFTAG_ICCPROFILE, icc));
                }
                wr.WriteFile(ms);
                streamContentType = ImageBytesType.CCITT;
                imageBytes        = ms.ToArray();
                return;
            }
            else
            {
                PngWriter png = new PngWriter(ms);
                if (decode != null)
                {
                    if (pngBitDepth == 1)
                    {
                        // if the decode array is 1,0, then we need to invert the image
                        if (decode.GetAsNumber(0).IntValue == 1 && decode.GetAsNumber(1).IntValue == 0)
                        {
                            int len = imageBytes.Length;
                            for (int t = 0; t < len; ++t)
                            {
                                imageBytes[t] ^= 0xff;
                            }
                        }
                        else
                        {
                            // if the decode array is 0,1, do nothing.  It's possible that the array could be 0,0 or 1,1 - but that would be silly, so we'll just ignore that case
                        }
                    }
                    else
                    {
                        // todo: add decode transformation for other depths
                    }
                }
                png.WriteHeader(width, height, pngBitDepth, pngColorType);
                if (icc != null)
                {
                    png.WriteIccProfile(icc);
                }
                if (palette != null)
                {
                    png.WritePalette(palette);
                }
                png.WriteData(imageBytes, stride);
                png.WriteEnd();
                streamContentType = ImageBytesType.PNG;
                imageBytes        = ms.ToArray();
            }
        }
Exemple #59
0
 /**
  * Adds an additional entry for the page dictionary.
  * @since 5.1.0
  */
 public void AddPageDictEntry(PdfName key, PdfObject obj) {
     pageDictEntries.Put(key, obj);
 }
 /**
  * @see com.itextpdf.text.pdf.PdfArray#add(int, com.itextpdf.text.pdf.PdfObject)
  */
 public override void Add(int index, PdfObject element)
 {
     throw new ArgumentException(MessageLocalization.GetComposedMessage("illegal.ve.value"));
 }