Accusoft.PdfXpress7.Net
Convert PDF to Image

To create an image-only PDF document:

  1. Create an empty document.
  2. Invoke CreatePage to add a blank page, sized to specific dimensions.
  3. Invoke AddImage to place the image onto the page as a PDF image stream. 

PDF Xpress™ does not offer viewing capabilities of images. ImagXpress® can be used in conjunction with PDF Xpress to provide image decompression, viewing, and format conversion.

To render a page of a PDF document to bitmap, dib, encapsulated postscript, or data, use the "RenderPage" methods (e.g., RenderPageToDib, RenderPageToEps, RenderPageToImageData, RenderPageToBitmap).

C# Example
Copy Code
            // This code demonstrates converting a single page PDF file to an image file
            Accusoft.PdfXpressSdk.PdfXpress pdfXpress1 = null;
            RenderOptions renderOpts = null;
            try
            {
                pdfXpress1 = new PdfXpress();
                pdfXpress1.Initialize();
                renderOpts = new RenderOptions();
                int index = pdfXpress1.Documents.Add("C:\\test.pdf");
                renderOpts.ProduceDibSection = false;
                int pageIndex = 0;
                imageXView.Image = ImageX.FromBitmap(imagXpress, pdfXpress1.Documents[index].RenderPageToBitmap(pageIndex, renderOpts));
            }
            catch (System.Exception)
            {
            }
            finally
            {
                if (null != pdfXpress1)
                {
                    pdfXpress1.Dispose();
                }
            }

  

C# Example
Copy Code
        // This code demonstrates rendering a PDF page to a bitmap
        public void RenderPageToCompatibleBitmap(Document document, Int32 pageIndex, SizeF resolutionInDpi, RectangleF selectionInInches)
        {
            Bitmap bitmap = null;
            try
            {
                // Create a render options object.
                RenderOptions options = new RenderOptions();
                options.ReduceToBitonal = false;
                options.ResolutionX = (double)resolutionInDpi.Width;
                options.ResolutionY = (double)resolutionInDpi.Height;
                // Express the selection area as userspace units
                const double UserspaceDpi = 72.0;
                options.SelectionX = UserspaceDpi * selectionInInches.Left;
                options.SelectionY = UserspaceDpi * selectionInInches.Bottom;
                options.SelectionWidth = UserspaceDpi * selectionInInches.Width;
                options.SelectionHeight = UserspaceDpi * selectionInInches.Height;
                // Render the selection area to a System.Drawing.Bitmap object instance
                bitmap = document.RenderPageToBitmap(pageIndex, options);
            }
            catch (PdfXpressLicensingException)
            {
                // PDF Xpress is not licensed for this feature       
            }
            catch (PdfXpressLibraryException)
            {
                // A problem was encountered
            }
            catch (PdfXpressException)
            {
                // A problem was encountered
            }
            finally
            {
                if (null != bitmap)
                {
                    bitmap.Dispose();// release Bitmap resources
                }
            }
        }
        public void RenderPageToCompatibleBitmap(Document document, Int32 pageIndex, SizeF resolutionInDpi)
        {
            // To render the entire page, choose a selection area where
            // all dimensions are zero
            RectangleF selectionInInches = new RectangleF(0.0f, 0.0f, 0.0f, 0.0f);
            this.RenderPageToCompatibleBitmap(document, pageIndex, resolutionInDpi, selectionInInches);
        }

 

C# Example
Copy Code
        // This code demonstrates rendering a PDF page to a DIBSection
        public void RenderPageToDibSection(Document document, Int32 pageIndex, SizeF resolutionInDpi, RectangleF selectionInInches)
        {
            IntPtr dibHandle = IntPtr.Zero;
            try
            {
                // Create a render options object
                RenderOptions options = new RenderOptions();
                options.ReduceToBitonal = false;
                options.ResolutionX = (double)resolutionInDpi.Width;
                options.ResolutionY = (double)resolutionInDpi.Height;
                options.ProduceDibSection = true;
                // Express the selection area as userspace units
                const double UserspaceDpi = 72.0;
                options.SelectionX = UserspaceDpi * selectionInInches.Left;
                options.SelectionY = UserspaceDpi * selectionInInches.Bottom;
                options.SelectionWidth = UserspaceDpi * selectionInInches.Width;
                options.SelectionHeight = UserspaceDpi * selectionInInches.Height;
                // Render the selection area to a DIBSection
                // Note: The caller is responsible for releasing the DIB handle using the DeleteObject
                // Windows function call.
                dibHandle = new IntPtr(document.RenderPageToDib(pageIndex, options));
            }
            catch (PdfXpressLicensingException)
            {
                //PDF Xpress is not licensed for this feature
            }
            catch (PdfXpressLibraryException)
            {
                //A problem was encountered
            }
            catch (PdfXpressException)
            {
                //A problem was encountered
            }
            finally
            {
                DeleteObject(dibHandle);//release GDI resources.
            }
        }
        public void RenderPageToDibSection(Document document, Int32 pageIndex, SizeF resolutionInDpi)
        {
            // To render the entire page, choose a selection area where
            // all dimensions are zero
            RectangleF selectionInInches = new RectangleF(0.0f, 0.0f, 0.0f, 0.0f);
            this.RenderPageToDibSection(document, pageIndex, resolutionInDpi, selectionInInches);
        }

 

