Beispiel #1
0
        /// <summary>
        /// Renders a page of the PDF document to an image.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="width">Width of the rendered image.</param>
        /// <param name="height">Height of the rendered image.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        /// <returns>The rendered image.</returns>
        public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRenderFlags flags)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if ((flags & PdfRenderFlags.CorrectFromDpi) != 0)
            {
                width  = width / 72 * (int)dpiX;
                height = height / 72 * (int)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 = NativeMethods.FPDFBitmap_CreateEx(width, height, 4, data.Scan0, width * 4);

                try
                {
                    uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                    NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, width, height, background);

                    bool success = _file.RenderPDFPageToBitmap(
                        page,
                        handle,
                        (int)dpiX, (int)dpiY,
                        0, 0, width, height,
                        FlagsToFPDFFlags(flags)
                        );

                    if (!success)
                    {
                        throw new Win32Exception();
                    }
                }
                finally
                {
                    NativeMethods.FPDFBitmap_Destroy(handle);
                }
            }
            finally
            {
                bitmap.UnlockBits(data);
            }

            return(bitmap);
        }
Beispiel #2
0
 /// <summary>
 /// Renders the page.
 /// </summary>
 /// <param name="width">
 /// The full width of the rendered image in px.
 /// If 0, width will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="height">
 /// The full wiheightth of the rendered image in px .
 /// If 0, height will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="rotate">Specify rotation.</param>
 /// <param name="flags">Specify flags.</param>
 /// <returns>Image from the page.</returns>
 public Image Render(int width, int height, PdfRotation rotate, PdfRenderFlags flags)
 {
     if (height == 0 && width != 0)
     {
         height = (int)((float)width * (Height / Width));
     }
     else if (height != 0 && width == 0)
     {
         width = (int)((float)height * (int)(Width / Height));
     }
     else if (height == 0 && width == 0)
     {
         throw new ArgumentException();
     }
     return(Render(width, height, 0, 0, width, height, 0, 0, rotate, flags));
 }
Beispiel #3
0
        /// <summary>
        /// Renders a page of the PDF document to an image.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="width">Width of the rendered image.</param>
        /// <param name="height">Height of the rendered image.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="rotate">Rotation.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        /// <param name="renderFormFill">Render form fills.</param>
        /// <returns>The rendered image.</returns>
        public SKBitmap Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags, bool renderFormFill)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if ((flags & PdfRenderFlags.CorrectFromDpi) != 0)
            {
                width  = width * (int)dpiX / 72;
                height = height * (int)dpiY / 72;
            }

            var bitmap = new SKBitmap(width, height);
            var handle = NativeMethods.FPDFBitmap_CreateEx(width, height, 4, bitmap.GetPixels(), width * 4);

            try
            {
                uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, width, height, background);

                bool success = _file !.RenderPDFPageToBitmap(
                    page,
                    handle,
                    0, 0, width, height,
                    (int)rotate,
                    FlagsToFPDFFlags(flags),
                    renderFormFill
                    );

                if (!success)
                {
                    throw new Win32Exception();
                }
            }
            finally
            {
                NativeMethods.FPDFBitmap_Destroy(handle);
            }

            return(bitmap);
        }
Beispiel #4
0
        /// <summary>
        /// Renders a page of the PDF document to an image.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="width">Width of the rendered image.</param>
        /// <param name="height">Height of the rendered image.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        /// <returns>The rendered image.</returns>
        public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRenderFlags flags)
        {
            if (_disposed)
                throw new ObjectDisposedException(GetType().Name);

            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 = NativeMethods.FPDFBitmap_CreateEx(width, height, 4, data.Scan0, width * 4);

                try
                {
                    uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                    NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, width, height, background);

                    bool success = _file.RenderPDFPageToBitmap(
                        page,
                        handle,
                        (int)dpiX, (int)dpiY,
                        0, 0, width, height,
                        FlagsToFPDFFlags(flags)
                    );

                    if (!success)
                        throw new Win32Exception();
                }
                finally
                {
                    NativeMethods.FPDFBitmap_Destroy(handle);
                }
            }
            finally
            {
                bitmap.UnlockBits(data);
            }

            return bitmap;
        }
 public void Render(int page, Graphics graphics, float dpiX, float dpiY, Rectangle bounds, PdfRenderFlags flags)
 {
     _document.Render(TranslatePage(page), graphics, dpiX, dpiY, bounds, flags);
 }
 public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRenderFlags flags)
 {
     return(_document.Render(TranslatePage(page), width, height, dpiX, dpiY, flags));
 }
