pdfToImage

Rasterises a 1-based page of a PDF into an ordinary image object, so the whole image* family (resize, crop, watermark, write in any format) applies to the result. width wins if given; otherwise dpi is used (PDF's native resolution is 72dpi, so dpi/72 is the scale); otherwise 1:1. The output canvas is capped at 40 megapixels regardless of what the page declares — if exceeded, the scale is reduced to fit rather than the call failing.

pdfToImage(pdfObj [, page [, width [, dpi]]]) → returns any

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

pdfObj any
Required

A PDF object from pdfRead() or pdf().

page numeric
Default: 1

1-based page number to render.

width numeric

Target width of the rendered image in pixels. Wins over dpi when given.

dpi numeric

Target resolution in DPI. Used when width is not given (scale = dpi / 72).

Examples
Sample code invoking the pdfToImage function

Rasterise the first page and write it to disk.

doc = PdfRead( expandPath( "/invoice.pdf" ) );
img = PdfToImage( doc, 1, 400 );
imageWrite( img, expandPath( "/thumb.png" ) );

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub