/* ----------------------------------------------------------------- */ /// /// FromPdf /// /// <summary> /// Creates a new instance of the PdfReader class. /// </summary> /// /// <param name="src">Path of the PDF file.</param> /// <param name="password">Password string or query.</param> /// <param name="options">Open options.</param> /// /// <returns>PdfReader object.</returns> /// /* ----------------------------------------------------------------- */ public static PdfReader FromPdf(string src, QueryMessage <IQuery <string>, string> password, OpenOption options ) { while (true) { try { var bytes = password.Value.HasValue() ? Encoding.UTF8.GetBytes(password.Value) : null; var dest = new PdfReader(src, bytes, options.SaveMemory); if (dest.IsOpenedWithFullPermissions || !options.FullAccess) { return(dest); } dest.Dispose(); throw new BadPasswordException("FullAccess"); } catch (BadPasswordException) { var msg = password.Source.Request(src); if (!msg.Cancel) { password.Value = msg.Value; } else { throw new OperationCanceledException(); } } } }
/* ----------------------------------------------------------------- */ /// /// DocumentReader /// /// <summary> /// Initializes a new instance of the DocumentReader class /// with the specified arguments. /// </summary> /// /// <param name="src">Path of the PDF file.</param> /// <param name="password">Password query or string.</param> /// <param name="options">Open options.</param> /// /* ----------------------------------------------------------------- */ private DocumentReader(string src, QueryMessage <IQuery <string>, string> password, OpenOption options ) { Core = ReaderFactory.FromPdf(src, password, options); var f = options.IO.GetPdfFile(src, password.Value); f.Count = Core.NumberOfPages; f.FullAccess = Core.IsOpenedWithFullPermissions; File = f; Metadata = Core.GetMetadata(); Encryption = Core.GetEncryption(f); Pages = new PageCollection(Core, f); Attachments = new AttachmentCollection(Core, f, options.IO); }
/* ----------------------------------------------------------------- */ /// /// GetRawReader /// /// <summary> /// Gets the PdfReader corresponding to the specified PDF file. /// </summary> /// /* ----------------------------------------------------------------- */ private PdfReader GetRawReader(PdfFile src) { var key = src.FullName; if (_hints.TryGetValue(key, out var hit)) { return(hit); } var options = new OpenOption { IO = IO, SaveMemory = false }; var reader = new DocumentReader(key, src.Password, options); _resources.Add(reader); _hints.Add(key, reader.Core); return(reader.Core); }
/* ----------------------------------------------------------------- */ /// /// DocumentReader /// /// <summary> /// Initializes a new instance of the DocumentReader class /// with the specified arguments. /// </summary> /// /// <param name="src">Path of the PDF file.</param> /// <param name="password">Password string.</param> /// <param name="options">Open options.</param> /// /* ----------------------------------------------------------------- */ public DocumentReader(string src, string password, OpenOption options) : this(src, MakeQuery(null, password), options) { }
/* ----------------------------------------------------------------- */ /// /// DocumentReader /// /// <summary> /// Initializes a new instance of the DocumentReader class /// with the specified arguments. /// </summary> /// /// <param name="src">Path of the PDF file.</param> /// <param name="query">Password query.</param> /// <param name="options">Open options.</param> /// /* ----------------------------------------------------------------- */ public DocumentReader(string src, IQuery <string> query, OpenOption options) : this(src, MakeQuery(query, string.Empty), options) { }