Beispiel #7
0
 private NativeMethods.FPDF _flagsToFPDFFlags(PdfRenderFlags flags)
 {
     return((NativeMethods.FPDF)(flags & ~(PdfRenderFlags.Transparent | PdfRenderFlags.CorrectFromDpi)));
 }
Beispiel #8
0
        /// <summary>
        /// Renders a page of the PDF document to an image.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        /// <returns>The rendered image.</returns>
        public Image Render(int page, float dpiX, float dpiY, PdfRenderFlags flags)
        {
            var size = PageSizes[page];

            return(Render(page, (int)size.Width, (int)size.Height, dpiX, dpiY, flags));
        }
Beispiel #9
0
 /// <summary>
 /// Renders a page of the PDF document to an image.
 /// </summary>
 /// <param name="page">Number of the page to render.</param>
 /// <param name="width">Width of the rendered image.</param>
 /// <param name="height">Height of the rendered image.</param>
 /// <param name="dpiX">Horizontal DPI.</param>
 /// <param name="dpiY">Vertical DPI.</param>
 /// <param name="flags">Flags used to influence the rendering.</param>
 /// <returns>The rendered image.</returns>
 public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRenderFlags flags)
 {
     return Render(page, width, height, dpiX, dpiY, 0, flags);
 }
Beispiel #10
0
 /// <summary>
 /// Renders a page of the PDF document to an image.
 /// </summary>
 /// <param name="page">Number of the page to render.</param>
 /// <param name="width">Width of the rendered image.</param>
 /// <param name="height">Height of the rendered image.</param>
 /// <param name="dpiX">Horizontal DPI.</param>
 /// <param name="dpiY">Vertical DPI.</param>
 /// <param name="flags">Flags used to influence the rendering.</param>
 /// <returns>The rendered image.</returns>
 public RawRenderData Render(int page, int width, int height, float dpiX, float dpiY, PdfRenderFlags flags)
 {
     return(Render(page, width, height, dpiX, dpiY, 0, flags));
 }
Beispiel #11
0
        /// <summary>
        /// Renders the page.
        /// </summary>
        /// <param name="width">
        /// The full width of the rendered image in px or percentage (if dpiX and dpiY are specified).
        /// If 0, width will be calculated from height using the correct apsect ratio.
        /// Height and width can not be both set to zero.
        /// </param>
        /// <param name="height">
        /// The full wiheightth of the rendered image in px or percentage (if dpiX and dpiY are specified).
        /// If 0, height will be calculated from height using the correct apsect ratio.
        /// Height and width can not be both set to zero.
        /// </param>
        /// <param name="clipX">X value of the start point of the clipping area</param>
        /// <param name="clipY">Y value of the start point of the clipping area</param>
        /// <param name="clipWidth">Width of the clip area</param>
        /// <param name="clipHeight">Height of the clip area</param>
        /// <param name="dpiX">DPI to render page. If set, width and height will accept percentage.</param>
        /// <param name="dpiY">DPI to render page. If set, width and height will accept percentage.</param>
        /// <param name="rotate">Specify rotation.</param>
        /// <param name="flags">Specify flags.</param>
        /// <returns>Image from the page.</returns>
        public Image Render(int width, int height, int clipX, int clipY, int clipWidth, int clipHeight, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(PdfPage));
            }

            if (height == 0 && width != 0)
            {
                height = width * (int)(Height / Width);
            }
            else if (height != 0 && width == 0)
            {
                width = height * (int)(Width / Height);
            }
            else if (height == 0 && width == 0)
            {
                throw new ArgumentException();
            }

            if (dpiX != 0 && dpiY != 0)
            {
                clipWidth  = (int)(clipWidth / 100f * width / 100f * Width * 0.013888888888889 * dpiX);
                clipHeight = (int)(clipHeight / 100f * height / 100f * Height * 0.013888888888889 * dpiY);
                width      = (int)(width / 100f * Width * 0.013888888888889 * dpiX);
                height     = (int)(height / 100f * Height * 0.013888888888889 * dpiY);
            }

            var bitmap = new Bitmap(clipWidth, clipHeight, PixelFormat.Format32bppArgb);

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

            try
            {
                var handle = NativeMethods.FPDFBitmap_CreateEx(clipWidth, clipHeight, 4, data.Scan0, clipWidth * 4);

                try
                {
                    uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                    NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, clipWidth, clipHeight, background);

                    bool success = RenderPDFPageToBitmap(
                        handle,
                        (int)dpiX, (int)dpiY, -clipX, -clipY, width, height,
                        (int)rotate,
                        FlagsToFPDFFlags(flags),
                        (flags & PdfRenderFlags.Annotations) != 0
                        );

                    if (!success)
                    {
                        throw new Exception();
                    }
                }
                finally
                {
                    NativeMethods.FPDFBitmap_Destroy(handle);
                }
            }
            finally
            {
                bitmap.UnlockBits(data);
            }

            return(bitmap);
        }
