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 pages

Rendering 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 quality

Text 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.
  • TiffDevice can 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

IssueCauseFix
Image is blurryResolution too lowIncrease DPI in the Resolution constructor
TIFF file too largeUncompressed or high-resolution settingsConfigure TiffSettings compression
Output stream is emptyProcess not called or page index wrongVerify 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 / MethodDescription
PngDeviceRender a page to PNG format
JpegDeviceRender a page to JPEG with quality control
TiffDeviceRender pages to multi-page TIFF
BmpDeviceRender a page to BMP format
ImageDeviceBase class for all image rendering devices
DocumentDeviceBase class for devices that process entire documents
TextDeviceExtract text via the device pipeline
ResolutionDPI specification for rendering
TiffSettingsTIFF output configuration (compression, color depth)

See Also

 English