示例#1
0
        //
        // Static Parse - supports the PDFParsableValue attribute
        //

        #region public static PDFDocumentID Parse(string value)

        /// <summary>
        /// Parses a string value into a PDFDocumentID with the expected format as either a single Guid or a comma separated pair of Guids.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static PDFDocumentID Parse(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException(CommonErrors.CannotParseTheDocumentIDs);
            }

            try
            {
                string[] both = value.Split(',');
                Guid     one  = new Guid(both[0].Trim());

                Guid two;
                if (both.Length > 1)
                {
                    two = new Guid(both[1].Trim());
                }
                else
                {
                    two = Guid.NewGuid();
                }

                PDFDocumentID ids = PDFDocumentID.Create(one, two);
                return(ids);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(CommonErrors.CannotParseTheDocumentIDs, "value", ex);
            }
        }
示例#2
0
        protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            if (null != this.OriginalFile)
            {
                writer.OpenDocument(this.OriginalFile, true);
                PDFObjectRef catalog = this.WriteCatalog(context, writer);
                this.WriteInfo(context, writer);

                PDFDocumentID id = this.DocumentComponent.DocumentID;
                if (null == id)
                {
                    id = PDFDocumentID.Create();
                }

                writer.CloseDocument(id);

                return(catalog);
            }
            else
            {
                return(base.DoOutputToPDF(context, writer));
            }
        }
        protected virtual PDFWriterFactory GetSecureWriter(Document forDoc, IDocumentPasswordSettings settings)
        {
            if (null == forDoc)
            {
                throw new ArgumentNullException("forDoc");
            }

            SecureString owner = null;
            SecureString user  = null;

            PDFDocumentID id          = forDoc.DocumentID;
            var           permissions = forDoc.Permissions;


            if (null != settings)
            {
                owner = settings.OwnerPassword;
                user  = settings.UserPassword;
            }

            if (null == id)
            {
                id = PDFDocumentID.Create();
                forDoc.DocumentID = id;
            }

            if (null == permissions)
            {
                permissions = new DocumentPermissions();
            }

            var encFactory = permissions.GetFactory();
            var enc        = encFactory.InitEncrypter(owner, user, id, permissions.GetRestrictions(), forDoc.PerformanceMonitor);

            return(new PDFSecureWrite14Factory(enc));
        }