Beispiel #12
0
 private NativeMethods.FPDF FlagsToFPDFFlags(PdfRenderFlags flags)
 {
     return (NativeMethods.FPDF)(flags & ~PdfRenderFlags.Transparent);
 }
 public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRenderFlags flags)
 {
     return(Document.Render(page, width, height, dpiX, dpiY, flags));
 }
 public Image Render(int page, float dpiX, float dpiY, PdfRenderFlags flags)
 {
     return(Document.Render(page, dpiX, dpiY, flags));
 }
 public void Render(int page, Graphics graphics, float dpiX, float dpiY, Rectangle bounds, PdfRenderFlags flags)
 {
     Document.Render(page, graphics, dpiX, dpiY, bounds, flags);
 }
Beispiel #16
0
        /// <summary>
        /// Renders a page of the PDF document to an image.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="width">Width of the rendered image.</param>
        /// <param name="height">Height of the rendered image.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        /// <returns>The rendered image.</returns>
        public Image Render(int page, System.Drawing.RectangleF pageBounds, System.Drawing.RectangleF clipRectangle, float dpiX, float dpiY, PdfRenderFlags flags)
        {
            RectangleF ir = RectangleF.Intersect(pageBounds, clipRectangle);

            double scale  = 1;
            int    width  = (int)(ir.Width / scale);  //pageBounds.Width;
            int    height = (int)(ir.Height / scale); //pageBounds.Height;

            if (width == 0 || height == 0)
            {
                return(null);
            }

            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if ((flags & PdfRenderFlags.CorrectFromDpi) != 0)
            {
                width  = width / 72 * (int)dpiX;
                height = height / 72 * (int)dpiY;
            }

            var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            //var bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            bitmap.SetResolution(dpiX, dpiY);

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

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

                try
                {
                    uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                    NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, width, height, background);

                    bool success = _file.RenderPDFPageToBitmap(
                        page,
                        handle,
                        (int)dpiX, (int)dpiY,
                        (int)(-(ir.X - pageBounds.X)), (int)(-(ir.Y - pageBounds.Y)), (int)(pageBounds.Width / scale), (int)(pageBounds.Height / scale),
                        //0, 0, width, height,
                        FlagsToFPDFFlags(flags)
                        );

                    if (!success)
                    {
                        throw new Win32Exception();
                    }
                }
                finally
                {
                    NativeMethods.FPDFBitmap_Destroy(handle);
                }
            }
            finally
            {
                bitmap.UnlockBits(data);
            }

            return(bitmap);
        }
Beispiel #17
0
        /// <summary>
        /// Renders a page of the PDF document to an image.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        /// <returns>The rendered image.</returns>
        public Image Render(int page, float dpiX, float dpiY, System.Drawing.RectangleF pageBounds, System.Drawing.RectangleF clipRectangle, PdfRenderFlags flags)
        {
            //var size = PageSizes[page];

            //return Render(page, (int)size.Width, (int)size.Height, dpiX, dpiY, flags);
            return(Render(page, pageBounds, clipRectangle, dpiX, dpiY, flags));
        }