C# Example
Copy Code
        // This code demonstrates rendering a PDF page to a Global Packed bitmap
        public void RenderPageToGlobalPackedBitmap(Document document, Int32 pageIndex, SizeF resolutionInDpi, RectangleF selectionInInches)
        {
            IntPtr globalMemoryHandle = IntPtr.Zero;
            try
            {
                // Create a render options object
                RenderOptions options = new RenderOptions();
                options.ReduceToBitonal = false;
                options.ResolutionX = (double)resolutionInDpi.Width;
                options.ResolutionY = (double)resolutionInDpi.Height;
                options.ProduceDibSection = false;
                // Express the selection area as userspace units
                const double UserspaceDpi = 72.0;
                options.SelectionX = UserspaceDpi * selectionInInches.Left;
                options.SelectionY = UserspaceDpi * selectionInInches.Bottom;
                options.SelectionWidth = UserspaceDpi * selectionInInches.Width;
                options.SelectionHeight = UserspaceDpi * selectionInInches.Height;
                // Render the selection area to a global memory buffer
                // containing a packed bitmap.
                // Note: The caller is responsible for releasing the global memory handle
                // using the GlobalFree Windows function call
                globalMemoryHandle = new IntPtr(document.RenderPageToDib(pageIndex, options));
            }
            catch (PdfXpressLicensingException)
            {
                //PDF Xpress is not licensed for this feature.
            }
            catch (PdfXpressLibraryException)
            {
                //A problem was encountered
            }
            catch (PdfXpressException)
            {
                // A problem was encountered
            }
            finally
            {
                GlobalFree(globalMemoryHandle);//release handle.
            }
        }
        public void RenderPageToGlobalPackedBitmap(Document document, Int32 pageIndex, SizeF resolutionInDpi)
        {
            // To render the entire page, choose a selection area where
            // all dimensions are zero
            RectangleF selectionInInches = new RectangleF(0.0f, 0.0f, 0.0f, 0.0f);
            this.RenderPageToGlobalPackedBitmap(document, pageIndex, resolutionInDpi, selectionInInches);
        }

 

C# Example
Copy Code
        // This code demonstrates rendering a PDF page to Local memory
        public void RenderPageToRaw(Document document, Int32 pageIndex, SizeF resolutionInDpi, RectangleF selectionInInches)
        {
            try
            {
                // Create a render options object.
                RenderOptions options = new RenderOptions();
                options.ReduceToBitonal = false;
                options.ResolutionX = (double)resolutionInDpi.Width;
                options.ResolutionY = (double)resolutionInDpi.Height;
                options.ProduceDibSection = true;
                // Express the selection area as userspace units.
                const double UserspaceDpi = 72.0;
                options.SelectionX = UserspaceDpi * selectionInInches.Left;
                options.SelectionY = UserspaceDpi * selectionInInches.Bottom;
                options.SelectionWidth = UserspaceDpi * selectionInInches.Width;
                options.SelectionHeight = UserspaceDpi * selectionInInches.Height;
                // Render the selection area to local memory
                ImageDataInfo imageData = document.RenderPageToImageData(pageIndex, options);
            }
            catch (PdfXpressLicensingException)
            {
                //PDF Xpress is not licensed for this feature.
            }
            catch (PdfXpressLibraryException)
            {
                //A problem was encountered
            }
            catch (PdfXpressException)
            {
                //A problem was encountered
            }
            finally
            {
            }
        }
        public void RenderPageToRaw(Document document, Int32 pageIndex, SizeF resolutionInDpi)
        {
            // To render the entire page, choose a selection area where
            // all dimensions are zero.
            RectangleF selectionInInches = new RectangleF(0.0f, 0.0f, 0.0f, 0.0f);
            this.RenderPageToRaw(document, pageIndex, resolutionInDpi, selectionInInches);
        }

 

C# Example
Copy Code
        // This code demonstrates rendering a PDF page to EPS
        public void RenderPageToEps(Document document, Int32 pageIndex)
        {
            try
            {
                // Create a render options object
                RenderEpsOptions options = new RenderEpsOptions();
                options.RenderAnnotations = true;
                // Render the page to a DIBSection
                // Note: The caller is responsible for releasing the DIB handle using the DeleteObject
                // Windows function call.
                byte[] epsByteArray = document.RenderPageToEps(pageIndex, options);
            }
            catch (PdfXpressLicensingException)
            {
                //PDF Xpress is not licensed for this feature.
            }
            catch (PdfXpressLibraryException)
            {
                //A problem was encountered
            }
            catch (PdfXpressException)
            {
                //A problem was encountered
            }
            finally
            {
            }
        }

 

See Also

 

 


©2018. Accusoft Corporation. All Rights Reserved.

Send Feedback