예제 #1
0
        public PdfGoTo createInternalLinkGoTo(string id, PdfObjectId objectId)
        {
            IDNode node = (IDNode)idReferences[id];

            node.CreateInternalLinkGoTo(objectId);
            return(node.GetInternalLinkGoTo());
        }
예제 #2
0
파일: PdfGoTo.cs 프로젝트: nholik/Fo.Net
 public PdfGoTo(PdfObjectReference pageReference, PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.Action;
     this[PdfName.Names.S] = PdfName.Names.GoTo;
     this.pageReference = pageReference;
 }
예제 #3
0
        /// <summary>
        ///     Encrypts the passed byte array using the ARC4 cipher.
        /// </summary>
        public byte[] Encrypt(byte[] data, PdfObjectId objectId)
        {
            Arc4 arc4 = new Arc4(ComputeEncryptionKey31(masterKey, objectId));

            arc4.Encrypt(data, data);
            return(data);
        }
예제 #4
0
 public PdfPageTree(PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.Pages;
     this.kids = new PdfArray();
     this[PdfName.Names.Kids] = kids;
 }
예제 #5
0
 public PdfPageTree(PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.Pages;
     this.kids = new PdfArray();
     this[PdfName.Names.Kids] = kids;
 }
예제 #6
0
        /// <summary>
        ///     Computes an encryption key that is used to encrypt string and stream data
        ///     in the PDF document.
        /// </summary>
        /// <remarks>
        ///     Corresponds to algorithm 3.1 in section 3.5 of the PDF specficiation.
        /// </remarks>
        private static byte[] ComputeEncryptionKey31(
            byte[] masterKey, PdfObjectId objectId)
        {
            byte[] key = new byte[masterKey.Length + 5];

            // Compute a hash based on:
            // a) The master key
            Array.Copy(masterKey, 0, key, 0, masterKey.Length);
            int pos = masterKey.Length;

            // b) The low order 3 bytes of the object number.
            key[pos++] = (byte)(objectId.ObjectNumber & 0xff);
            key[pos++] = (byte)((objectId.ObjectNumber >> 8) & 0xff);
            key[pos++] = (byte)((objectId.ObjectNumber >> 16) & 0xff);
            // b) The low order 2 bytes of the generation number.
            key[pos++] = (byte)(objectId.GenerationNumber & 0xff);
            key[pos++] = (byte)((objectId.GenerationNumber >> 8) & 0xff);

            MD5 md5 = MD5.Create();

            byte[] hash = md5.ComputeHash(key);

            // The first n+5 bytes of the computed hash consitute the encryption key.
            Array.Copy(hash, 0, key, 0, masterKey.Length + 5);
            return(key);
        }
예제 #7
0
 public PdfXObject(byte[] objectData, PdfName name, PdfObjectId objectId)
     : base(objectId)
 {
     this.objectData = objectData;
     this.name       = name;
     dictionary[PdfName.Names.Type] = PdfName.Names.XObject;
 }
예제 #8
0
 public PdfFontDescriptor(
     string fontName, PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.Type]     = PdfName.Names.Font;
     this[PdfName.Names.FontName] = new PdfName(fontName);
 }
예제 #9
0
 public PdfType1Font(
     PdfObjectId objectId, string fontName, string baseFont)
     : base(fontName, objectId)
 {
     this[PdfName.Names.Subtype]  = PdfName.Names.Type1;
     this[PdfName.Names.BaseFont] = new PdfName(baseFont);
 }
예제 #10
0
파일: PdfXObject.cs 프로젝트: nholik/Fo.Net
 public PdfXObject(byte[] objectData, PdfName name, PdfObjectId objectId)
     : base(objectId)
 {
     this.objectData = objectData;
     this.name = name;
     dictionary[PdfName.Names.Type] = PdfName.Names.XObject;
 }
예제 #11
0
 public PdfType1Font(
     PdfObjectId objectId, string fontName, string baseFont)
     : base(fontName, objectId)
 {
     this[PdfName.Names.Subtype] = PdfName.Names.Type1;
     this[PdfName.Names.BaseFont] = new PdfName(baseFont);
 }
