Documentation ¶
Overview ¶
Package lazypdf provides a MuPDF-based document page rasterizer. It is managed via the Rasterizer struct.
Index ¶
- Constants
- Variables
- func IsBadPage(err error) bool
- func IsRasterTimeout(err error) bool
- type RasterImageReply
- type RasterReply
- type RasterRequest
- type RasterSVGReply
- type Rasterizer
- func (r *Rasterizer) GeneratePageImage(ctx context.Context, pageNumber int, width int, scale float64) (image.Image, error)
- func (r *Rasterizer) GeneratePageSVG(ctx context.Context, pageNumber int, width int, scale float64) ([]byte, error)
- func (r *Rasterizer) GetPageCount() int
- func (r *Rasterizer) Run() error
- func (r *Rasterizer) Stop()
- type ReplyWrapper
Constants ¶
const ( // We'll wait up to 10 seconds for a single page to Rasterize. RasterTimeout = 10 * time.Second LandscapeScale = 1.0 PortraitScale = 1.5 )
const ( RasterImage rasterType = iota RasterSVG )
Variables ¶
var ( // A page was requested with an out of bounds page number. ErrBadPage = errors.New("invalid page number") // We tried to rasterize the page, but we gave up waiting. ErrRasterTimeout = errors.New("rasterizer timed out!") )
Functions ¶
func IsRasterTimeout ¶
IsRasterTimeout validates that the type of error was an ErrRasterTimeout.
Types ¶
type RasterImageReply ¶
type RasterImageReply struct { RasterReply Image image.Image }
type RasterReply ¶
type RasterReply struct {
// contains filtered or unexported fields
}
func (*RasterReply) Error ¶
func (r *RasterReply) Error() error
type RasterRequest ¶
type RasterSVGReply ¶
type RasterSVGReply struct { RasterReply SVG []byte }
type Rasterizer ¶
type Rasterizer struct { Filename string RequestChan chan *RasterRequest Ctx *C.struct_fz_context_s Document *C.struct_fz_document_s Logger zerolog.Logger // contains filtered or unexported fields }
Rasterizer is an actor that runs on an event loop processing a request channel. Replies are asynchronous from the standpoint of the internals of the library but the exported interface (via GeneratePage) is synchronous, using channels.
If you need to use this asynchronously, you can directly insert entries into the RequestChan.
Lifecycle:
- The event loop is started up by calling the Run() function, which will allocate some resources and then start up a background Goroutine.
- You need to stop the event loop to remove the Goroutine and to free up any resources that have been allocated in the Run() function.
func NewRasterizer ¶
func NewRasterizer(filename string, rasterBufferSize int) *Rasterizer
NewRasterizer returns a configured Rasterizer for a given filename, which uses a buffered channel of rasterBufferSize to queue requests for the rasterizer.
func NewRasterizerWithLogger ¶
func NewRasterizerWithLogger(filename string, rasterBufferSize int, logger zerolog.Logger) *Rasterizer
NewRasterizerWithLogger same as NewRasterizer but this function also accepts a logger.
func (*Rasterizer) GeneratePageImage ¶
func (r *Rasterizer) GeneratePageImage(ctx context.Context, pageNumber int, width int, scale float64) (image.Image, error)
GeneratePageImage is a synchronous interface to the processing engine and will return a Go stdlib image.Image.
func (*Rasterizer) GeneratePageSVG ¶
func (r *Rasterizer) GeneratePageSVG(ctx context.Context, pageNumber int, width int, scale float64) ([]byte, error)
GeneratePageSVG is a synchronous interface to the processing engine and will return a Go byte array containing the SVG string.
func (*Rasterizer) GetPageCount ¶
func (r *Rasterizer) GetPageCount() int
GetPageCount returns the number of pages in the document
func (*Rasterizer) Run ¶
func (r *Rasterizer) Run() error
Run starts the main even loop after allocating some resources. This needs to be called before making any requests to rasterize pages.
func (*Rasterizer) Stop ¶
func (r *Rasterizer) Stop()
Stop shuts down the rasterizer and frees up some common data structures that were allocated in the Run() method.
type ReplyWrapper ¶
type ReplyWrapper interface {
Error() error
}