Beispiel #18
0
 /// <summary>
 /// Renders the page.
 /// </summary>
 /// <param name="width">
 /// The full width of the rendered image in px or percentage (if dpiX and dpiY are specified).
 /// If 0, width will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="height">
 /// The full wiheightth of the rendered image in px or percentage (if dpiX and dpiY are specified).
 /// If 0, height will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="dpiX">DPI to render page. If set, width and height will accept percentage.</param>
 /// <param name="dpiY">DPI to render page. If set, width and height will accept percentage.</param>
 /// <param name="rotate">Specify rotation.</param>
 /// <param name="flags">Specify flags.</param>
 /// <returns>Image from the page.</returns>
 public Image Render(int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
 {
     return(Render(width, height, 0, 0, width, height, dpiX, dpiY, rotate, flags));
 }
Beispiel #19
0
 /// <summary>
 /// Renders the page.
 /// </summary>
 /// <param name="width">
 /// The full width of the rendered image in px.
 /// If 0, width will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="height">
 /// The full wiheightth of the rendered image in px.
 /// If 0, height will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="clipX">X value of the start point of the clipping area</param>
 /// <param name="clipY">Y value of the start point of the clipping area</param>
 /// <param name="clipWidth">Width of the clip area</param>
 /// <param name="clipHeight">Height of the clip area</param>
 /// <param name="rotate">Specify rotation.</param>
 /// <param name="flags">Specify flags.</param>
 /// <returns>Image from the page.</returns>
 public Image Render(int width, int height, int clipX, int clipY, int clipWidth, int clipHeight, PdfRotation rotate, PdfRenderFlags flags)
 {
     return(Render(width, height, clipX, clipY, clipWidth, clipHeight, 0, 0, rotate, flags));
 }
Beispiel #20
0
 /// <summary>
 /// Renders a page of the PDF document to an image.
 /// </summary>
 /// <param name="page">Number of the page to render.</param>
 /// <param name="width">Width of the rendered image.</param>
 /// <param name="height">Height of the rendered image.</param>
 /// <param name="dpiX">Horizontal DPI.</param>
 /// <param name="dpiY">Vertical DPI.</param>
 /// <param name="flags">Flags used to influence the rendering.</param>
 /// <returns>The rendered image.</returns>
 public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRenderFlags flags)
 {
     return(Render(page, width, height, dpiX, dpiY, 0, flags & ~PdfRenderFlags.Annotations, (flags & PdfRenderFlags.Annotations) != 0));
 }
 public void Render(int page, Graphics graphics, float dpiX, float dpiY, Rectangle bounds, PdfRenderFlags flags)
 {
     throw new NotImplementedException();
 }
Beispiel #22
0
        public RawRenderData Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if ((flags & PdfRenderFlags.CorrectFromDpi) != 0)
            {
                width  = width * (int)dpiX / 72;
                height = height * (int)dpiY / 72;
            }

            var byteArray = new byte[4 * width * height];

            var gcHandle = GCHandle.Alloc(byteArray, GCHandleType.Pinned);

            try
            {
                var handle = NativeMethods.FPDFBitmap_CreateEx(width, height, 4, gcHandle.AddrOfPinnedObject(), width * 4);

                try
                {
                    uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                    NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, width, height, background);

                    bool success = _file.RenderPDFPageToBitmap(
                        page,
                        handle,
                        0, 0, width, height,
                        (int)rotate,
                        _flagsToFPDFFlags(flags),
                        (flags & PdfRenderFlags.Annotations) != 0
                        );

                    if (!success)
                    {
                        throw new Win32Exception();
                    }
                }
                finally
                {
                    NativeMethods.FPDFBitmap_Destroy(handle);
                }
            }
            finally
            {
                gcHandle.Free();
            }

            return(new RawRenderData(byteArray, width, height));
        }
 public Image Render(int page, float dpiX, float dpiY, PdfRenderFlags flags)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
        /// <summary>
        /// Renders a page of the PDF document to the provided graphics instance.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="graphics">Graphics instance to render the page on.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="bounds">Bounds to render the page in.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        public void Render(int page, Graphics graphics, float dpiX, float dpiY, Rectangle bounds, PdfRenderFlags flags)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            float graphicsDpiX = graphics.DpiX;
            float graphicsDpiY = graphics.DpiY;

            var dc = graphics.GetHdc();

            try
            {
                if ((int)graphicsDpiX != (int)dpiX || (int)graphicsDpiY != (int)dpiY)
                {
                    var transform = new NativeMethods.XFORM
                    {
                        eM11 = graphicsDpiX / dpiX,
                        eM22 = graphicsDpiY / dpiY
                    };

                    NativeMethods.SetGraphicsMode(dc, NativeMethods.GM_ADVANCED);
                    NativeMethods.ModifyWorldTransform(dc, ref transform, NativeMethods.MWT_LEFTMULTIPLY);
                }

                var point = new NativeMethods.POINT();
                NativeMethods.SetViewportOrgEx(dc, bounds.X, bounds.Y, out point);

                bool success = _file.RenderPDFPageToDC(
                    page,
                    dc,
                    (int)dpiX, (int)dpiY,
                    0, 0, bounds.Width, bounds.Height,
                    FlagsToFPDFFlags(flags)
                    );

                NativeMethods.SetViewportOrgEx(dc, point.X, point.Y, out point);

                if (!success)
                {
                    throw new Win32Exception();
                }
            }
            finally
            {
                graphics.ReleaseHdc(dc);
            }
        }
 public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
 {
     throw new NotImplementedException();
 }
