public static DateTime?GetMetaTextAsDate(IntPtr document, string tag)
        {
            string   dt = CallNative.GetMetaText(document, tag);
            DateTime parseDate;

            if (string.IsNullOrEmpty(dt))
            {
                return(null);
            }

            Regex dtRegex =
                new Regex(
                    @"(?:D:)(?<year>\d\d\d\d)(?<month>\d\d)(?<day>\d\d)(?<hour>\d\d)(?<minute>\d\d)(?<second>\d\d)(?<tz_offset>[+-zZ])?(?<tz_hour>\d\d)?'?(?<tz_minute>\d\d)?'?");

            Match match = dtRegex.Match(dt);

            if (match.Success)
            {
                var year     = match.Groups["year"].Value;
                var month    = match.Groups["month"].Value;
                var day      = match.Groups["day"].Value;
                var hour     = match.Groups["hour"].Value;
                var minute   = match.Groups["minute"].Value;
                var second   = match.Groups["second"].Value;
                var tzOffset = match.Groups["tz_offset"]?.Value;
                var tzHour   = match.Groups["tz_hour"]?.Value;
                var tzMinute = match.Groups["tz_minute"]?.Value;

                string formattedDate = $"{year}-{month}-{day}T{hour}:{minute}:{second}.0000000";

                if (!string.IsNullOrEmpty(tzOffset))
                {
                    switch (tzOffset)
                    {
                    case "Z":
                    case "z":
                        formattedDate += "+0";
                        break;

                    case "+":
                    case "-":
                        formattedDate += $"{tzOffset}{tzHour}:{tzMinute}";
                        break;
                    }
                }

                if (!DateTime.TryParse(formattedDate, out parseDate))
                {
                    throw new FormatException();
                }

                return(parseDate);
            }

            return(null);
        }
        public bool RenderPDFPageToBitmap(int pageNumber, IntPtr bitmapHandle, int dpiX, int dpiY,
                                          int boundsOriginX, int boundsOriginY, int boundsWidth, int boundsHeight,
                                          int rotate, CallNative.FPDF flags, bool renderFormFill)
        {
            using (var pageData = new CallNative.PageData(_doc, pageNumber))
            {
                CallNative.GetFPDFRenderPageBitmap(bitmapHandle, pageData.Page, boundsOriginX, boundsOriginY,
                                                   boundsWidth, boundsHeight, 0, flags);
            }

            return(true);
        }
        public PdfInformation GetInformation()
        {
            var pdfInfo = new PdfInformation();

            pdfInfo.Creator          = CallNative.GetMetaText(_doc, "Creator");
            pdfInfo.Title            = CallNative.GetMetaText(_doc, "Title");
            pdfInfo.Author           = CallNative.GetMetaText(_doc, "Author");
            pdfInfo.Subject          = CallNative.GetMetaText(_doc, "Subject");
            pdfInfo.Keywords         = CallNative.GetMetaText(_doc, "Keywords");
            pdfInfo.Producer         = CallNative.GetMetaText(_doc, "Producer");
            pdfInfo.CreationDate     = CallNative.GetMetaTextAsDate(_doc, "CreationDate");
            pdfInfo.ModificationDate = CallNative.GetMetaTextAsDate(_doc, "ModDate");

            return(pdfInfo);
        }
        public bool LoadFile(string F)
        {
            string file = F;

            _doc = CallNative.GetFPDFLoadDocument(file, null);

            if (_doc == IntPtr.Zero)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        public Image Render(int page, int width, int height, float dpiX, float dpiY)
        {
            var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            bitmap.SetResolution(dpiX, dpiY);

            var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bitmap.PixelFormat);

            try
            {
                var handle = CallNative.GetFPDFBitmapCreateEx(width, height, 4, data.Scan0, width * 4);

                uint background = 0xFFFFFFFF;
                CallNative.GetFPDFBitmapFillRect(handle, 0, 0, width, height, background);

                this.RenderPDFPageToBitmap(
                    page,
                    handle,
                    (int)dpiX, (int)dpiY,
                    0, 0, width, height,
                    0,
                    0,
                    false);

                CallNative.GetFPDFBitmapDestroy(handle);
            }
            catch (Exception ex)
            {
                Console.Write("Unable to render PDF image.");
                throw new Win32Exception("RenderFPDFPageToBitmap.", ex);
            }

            finally
            {
                bitmap.UnlockBits(data);
            }

            return(bitmap);
        }
 public int PageCount()
 {
     return(CallNative.GetFPDFGetPageCount(_doc));
 }
 public Pdfium()
 {
     CallNative.GetFPDFInitLibrary();
 }