Help us shape the future of Go! Take the 2026 Go Developer Survey

pdfrender

package module
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

README

go-tex/pdfrender

ci Go Reference

Pure-Go (CGO=0) rasteriser for PDF figures, shaped to plug into go-tex/engine's RasterizePDF seam so \includegraphics of a vector .pdf typesets as a real raster instead of a placeholder. A thin wrapper over go-pdfkit/render.

Why a separate module

A pure-Go PDF renderer is a heavy dependency. The engine core — and its browser/wasm build — stay free of it: the engine exposes a func seam, and a consumer that wants PDF figures (the CLI, loom) opts in with one line.

Use

import (
	"github.com/go-tex/engine"
	"github.com/go-tex/pdfrender"
)

func init() { engine.RasterizePDF = pdfrender.Rasterize } // \includegraphics{fig.pdf} now renders

Or rasterise directly:

img, err := pdfrender.Rasterize(pdfBytes, 200) // first page at 200 DPI → image.Image
img, err  = pdfrender.RasterizePage(pdfBytes, 2, 300)

License

BSD-3-Clause — see LICENSE. Copyright the go-tex/pdfrender authors.

Documentation

Overview

Package pdfrender rasterises a PDF page to an image in pure Go (CGO=0). It is a thin wrapper over github.com/go-pdfkit/render, shaped to plug straight into go-tex/engine's RasterizePDF seam:

engine.RasterizePDF = pdfrender.Rasterize

so \includegraphics of a vector .pdf figure typesets as a real raster. The engine core stays free of this (heavy) renderer; a consumer that wants PDF figures — the CLI, loom — opts in with the line above, while the browser/wasm build leaves the seam nil and shows a placeholder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NumPages added in v0.2.0

func NumPages(pdf []byte) int

NumPages reports how many pages a PDF document holds, or 0 when it cannot be opened. go-tex/engine's \includepdf needs it to resolve pdfpages' ranges — pages={2-5} and pages=- name a count the document alone knows — and counting "/Type /Page" in the bytes does not work on a PDF whose page tree lives in an object stream, which most modern writers produce.

func Rasterize

func Rasterize(pdf []byte, dpi float64) (image.Image, error)

Rasterize renders the first page of a PDF document to an image at the given DPI. It matches the signature of go-tex/engine's RasterizePDF hook.

func RasterizePage

func RasterizePage(pdf []byte, page int, dpi float64) (image.Image, error)

RasterizePage renders a specific 1-based page of a PDF document at the given DPI.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL