Exemplo n.º 1
0
        /// <summary>
        /// Renders a page to a BitmapSource and returns the result.
        /// The result has a width equal to RenderWidth. The height is
        /// calculated automatically. The rendered page is 8-bit grayscale.
        /// </summary>
        /// <param name="page">The number of the page to render.</param>
        /// <returns>The rendered page</returns>
        /// <exception cref="Pdf2KTException">On errors.</exception>
        public BitmapSource RenderPage(int page)
        {
            if (page <= 0 || page > _mupdf.PageCount)
            {
                throw new Pdf2KTException("Page does not exist.");
            }

            _mupdf.Page = page;

            try
            {
                //TODO mupdf seems to render 1 pixel too large in width
                return(_mupdf.GetBitmapSource(RenderWidth - 1, 0, RenderDPI, RenderDPI, 0, RenderType.Grayscale, false, false, 10000000));
            }
            catch (Exception e)
            {
                throw new Pdf2KTException("Error while rendering the page.", e);
            }
        }