예제 #12
0
 public PdfGoTo(PdfObjectReference pageReference, PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.Action;
     this[PdfName.Names.S]    = PdfName.Names.GoTo;
     this.pageReference       = pageReference;
 }
예제 #13
0
            public IndirectObject CreateInstance(PdfObjectId objectId, PdfObject referencedObject, bool isReadOnly)
            {
                var objectType = referencedObject.GetType();

                var genCtor = ctorCache.GetOrAdd(objectType, GetConstructorForType);

                return((IndirectObject)genCtor.Invoke(new object[] { objectId, referencedObject, isReadOnly }));
            }
예제 #14
0
 /// <param name="objectId">
 ///     A unique object number.
 /// </param>
 /// <param name="fontName">
 ///     The name by which the font is reference in the Font subdictionary
 /// </param>
 /// <param name="baseFont">
 ///     The PostScript name of the font.
 /// </param>
 public PdfTrueTypeFont(PdfObjectId objectId, string fontName, string baseFont)
     : base(fontName, objectId)
 {
     this[PdfName.Names.Subtype]   = PdfName.Names.TrueType;
     this[PdfName.Names.BaseFont]  = new PdfName(baseFont);
     this[PdfName.Names.FirstChar] = new PdfNumeric(0);
     this[PdfName.Names.LastChar]  = new PdfNumeric(255);
 }
예제 #15
0
 /// <param name="objectId">
 ///     A unique object number.
 /// </param>
 /// <param name="fontName">
 ///     The name by which the font is reference in the Font subdictionary 
 /// </param>
 /// <param name="baseFont">
 ///     The PostScript name of the font.
 /// </param>
 public PdfTrueTypeFont(PdfObjectId objectId, string fontName, string baseFont)
     : base(fontName, objectId)
 {
     this[PdfName.Names.Subtype] = PdfName.Names.TrueType;
     this[PdfName.Names.BaseFont] = new PdfName(baseFont);
     this[PdfName.Names.FirstChar] = new PdfNumeric(0);
     this[PdfName.Names.LastChar] = new PdfNumeric(255);
 }
예제 #16
0
 public PdfGoToRemote(PdfFileSpec fileSpec, PdfObjectId objectId)
     : base(objectId)
 {
     this.fileSpec            = fileSpec;
     this[PdfName.Names.Type] = PdfName.Names.Action;
     this[PdfName.Names.S]    = PdfName.Names.GoToR;
     this[PdfName.Names.F]    = fileSpec.GetReference();
     this[PdfName.Names.D]    = DefaultDestination;
 }
예제 #17
0
 public PdfGoToRemote(PdfFileSpec fileSpec, PdfObjectId objectId)
     : base(objectId)
 {
     this.fileSpec = fileSpec;
     this[PdfName.Names.Type] = PdfName.Names.Action;
     this[PdfName.Names.S] = PdfName.Names.GoToR;
     this[PdfName.Names.F] = fileSpec.GetReference();
     this[PdfName.Names.D] = DefaultDestination;
 }
예제 #18
0
파일: PDFCIDFont.cs 프로젝트: nholik/Fo.Net
 public PdfCIDFont(
     PdfObjectId objectId, PdfFontSubTypeEnum subType, string baseFont)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.Font;
     this[PdfName.Names.Subtype] = new PdfName(subType.ToString());
     this[PdfName.Names.BaseFont] = new PdfName(baseFont);
     this[PdfName.Names.DW] = new PdfNumeric(1000);
     this[PdfName.Names.CIDToGIDMap] = PdfName.Names.Identity;
 }
예제 #19
0
 public PdfCIDFont(
     PdfObjectId objectId, PdfFontSubTypeEnum subType, string baseFont)
     : base(objectId)
 {
     this[PdfName.Names.Type]        = PdfName.Names.Font;
     this[PdfName.Names.Subtype]     = new PdfName(subType.ToString());
     this[PdfName.Names.BaseFont]    = new PdfName(baseFont);
     this[PdfName.Names.DW]          = new PdfNumeric(1000);
     this[PdfName.Names.CIDToGIDMap] = PdfName.Names.Identity;
 }
