PDF Xpress for .NET - User Guide > How To > View PDF |
ImagXpress® can be used in conjunction with PDF Xpress™ to display PDF pages. Assign bitmaps rendered using PDF Xpress to an ImagXpress ImageXView object to leverage its image-viewing features.
To view a PDF document page:
C# Example |
Copy Code
|
---|---|
using System; using System.Windows.Forms; namespace PdfViewerApplication { public partial class PdfViewerForm : Form { public PdfViewerForm() { InitializeComponent(); } Accusoft.ImagXpressSdk.ImagXpress imagXpressInstance = null; Accusoft.ImagXpressSdk.ImageXView imageXViewInstance = null; private void RenderImageButton_Click(object sender, EventArgs e) { // This code demonstrates rendering a single page PDF file using the ImageXView control Accusoft.PdfXpressSdk.PdfXpress pdfXpressInstance = null; Accusoft.PdfXpressSdk.RenderOptions options = null; Accusoft.PdfXpressSdk.Document documentOpened = null; try { imagXpressInstance = new Accusoft.ImagXpressSdk.ImagXpress(); pdfXpressInstance = new Accusoft.PdfXpressSdk.PdfXpress(); pdfXpressInstance.Initialize(); imageXViewInstance = new Accusoft.ImagXpressSdk.ImageXView(imagXpressInstance); imageXViewInstance.AutoResize = Accusoft.ImagXpressSdk.AutoResizeType.BestFit; imageXViewInstance.Location = new System.Drawing.Point(3, 16); imageXViewInstance.Size = new System.Drawing.Size(652, 481); imageXViewInstance.TabIndex = 1; this.Controls.Add(imageXViewInstance); //render at 200DPI options = new Accusoft.PdfXpressSdk.RenderOptions(); options.ResolutionX = 200; options.ResolutionY = 200; documentOpened = new Accusoft.PdfXpressSdk.Document(pdfXpressInstance, "C:\\test.pdf"); //render first page int pageNumber = 0; imageXViewInstance.Image = Accusoft.ImagXpressSdk.ImageX.FromBitmap(imagXpressInstance, documentOpened.RenderPageToBitmap(pageNumber, options)); } finally { if (null != documentOpened) { documentOpened.Dispose(); documentOpened = null; } if (null != pdfXpressInstance) { pdfXpressInstance.Dispose(); pdfXpressInstance = null; } } } } } |
The following code should be called in PdfViewerApplication.PdfViewerForm.Dispose(bool disposing):
C# Example |
Copy Code
|
---|---|
if (imageXViewInstance != null) { if (imageXViewInstance.Image != null) { imageXViewInstance.Image.Dispose(); imageXViewInstance.Image = null; } imageXViewInstance.Dispose(); imageXViewInstance = null; } if (imagXpressInstance != null) { imagXpressInstance.Dispose(); imagXpressInstance = null; } |