To create an image-only PDF document:
- Create an empty document.
- Invoke CreatePage to add a blank page, sized to specific dimensions.
- Invoke AddImage to place the image onto the page as a PDF image stream.
PDF Xpress™ does not offer native compression or decompression of image streams used to populate PDF pages. ImagXpress® can be used in conjunction with PDF Xpress to provide image compression, decompression, 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).
When rendering an image at a high resolution, a "Creation of rasterizer port failed" exception may occur. If this exception occurs, lower the resolution and attempt to render the page again. |
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( pdfXpress1.Documents [index].RenderPageToBitmap pageIndex, renderOpts)); } catch (System.Exception ex) { } finally { if ( null != renderOpts) renderOpts.Dispose( ); 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 { } } |