Conversion
Converting a PDF to images means rendering it, and that lives in the render
package. ImageDevice interprets a page’s content stream and paints it into a Go
image.Image:
device := render.NewImageDevice()
device.OutputWidth = 1600
img, err := device.Render(page)Rendering is per page, so you drive the loop and the reader yourself. The device is stateless with respect to the document apart from its font and glyph caches, which is why one device should be reused across the pages of a document and not shared between goroutines.
Two things are worth separating in your head. The image device decides how the
page becomes pixels and what format is written out. Stream encoders decide whether
the images inside the page can be decoded at all, and that is where a custom
encoder comes in: UniPDF has no JPEG2000 decoder, so pages carrying JPXDecode
images need one registered before they will render.
Where to look
| Guide | Covers |
|---|---|
| PDF to image | Rendering pages to PNG or JPEG, output size, annotations, unsupported features. |
| PDF to image custom encoding | Registering a stream encoder so JPEG2000 images decode. |
Going the other way, building a PDF from images or other content, is the
creator package rather than render.