示例#1
0
        /* ----------------------------------------------------------------- */
        ///
        /// GetText
        ///
        /// <summary>
        /// Gets the metadata corresponding to the specified name.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private static string GetText(PdfiumReader core, string name)
        {
            var size = core.Invoke(e => PdfiumApi.FPDF_GetMetaText(e, name, null, 0));

            if (size <= 2)
            {
                return(string.Empty);
            }

            var buffer = new byte[size];

            core.Invoke(e => PdfiumApi.FPDF_GetMetaText(e, name, buffer, size));
            return(Encoding.Unicode.GetString(buffer, 0, (int)(size - 2)));
        }
示例#2
0
        /* ----------------------------------------------------------------- */
        ///
        /// Create
        ///
        /// <summary>
        /// Creates a PdfFile object from the specified arguments.
        /// </summary>
        ///
        /// <param name="core">PDFium object.</param>
        /// <param name="password">Password of the file.</param>
        /// <param name="fullaccess">
        /// Value indicating whether the loaded PDF document can be fully
        /// accessible.
        /// </param>
        ///
        /// <returns>PdfFile object.</returns>
        ///
        /* ----------------------------------------------------------------- */
        public static PdfFile Create(PdfiumReader core, string password, bool fullaccess)
        {
            var dest = core.IO.GetPdfFile(core.Source, password);

            dest.Count      = core.Invoke(NativeMethods.FPDF_GetPageCount);
            dest.FullAccess = fullaccess;
            return(dest);
        }
示例#3
0
        /* ----------------------------------------------------------------- */
        ///
        /// Create
        ///
        /// <summary>
        /// Creates a new instance of the Encryption class with the
        /// specified arguments.
        /// </summary>
        ///
        /// <param name="core">PDFium object.</param>
        /// <param name="password">Password</param>
        ///
        /// <returns>Encryption object.</returns>
        ///
        /// <remarks>
        /// 現在 FPDF_GetDocPermissions の結果で諸々の判定を行っているが
        /// 最終的には OwnerPassword で開いた状態でもオリジナルの
        /// Permission を取得する事を目指す。それに伴って、各種操作も
        /// 修正する必要がある。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        public static Encryption Create(PdfiumReader core, string password)
        {
            var method     = core.Invoke(e => PdfiumApi.FPDF_GetSecurityHandlerRevision(e));
            var permission = (uint)core.Invoke(e => PdfiumApi.FPDF_GetDocPermissions(e));
            var restrict   = permission != 0xfffffffc;

            return(method == -1 ?
                   new Encryption() :
                   new Encryption
            {
                Enabled = true,
                OwnerPassword = restrict ? string.Empty : password,
                OpenWithPassword = restrict,
                UserPassword = restrict ? password : string.Empty,
                Method = CreateMethod(method),
                Permission = new Permission(permission),
            });
        }
示例#4
0
 /* ----------------------------------------------------------------- */
 ///
 /// Create
 ///
 /// <summary>
 /// Creates a new instance of the Metadata class with the core
 /// object.
 /// </summary>
 ///
 /// <param name="core">PDFium object.</param>
 ///
 /// <returns>Metadata object.</returns>
 ///
 /* ----------------------------------------------------------------- */
 public static Metadata Create(PdfiumReader core) => core.Invoke(e => new Metadata
 {
     Version  = GetVersion(e),
     Title    = GetText(e, nameof(Metadata.Title)),
     Author   = GetText(e, nameof(Metadata.Author)),
     Subject  = GetText(e, nameof(Metadata.Subject)),
     Keywords = GetText(e, nameof(Metadata.Keywords)),
     Creator  = GetText(e, nameof(Metadata.Creator)),
     Producer = GetText(e, nameof(Metadata.Producer)),
     Options  = GetPageMode(e),
 });
示例#5
0
        /* ----------------------------------------------------------------- */
        ///
        /// Create
        ///
        /// <summary>
        /// Creates a new instance of the Encryption class with the
        /// specified arguments.
        /// </summary>
        ///
        /// <param name="core">PDFium object.</param>
        /// <param name="password">Password</param>
        ///
        /// <returns>Encryption object.</returns>
        ///
        /// <remarks>
        /// 現在 FPDF_GetDocPermissions の結果で諸々の判定を行っているが
        /// 最終的には OwnerPassword で開いた状態でもオリジナルの
        /// Permission を取得する事を目指す。それに伴って、各種操作も
        /// 修正する必要がある。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        public static Encryption Create(PdfiumReader core, string password) => core.Invoke(e =>
        {
            var method  = NativeMethods.FPDF_GetSecurityHandlerRevision(e);
            var value   = (uint)NativeMethods.FPDF_GetDocPermissions(e);
            var mask    = 0xfffffffc;
            var limited = (value & mask) != mask;
            core.LogDebug($"Permission:0x{value:X}", $"Revision:{method}");

            return(method == -1 ?
                   new Encryption() :
                   new Encryption
            {
                Enabled = true,
                OwnerPassword = limited ? string.Empty : password,
                OpenWithPassword = limited,
                UserPassword = limited ? password : string.Empty,
                Method = CreateMethod(method),
                Permission = new Permission(value),
            });
        });
示例#6
0
 /* ----------------------------------------------------------------- */
 ///
 /// Render
 ///
 /// <summary>
 /// Executes the rendering with the specified arguments.
 /// </summary>
 ///
 /// <param name="src">PDFium object.</param>
 /// <param name="dest">Graphics to be rendered.</param>
 /// <param name="page">Page object.</param>
 /// <param name="point">Starting point.</param>
 /// <param name="size">Drawing size.</param>
 /// <param name="flags">Drawing flags.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Render(this PdfiumReader src, Graphics dest, Page page,
                           PointF point, SizeF size, int flags) =>
 src.Invoke(e => Render(e, dest, page, point, size, flags));