Beispiel #26
0
 private NativeMethods.FPDF FlagsToFPDFFlags(PdfRenderFlags flags)
 {
     return((NativeMethods.FPDF)(flags & ~PdfRenderFlags.Transparent));
 }
Beispiel #27
0
        /// <summary>
        /// Renders a page of the PDF document to the provided graphics instance.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="graphics">Graphics instance to render the page on.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="bounds">Bounds to render the page in.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        public void Render(int page, Graphics graphics, float dpiX, float dpiY, Rectangle bounds, PdfRenderFlags flags)
        {
            if (graphics == null)
                throw new ArgumentNullException("graphics");
            if (_disposed)
                throw new ObjectDisposedException(GetType().Name);

            float graphicsDpiX = graphics.DpiX;
            float graphicsDpiY = graphics.DpiY;

            var dc = graphics.GetHdc();

            try
            {
                if ((int)graphicsDpiX != (int)dpiX || (int)graphicsDpiY != (int)dpiY)
                {
                    var transform = new NativeMethods.XFORM
                    {
                        eM11 = graphicsDpiX / dpiX,
                        eM22 = graphicsDpiY / dpiY
                    };

                    NativeMethods.SetGraphicsMode(dc, NativeMethods.GM_ADVANCED);
                    NativeMethods.ModifyWorldTransform(dc, ref transform, NativeMethods.MWT_LEFTMULTIPLY);
                }

                var point = new NativeMethods.POINT();
                NativeMethods.SetViewportOrgEx(dc, bounds.X, bounds.Y, out point);

                bool success = _file.RenderPDFPageToDC(
                    page,
                    dc,
                    (int)dpiX, (int)dpiY,
                    0, 0, bounds.Width, bounds.Height,
                    FlagsToFPDFFlags(flags)
                );

                NativeMethods.SetViewportOrgEx(dc, point.X, point.Y, out point);

                if (!success)
                    throw new Win32Exception();
            }
            finally
            {
                graphics.ReleaseHdc(dc);
            }
        }
 public Image Render(int page, float dpiX, float dpiY, PdfRenderFlags flags)
 {
     return(_document.Render(TranslatePage(page), dpiX, dpiY, flags));
 }
Beispiel #29
0
        /// <summary>
        /// Renders a page of the PDF document to an image.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        /// <returns>The rendered image.</returns>
        public Image Render(int page, float dpiX, float dpiY, PdfRenderFlags flags)
        {
            var size = PageSizes[page];

            return Render(page, (int)size.Width, (int)size.Height, dpiX, dpiY, flags);
        }
 public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
 {
     return(_document.Render(page, width, height, dpiX, dpiY, rotate, flags));
 }
Beispiel #31
0
 /// <summary>
 /// Renders a page of the PDF document to an image.
 /// </summary>
 /// <param name="page">Number of the page to render.</param>
 /// <param name="width">Width of the rendered image.</param>
 /// <param name="height">Height of the rendered image.</param>
 /// <param name="dpiX">Horizontal DPI.</param>
 /// <param name="dpiY">Vertical DPI.</param>
 /// <param name="flags">Flags used to influence the rendering.</param>
 /// <param name="renderFormFill">Render form fills.</param>
 /// <returns>The rendered image.</returns>
 public SKBitmap Render(int page, int width, int height, float dpiX, float dpiY, PdfRenderFlags flags, bool renderFormFill)
 {
     return(Render(page, width, height, dpiX, dpiY, 0, flags, renderFormFill));
 }