public Bitmap GetPage(Tile page, bool isPrinting)
        {
            var imgBuffer = new byte[page.Width * page.Height * 4];
            var imgHandle = GCHandle.Alloc(imgBuffer, GCHandleType.Pinned);

            try
            {
                var pagePtr = _nativeXps.Pages[page.PageNum];
                if (RenderLibrary.render_page(imgHandle.AddrOfPinnedObject(), pagePtr, (float)page.Scale, page.Width, page.Height) == 0)
                {
                    var bitmap = new Bitmap(page.Width, page.Height, 4 * page.Width,
                                            PixelFormat.Format32bppPArgb,
                                            Marshal.UnsafeAddrOfPinnedArrayElement(imgBuffer, 0));
                    return(bitmap);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
            finally
            {
                imgHandle.Free();
            }
        }
        public byte[] GetPageInBytes(Tile page, bool isPrinting)
        {
            var imgBuffer = new byte[page.Width * page.Height * 4];
            var imgHandle = GCHandle.Alloc(imgBuffer, GCHandleType.Pinned);

            try
            {
                var pagePtr = _nativeXps.Pages[page.PageNum];
                if (RenderLibrary.render_page(imgHandle.AddrOfPinnedObject(), pagePtr, (float)page.Scale, page.Width, page.Height) == 0)
                {
                    var bitmap = new Bitmap(page.Width, page.Height, 4 * page.Width,
                                            PixelFormat.Format32bppPArgb,
                                            Marshal.UnsafeAddrOfPinnedArrayElement(imgBuffer, 0));
                    using (bitmap)
                    {
                        using (var ms = new MemoryStream())
                        {
                            bitmap.Save(ms, ImageFormat.Png);
                            imgBuffer = ms.ToArray();
                        }
                        return(imgBuffer);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
            finally
            {
                imgHandle.Free();
            }
        }