예제 #20
0
 public PdfDictionary GetEncrypt(PdfObjectId objectId)
 {
     PdfDictionary encrypt = new PdfDictionary(objectId);
     encrypt[PdfName.Names.Filter] = PdfName.Names.Standard;
     encrypt[PdfName.Names.V] = new PdfNumeric(1);
     encrypt[PdfName.Names.Length] = new PdfNumeric(40);
     encrypt[PdfName.Names.R] = new PdfNumeric(2);
     PdfString o = new PdfString(ownerEntry);
     o.NeverEncrypt = true;
     encrypt[PdfName.Names.O] = o;
     PdfString u = new PdfString(userEntry);
     u.NeverEncrypt = true;
     encrypt[PdfName.Names.U] = u;
     encrypt[PdfName.Names.P] = new PdfNumeric(permissions);
     return encrypt;
 }
예제 #21
0
        internal void CreateInternalLinkGoTo(PdfObjectId objectId)
        {
            if (internalLinkGoToPageReference == null)
            {
                internalLinkGoTo = new PdfGoTo(null, objectId);
            }
            else
            {
                internalLinkGoTo = new PdfGoTo(internalLinkGoToPageReference, objectId);
            }

            if (xPosition != 0)
            {
                internalLinkGoTo.X = xPosition;
                internalLinkGoTo.Y = yPosition;
            }
        }
예제 #22
0
        public PdfDictionary GetEncrypt(PdfObjectId objectId)
        {
            PdfDictionary encrypt = new PdfDictionary(objectId);

            encrypt[PdfName.Names.Filter] = PdfName.Names.Standard;
            encrypt[PdfName.Names.V]      = new PdfNumeric(1);
            encrypt[PdfName.Names.Length] = new PdfNumeric(40);
            encrypt[PdfName.Names.R]      = new PdfNumeric(2);
            PdfString o = new PdfString(ownerEntry);

            o.NeverEncrypt           = true;
            encrypt[PdfName.Names.O] = o;
            PdfString u = new PdfString(userEntry);

            u.NeverEncrypt           = true;
            encrypt[PdfName.Names.U] = u;
            encrypt[PdfName.Names.P] = new PdfNumeric(permissions);
            return(encrypt);
        }
예제 #23
0
파일: PdfPage.cs 프로젝트: nholik/Fo.Net
        public PdfPage(
            PdfResources resources,
            PdfContentStream contents,
            int pagewidth,
            int pageheight,
            PdfObjectId objectId)
            : base(objectId)
        {
            this[PdfName.Names.Type] = PdfName.Names.Page;
            this[PdfName.Names.Resources] = resources.GetReference();
            this[PdfName.Names.Contents] = contents.GetReference();

            PdfArray mediaBox = new PdfArray();
            mediaBox.Add(new PdfNumeric(0));
            mediaBox.Add(new PdfNumeric(0));
            mediaBox.Add(new PdfNumeric(pagewidth));
            mediaBox.Add(new PdfNumeric(pageheight));
            this[PdfName.Names.MediaBox] = mediaBox;
        }
예제 #24
0
        public PdfPage(
            PdfResources resources,
            PdfContentStream contents,
            int pagewidth,
            int pageheight,
            PdfObjectId objectId)
            : base(objectId)
        {
            this[PdfName.Names.Type]      = PdfName.Names.Page;
            this[PdfName.Names.Resources] = resources.GetReference();
            this[PdfName.Names.Contents]  = contents.GetReference();

            PdfArray mediaBox = new PdfArray();

            mediaBox.Add(new PdfNumeric(0));
            mediaBox.Add(new PdfNumeric(0));
            mediaBox.Add(new PdfNumeric(pagewidth));
            mediaBox.Add(new PdfNumeric(pageheight));
            this[PdfName.Names.MediaBox] = mediaBox;
        }
예제 #25
0
 /// <summary>
 /// Instanciates a new IndirectObject
 /// </summary>
 /// <param name="objectId">The <see cref="PdfObjectId"/> of the referenced object</param>
 /// <param name="referencedObject">Referenced <see cref="PdfObject"/></param>
 /// <param name="isReadOnly">True if object is read-only, otherwise false.</param>
 protected IndirectObject(PdfObjectId objectId, PdfObject referencedObject, bool isReadOnly) : base(isReadOnly)
 {
     this.objectId         = objectId;
     this.referencedObject = referencedObject;
 }
