Example #1
0
        internal static async Task <PdfPage> Create(
            ThreadDispatcher dispatcher,
            FpdfDocumentT documentInstance,
            int pageIndex)
        {
            var loadPageResult = await dispatcher.QueueWithResult(() => fpdfview.FPDF_LoadPage(documentInstance, pageIndex));

            if (loadPageResult == null)
            {
                throw new Exception($"Failed to open page for page index {pageIndex}.");
            }

            var page = new PdfPage(dispatcher, documentInstance, loadPageResult)
            {
                InitialIndex = pageIndex
            };

            var getPageSizeResult = await dispatcher.QueueWithResult(() =>
            {
                var size = new FS_SIZEF_();

                var result = fpdfview.FPDF_GetPageSizeByIndexF(documentInstance, pageIndex, size);

                return(result == 0 ? null : size);
            });

            if (getPageSizeResult == null)
            {
                throw new Exception($"Could not retrieve page size for page index {pageIndex}.");
            }

            page.Size = new SizeF(getPageSizeResult.Width, getPageSizeResult.Height);

            return(page);
        }
Example #2
0
        public async Task <PdfBitmap> Render(
            float scale,
            Color?backgroundColor,
            RenderFlags flags                   = RenderFlags.RenderAnnotations,
            DispatcherPriority priority         = DispatcherPriority.Normal,
            CancellationToken cancellationToken = default)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException(nameof(PdfPage));
            }

            return(await _dispatcher.QueueWithResult(
                       new RenderPageAction(
                           _dispatcher,
                           _pageInstance,
                           scale,
                           new RectangleF(0, 0, Size.Width, Size.Height),
                           flags,
                           backgroundColor),
                       priority, cancellationToken));
        }