iTextSharp.text.pdf.AcroFields.GetFieldPositions C# (CSharp) Метод

GetFieldPositions() публичный Метод

public GetFieldPositions ( String name ) : float[]
name String
Результат float[]
        public float[] GetFieldPositions(String name) {
            Item item = GetFieldItem(name);
            if (item == null)
                return null;
            float[] ret = new float[item.Size * 5];
            int ptr = 0;
            for (int k = 0; k < item.Size; ++k) {
                try {
                    PdfDictionary wd = item.GetWidget(k);
                    PdfArray rect = wd.GetAsArray(PdfName.RECT);
                    if (rect == null)
                        continue;
                    Rectangle r = PdfReader.GetNormalizedRectangle(rect);
                    int page = item.GetPage(k);
                    int rotation = reader.GetPageRotation(page);
                    ret[ptr++] = page;
                    if (rotation != 0) {
                        Rectangle pageSize = reader.GetPageSize(page);
                        switch (rotation) {
                            case 270:
                                r = new Rectangle(
                                    pageSize.Top - r.Bottom,
                                    r.Left,
                                    pageSize.Top - r.Top,
                                    r.Right);
                                break;
                            case 180:
                                r = new Rectangle(
                                    pageSize.Right - r.Left,
                                    pageSize.Top - r.Bottom,
                                    pageSize.Right - r.Right,
                                    pageSize.Top - r.Top);
                                break;
                            case 90:
                                r = new Rectangle(
                                    r.Bottom,
                                    pageSize.Right - r.Left,
                                    r.Top,
                                    pageSize.Right - r.Right);
                                break;
                        }
                        r.Normalize();
                    }
                    ret[ptr++] = r.Left;
                    ret[ptr++] = r.Bottom;
                    ret[ptr++] = r.Right;
                    ret[ptr++] = r.Top;
                }
                catch {
                    // empty on purpose
                }
            }
            if (ptr < ret.Length) {
                float[] ret2 = new float[ptr];
                System.Array.Copy(ret, 0, ret2, 0, ptr);
                return ret2;
            }
            return ret;
        }
        

Usage Example

Пример #1
0
        public static SignaturePermissions InspectSignature(AcroFields fields, String name, SignaturePermissions perms)
        {
            IList<AcroFields.FieldPosition> fps = fields.GetFieldPositions(name);
            if (fps != null && fps.Count > 0)
            {
                AcroFields.FieldPosition fp = fps[0];
                Rectangle pos = fp.position;
                if (pos.Width == 0 || pos.Height == 0)
                {
                    Console.WriteLine("Invisible signature");
                }
                else
                {
                    Console.WriteLine("Field en página {0}; llx: {1}, lly: {2}, urx: {3}; ury: {4}",
                        fp.page, pos.Left, pos.Bottom, pos.Right, pos.Top);
                }
            }
            PdfPKCS7 pkcs7 = fields.VerifySignature(name);
            Console.WriteLine("Algoritmo de Digest: " + pkcs7.GetHashAlgorithm());
            Console.WriteLine("Algoritmo Encripción: " + pkcs7.GetEncryptionAlgorithm());
            Console.WriteLine("Filter subtype: " + pkcs7.GetFilterSubtype());
            X509Certificate cert = pkcs7.SigningCertificate;
            Console.WriteLine("Nombre del firmante: " + CertificateInfo.GetSubjectFields(cert).GetField("CN"));
            if (pkcs7.SignName != null)
                Console.WriteLine("Nombre Alternativo del firmante: " + pkcs7.SignName);

            Console.WriteLine("Firmado en: " + pkcs7.SignDate.ToString("yyyy-MM-dd HH:mm:ss.ff"));
            if (!pkcs7.TimeStampDate.Equals(DateTime.MaxValue))
            {
                Console.WriteLine("TimeStamp: " + pkcs7.TimeStampDate.ToString("yyyy-MM-dd HH:mm:ss.ff"));
                TimeStampToken ts = pkcs7.TimeStampToken;
                Console.WriteLine("TimeStamp service: " + ts.TimeStampInfo.Tsa);
                Console.WriteLine("Timestamp verificado? " + pkcs7.VerifyTimestampImprint());
            }
            Console.WriteLine("Ubicación: " + pkcs7.Location);
            Console.WriteLine("Motivo: " + pkcs7.Reason);
            PdfDictionary sigDict = fields.GetSignatureDictionary(name);
            PdfString contact = sigDict.GetAsString(PdfName.CONTACTINFO);
            if (contact != null)
                Console.WriteLine("Datos de contacto: " + contact);
            perms = new SignaturePermissions(sigDict, perms);
            Console.WriteLine("Tipo de firma: " + (perms.Certification ? "certification" : "approval"));
            //Console.WriteLine("Filling out fields allowed: " + perms.FillInAllowed);
            //Console.WriteLine("Adding annotations allowed: " + perms.AnnotationsAllowed);
            foreach (SignaturePermissions.FieldLock Lock in perms.FieldLocks)
            {
                Console.WriteLine("Lock: " + Lock);
            }
            return perms;
        }
All Usage Examples Of iTextSharp.text.pdf.AcroFields::GetFieldPositions