예제 #26
0
 /// <summary>
 /// Instanciates a new IndirectObject
 /// </summary>
 /// <param name="objectId">The <see cref="PdfObjectId"/> of the referenced object</param>
 /// <param name="referencedObject">Referenced <see cref="PdfObject"/></param>
 protected IndirectObject(PdfObjectId objectId, PdfObject referencedObject)
 {
     this.objectId         = objectId;
     this.referencedObject = referencedObject;
 }
예제 #27
0
 public PdfAnnotList(PdfObjectId objectId) : base(objectId)
 {
 }
예제 #28
0
 /// <summary>
 ///     Adds an entry to the table.
 /// </summary>
 public void Add(PdfObjectId objectId, long offset)
 {
     section.Add(objectId, offset);
 }
예제 #29
0
 public PdfResources(PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.ProcSet] = DefaultProcedureSets;
 }
예제 #30
0
 public PdfBoolean(bool val, PdfObjectId objectId)
     : base(objectId)
 {
     this.val = val;
 }
예제 #31
0
        /// <summary>
        ///     Computes an encryption key that is used to encrypt string and stream data 
        ///     in the PDF document.
        /// </summary>
        /// <remarks>
        ///     Corresponds to algorithm 3.1 in section 3.5 of the PDF specficiation.
        /// </remarks>
        private static byte[] ComputeEncryptionKey31(
            byte[] masterKey, PdfObjectId objectId)
        {
            byte[] key = new byte[masterKey.Length + 5];

            // Compute a hash based on:
            // a) The master key
            Array.Copy(masterKey, 0, key, 0, masterKey.Length);
            int pos = masterKey.Length;
            // b) The low order 3 bytes of the object number.
            key[pos++] = (byte)(objectId.ObjectNumber & 0xff);
            key[pos++] = (byte)((objectId.ObjectNumber >> 8) & 0xff);
            key[pos++] = (byte)((objectId.ObjectNumber >> 16) & 0xff);
            // b) The low order 2 bytes of the generation number.
            key[pos++] = (byte)(objectId.GenerationNumber & 0xff);
            key[pos++] = (byte)((objectId.GenerationNumber >> 8) & 0xff);

            MD5 md5 = MD5.Create();
            byte[] hash = md5.ComputeHash(key);

            // The first n+5 bytes of the computed hash consitute the encryption key.
            Array.Copy(hash, 0, key, 0, masterKey.Length + 5);
            return key;
        }
예제 #32
0
파일: XRefTable.cs 프로젝트: nholik/Fo.Net
 /// <summary>
 ///     Adds an entry to the table.
 /// </summary>
 public void Add(PdfObjectId objectId, long offset)
 {
     section.Add(objectId, offset);
 }
예제 #33
0
파일: PdfBoolean.cs 프로젝트: nholik/Fo.Net
 public PdfBoolean(bool val, PdfObjectId objectId)
     : base(objectId)
 {
     this.val = val;
 }
예제 #34
0
 public PdfResources(PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.ProcSet] = DefaultProcedureSets;
 }
예제 #35
0
파일: PdfCatalog.cs 프로젝트: nholik/Fo.Net
 public PdfCatalog(PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.Catalog;
 }
예제 #36
0
 /// <summary>
 /// Instanciates a new IndirectReference
 /// </summary>
 /// <param name="objectId">Referenced <see cref="PdfObjectId"/></param>
 public IndirectReference(PdfObjectId objectId) : base(objectId, null)
 {
 }
예제 #37
0
 /// <summary>
 ///     Adds an entry to the section.
 /// </summary>
 internal void Add(PdfObjectId objectId, long offset)
 {
     subsection.Add(objectId, offset);
 }
예제 #38
0
 public PdfICCStream(PdfObjectId id, byte[] profileData)
     : base(id)
 {
     this.data = profileData;
 }
예제 #39
0
 /// <summary>
 /// Instanciates a new PDF object reference.
 /// </summary>
 /// <param name="objectId">The referenced object's <see cref="PdfObjectId"/>.</param>
 protected PdfObjectReferenceBase(PdfObjectId objectId)
 {
     this.objectId = objectId;
 }
