Devices and Rendering
Devices and Rendering
Aspose.PDF FOSS for .NET provides device classes that render PDF pages to raster images. Each device targets a specific format — TIFF, JPEG, PNG, or BMP — and accepts resolution and quality parameters.
Rendering to PNG
PngDevice converts a PDF page to a PNG image.
using var doc = Document.Open(pdfBytes);
var device = new PngDevice(new Resolution(300));
using var stream = File.Create("page1.png");
device.Process(doc.Pages[1], stream);Rendering to JPEG
JpegDevice converts a page to JPEG with configurable quality.
var device = new JpegDevice(new Resolution(150), 90); // 90% quality
using var stream = File.Create("page1.jpg");
device.Process(doc.Pages[1], stream);Rendering to TIFF
TiffDevice converts one or more pages to a multi-page TIFF image.
TiffSettings controls compression, color depth, and shape.
var settings = new TiffSettings();
var device = new TiffDevice(new Resolution(200), settings);
using var stream = File.Create("document.tiff");
device.Process(doc, stream); // All pagesRendering to BMP
BmpDevice converts a page to an uncompressed bitmap.
var device = new BmpDevice(new Resolution(300));
using var stream = File.Create("page1.bmp");
device.Process(doc.Pages[1], stream);Resolution control
All devices accept a Resolution object specifying DPI.
var lowRes = new Resolution(72); // Screen quality
var midRes = new Resolution(150); // Print draft
var hiRes = new Resolution(300); // Print qualityText extraction via TextDevice
TextDevice extracts text from a page using the device processing pipeline.
var device = new TextDevice();
using var stream = new MemoryStream();
device.Process(doc.Pages[1], stream);
string text = System.Text.Encoding.UTF8.GetString(stream.ToArray());Tips and Best Practices
- Use 300 DPI for print-quality output and 72-150 DPI for screen/web use.
TiffDevicecan process the entire document in one call; other devices process one page at a time.- JPEG quality values range from 0-100; 85-90 provides a good balance of quality and file size.
- For batch conversion, iterate pages and process each with the appropriate device.
- Dispose streams after processing to release file handles.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| Image is blurry | Resolution too low | Increase DPI in the Resolution constructor |
| TIFF file too large | Uncompressed or high-resolution settings | Configure TiffSettings compression |
| Output stream is empty | Process not called or page index wrong | Verify page exists and Process completes |
FAQ
Can I render a specific page range to TIFF?
Yes. TiffDevice.Process has overloads accepting start and end page numbers.
What compression types does TiffSettings support?
LZW, CCITT3, CCITT4, RLE, None, and other standard TIFF compression types.
Can I control the output image dimensions?
Yes. Device constructors accept width and height parameters in addition to or instead of resolution.
API Reference Summary
| Class / Method | Description |
|---|---|
PngDevice | Render a page to PNG format |
JpegDevice | Render a page to JPEG with quality control |
TiffDevice | Render pages to multi-page TIFF |
BmpDevice | Render a page to BMP format |
ImageDevice | Base class for all image rendering devices |
DocumentDevice | Base class for devices that process entire documents |
TextDevice | Extract text via the device pipeline |
Resolution | DPI specification for rendering |
TiffSettings | TIFF output configuration (compression, color depth) |