public RasterImage GetPageImage(
RasterCodecs codecs,
int pageNumber
)
public RasterImage getPageImage(
RasterCodecs codecs,
int pageNumber
);
public:
RasterImage^ GetPageImage(
RasterCodecs^ codecs,
int pageNumber
)
def GetPageImage(self,codecs,pageNumber):
codecs
An optional Leadtools.Codecs.RasterCodecs to use when reading the page. If you pass a null reference, then this method will internal create a new Leadtools.Codecs.RasterCodecs object and dispose before it returns.
pageNumber
The 1-based page number to read. Must be greater than or equal to 1 and less than or equal to the total number of pages in the document (Pages.Count). Use the special value of -1 to represent the last page in the document.
A Leadtools.RasterImage that represents the rendering of the requested page.
This method does not perform anything beyond 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 resulting 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 (where each unit is 1/72 of an inch) and the resolution value is 300, then the resulting 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 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 and GetPageSvg(RasterCodecs,Int32,CodecsLoadSvgOptions) to get an SVG representation of the page.
This example will convert a multipage PDF to a multipage TIF file
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls;
using Leadtools.Pdf;
using Leadtools.Svg;
using Leadtools.WinForms;
public void PDFDocumentGetPageImageExample()
{
string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.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:\LEADTOOLS23\Resources\Images";
}
import java.io.BufferedWriter;
import java.io.Console;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.Buffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import javax.xml.validation.Schema;
import org.apache.lucene.store.Directory;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.barcode.*;
import leadtools.codecs.*;
import leadtools.pdf.*;
import leadtools.svg.*;
public void pdfDocumentGetPageImageExample() {
String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images";
String pdfFileName = combine(LEAD_VARS_ImagesDir, "Leadtools.pdf");
String tifFileName = combine(LEAD_VARS_ImagesDir, "LEAD_pdf.tif");
File file = new File("LEAD_pdf.tif");
if (file.exists()) {
// So we won't append to it twice
file.delete();
}
// Open the document
PDFDocument document = new PDFDocument(pdfFileName);
// Set the resolution to 200 dots/inch
document.setResolution(200);
RasterCodecs codecs = new RasterCodecs();
// For each page...
for (int i = 1; i <= document.getPages().size(); i++) {
// Get the page as a raster image
RasterImage image = document.getPageImage(codecs, i);
// Save it to the destination file
codecs.save(image, tifFileName, RasterImageFormat.TIF_JPEG, 24, 1, 1, -1, CodecsSavePageMode.APPEND);
}
assertTrue(new File(tifFileName).exists());
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document