예제 #40
0
 /// <summary>
 ///     Encrypts the passed byte array using the ARC4 cipher.
 /// </summary>
 public byte[] Encrypt(byte[] data, PdfObjectId objectId)
 {
     Arc4 arc4 = new Arc4(ComputeEncryptionKey31(masterKey, objectId));
     arc4.Encrypt(data, data);
     return data;
 }
예제 #41
0
파일: PdfFont.cs 프로젝트: nholik/Fo.Net
 public PdfFont(string fontname, PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.Font;
     this[PdfName.Names.Name] = new PdfName(fontname);
 }
예제 #42
0
 /// <summary>
 ///     Adds an entry to the section.
 /// </summary>
 internal void Add(PdfObjectId objectId, long offset)
 {
     subsection.Add(objectId, offset);
 }
예제 #43
0
 public PdfFileSpec(PdfObjectId objectId, string filename)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.FileSpec;
     this[PdfName.Names.F] = new PdfString(filename);
 }
예제 #44
0
 public PdfCatalog(PdfObjectId objectId)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.Catalog;
 }
예제 #45
0
파일: PdfNumeric.cs 프로젝트: nholik/Fo.Net
 public PdfNumeric(decimal val, PdfObjectId objectId)
     : base(objectId)
 {
     this.val = val;
 }
예제 #46
0
 public PdfInfo(PdfObjectId objectId) : base(objectId)
 {
 }
예제 #47
0
        /// <summary>
        /// Reads next <see cref="PdfObject"/> from PDF stream.
        /// </summary>
        /// <param name="reader">The <see cref="PdfReader"/> to use.</param>
        /// <returns>Read PdfObject.</returns>
        public static PdfObject ReadObject(this PdfReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            reader.MoveToNonWhiteSpace();

            char firstChar = reader.Peek();

            switch (firstChar)
            {
            case '%':
                // Skip comment
                reader.SkipWhile(c => !Chars.IsEndOfLine(c));
                reader.SkipWhile(Chars.IsEndOfLine);
                // Then try read next object
                return(ReadObject(reader));

            case 't':
                reader.ReadToken(BooleanObject.TrueToken);
                return(new BooleanObject(true, true));

            case 'f':
                reader.ReadToken(BooleanObject.FalseToken);
                return(new BooleanObject(false, true));

            case 'n':
                reader.ReadToken(NullObject.NullToken);
                return(new NullObject());

            case '(':
                return(LiteralStringObject.FromReader(reader));

            case '<':
                if (reader.Peek(1) == '<')
                {
                    return(DictionaryObject.FromReader(reader));
                }
                else
                {
                    return(HexadecimalStringObject.FromReader(reader));
                }

            case '/':
                return(NameObject.FromReader(reader));

            case '[':
                return(ArrayObject.FromReader(reader));

            case '+':
            case '-':
                return(NumericObject.FromReader(reader));
            }
            if (char.IsDigit(firstChar))
            {
                int indRefLength = IsIndirectReference(reader);
                if (indRefLength >= 5)
                {
                    var indRefStr = reader.ReadString(indRefLength);
                    var objectId  = PdfObjectId.FromString(indRefStr.Substring(0, indRefLength - 2));

                    return(new IndirectReference(objectId));
                }

                return(NumericObject.FromReader(reader));
            }
            throw new NotImplementedException();
        }
예제 #48
0
파일: PdfInfo.cs 프로젝트: nholik/Fo.Net
 public PdfInfo(PdfObjectId objectId) : base(objectId) { }
예제 #49
0
 public PdfAnnotList(PdfObjectId objectId) : base(objectId)
 {
 }
예제 #50
0
 public PdfFileSpec(PdfObjectId objectId, string filename)
     : base(objectId)
 {
     this[PdfName.Names.Type] = PdfName.Names.FileSpec;
     this[PdfName.Names.F]    = new PdfString(filename);
 }
예제 #51
0
 public PdfICCStream(PdfObjectId id, byte[] profileData)
     : base(id)
 {
     this.data = profileData;
 }
예제 #52
0
 public PdfNumeric(decimal val, PdfObjectId objectId)
     : base(objectId)
 {
     this.val = val;
 }