Leadtools.Pdf Namespace > PDFDocument Class : GetPageImage Method |
public RasterImage GetPageImage( RasterCodecs codecs, int pageNumber )
'Declaration Public Function GetPageImage( _ ByVal codecs As RasterCodecs, _ ByVal pageNumber As Integer _ ) As RasterImage
'Usage Dim instance As PDFDocument Dim codecs As RasterCodecs Dim pageNumber As Integer Dim value As RasterImage value = instance.GetPageImage(codecs, pageNumber)
public RasterImage GetPageImage( RasterCodecs codecs, int pageNumber )
function Leadtools.Pdf.PDFDocument.GetPageImage( codecs , pageNumber )
public: RasterImage^ GetPageImage( RasterCodecs^ codecs, int pageNumber )
This method does not perform anything beyound simply using the Leadtools.Codecs.RasterCodecs object passed (or the temporary one created) to load the PDF page:
rasterCodecsObject.Load(document.FileName, 0, CodecsLoadByteOrder.Bgr, pageNumber, pageNumber)
For more information, refer to RasterCodecs.Load.
The size of the result Leadtools.RasterImage depends on the size of the page (PDFDocumentPage.Width and PDFDocumentPage.Height) and the current resolution value of the document PDFDocument.Resolution). For example, if the PDF size is 612 by 792 PDF units (or 1/72 of an inch) and resolution value is 300, then the result image size is: 300 * 612/72 by 300 * 792/72 = 2550 by 3300 pixels. You can increase or decrease the value of the resolution to load the image at larger or smaller pixel size. Refer to PDF Coordinate System for more information.
Once the page is rendered as a Leadtools.RasterImage object, you can use this object to perform any other image functionality with LEADTOOLS, such as setting it into a viewer control, image processing, saving to other formats, etc.
Since a Leadtools.Codecs.RasterCodecs object is required by this method, you can either pass one through the codecs parameter and the method will use this object to load the page. This is helpful if you need to change the default Leadtools.Codecs.RasterCodecs load options or subscribe to any of the events that will occur during loading. If none of that is required, you can simply pass null (Nothing in Visual Basic) for the codecs parameter and this method will internally create, use and dispose a temporary Leadtools.Codecs.RasterCodecs object.
To get a thumbnail of any page in a PDF document, use GetThumbnail.
Public Sub PDFDocumentGetPageImageExample() Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "LEAD.pdf") Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "LEAD_pdf.tif") If File.Exists(tifFileName) Then ' So we won't append to it twice File.Delete(tifFileName) End If ' Open the document Using document As New PDFDocument(pdfFileName) ' Set the resolution to 200 dots/inch document.Resolution = 200 Using codecs As New RasterCodecs() ' For each page... For i As Integer = 1 To document.Pages.Count ' Get the page as a raster image Using image As RasterImage = document.GetPageImage(codecs, i) ' Save it to the destination file codecs.Save(image, tifFileName, RasterImageFormat.TifJpeg, 24, 1, 1, -1, CodecsSavePageMode.Append) End Using Next End Using End Using End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void PDFDocumentGetPageImageExample() { string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD.pdf"); string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD_pdf.tif"); if(File.Exists(tifFileName)) { // So we won't append to it twice File.Delete(tifFileName); } // Open the document using(PDFDocument document = new PDFDocument(pdfFileName)) { // Set the resolution to 200 dots/inch document.Resolution = 200; using(RasterCodecs codecs = new RasterCodecs()) { // For each page... for(int i = 1; i <= document.Pages.Count; i++) { // Get the page as a raster image using(RasterImage image = document.GetPageImage(codecs, i)) { // Save it to the destination file codecs.Save(image, tifFileName, RasterImageFormat.TifJpeg, 24, 1, 1, -1, CodecsSavePageMode.Append); } } } } } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2