iTextSharp.text.pdf.PdfSignatureAppearance.SetVisibleSignature C# (CSharp) Метод

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

public SetVisibleSignature ( String fieldName ) : void
fieldName String
Результат void
        public void SetVisibleSignature(String fieldName)
        {
            AcroFields af = writer.AcroFields;
            AcroFields.Item item = af.GetFieldItem(fieldName);
            if (item == null)
                throw new ArgumentException(MessageLocalization.GetComposedMessage("the.field.1.does.not.exist", fieldName));
            PdfDictionary merged = item.GetMerged(0);
            if (!PdfName.SIG.Equals(PdfReader.GetPdfObject(merged.Get(PdfName.FT))))
                throw new ArgumentException(MessageLocalization.GetComposedMessage("the.field.1.is.not.a.signature.field", fieldName));
            this.fieldName = fieldName;
            PdfArray r = merged.GetAsArray(PdfName.RECT);
            float llx = r.GetAsNumber(0).FloatValue;
            float lly = r.GetAsNumber(1).FloatValue;
            float urx = r.GetAsNumber(2).FloatValue;
            float ury = r.GetAsNumber(3).FloatValue;
            pageRect = new Rectangle(llx, lly, urx, ury);
            pageRect.Normalize();
            page = item.GetPage(0);
            int rotation = writer.reader.GetPageRotation(page);
            Rectangle pageSize = writer.reader.GetPageSizeWithRotation(page);
            switch (rotation) {
                case 90:
                    pageRect = new Rectangle(
                    pageRect.Bottom,
                    pageSize.Top - pageRect.Left,
                    pageRect.Top,
                    pageSize.Top - pageRect.Right);
                    break;
                case 180:
                    pageRect = new Rectangle(
                    pageSize.Right - pageRect.Left,
                    pageSize.Top - pageRect.Bottom,
                    pageSize.Right - pageRect.Right,
                    pageSize.Top - pageRect.Top);
                    break;
                case 270:
                    pageRect = new Rectangle(
                    pageSize.Right - pageRect.Bottom,
                    pageRect.Left,
                    pageSize.Right - pageRect.Top,
                    pageRect.Right);
                    break;
            }
            if (rotation != 0)
                pageRect.Normalize();
            rect = new Rectangle(this.pageRect.Width, this.pageRect.Height);
        }

Same methods

PdfSignatureAppearance::SetVisibleSignature ( Rectangle pageRect, int page, String fieldName ) : void

Usage Example

Пример #1
1
        /**
         * Signs a document with a PAdES-LTV Timestamp. The document is closed at the end.
         * @param sap the signature appearance
         * @param tsa the timestamp generator
         * @param signatureName the signature name or null to have a name generated
         * automatically
         * @throws Exception
         */
        public static void Timestamp(PdfSignatureAppearance sap, ITSAClient tsa, String signatureName) {
            int contentEstimated = tsa.GetTokenSizeEstimate();
            sap.SetVisibleSignature(new Rectangle(0,0,0,0), 1, signatureName);

            PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, PdfName.ETSI_RFC3161);
            dic.Put(PdfName.TYPE, PdfName.DOCTIMESTAMP);
            sap.CryptoDictionary = dic;

            Dictionary<PdfName,int> exc = new Dictionary<PdfName,int>();
            exc[PdfName.CONTENTS] = contentEstimated * 2 + 2;
            sap.PreClose(exc);
            Stream data = sap.RangeStream;
            IDigest messageDigest = DigestUtilities.GetDigest(tsa.GetDigestAlgorithm());
            byte[] buf = new byte[4096];
            int n;
            while ((n = data.Read(buf, 0, buf.Length)) > 0) {
                messageDigest.BlockUpdate(buf, 0, n);
            }
            byte[] tsImprint = new byte[messageDigest.GetDigestSize()];
            messageDigest.DoFinal(tsImprint, 0);
            byte[] tsToken = tsa.GetTimeStampToken(tsImprint);

            if (contentEstimated + 2 < tsToken.Length)
                throw new Exception("Not enough space");

            byte[] paddedSig = new byte[contentEstimated];
            System.Array.Copy(tsToken, 0, paddedSig, 0, tsToken.Length);

            PdfDictionary dic2 = new PdfDictionary();
            dic2.Put(PdfName.CONTENTS, new PdfString(paddedSig).SetHexWriting(true));
            sap.Close(dic2);
        }
All Usage Examples Of iTextSharp.text.pdf.PdfSignatureAppearance::SetVisibleSignature