Image inclusion
To include images in your document, a few steps are necessary:
imgfile, err := f.Doc.LoadImageFile("path/to/image.pdf")to load an image object
type Imagefile struct {
PageSizes map[int]map[string]map[string]float64
Format string
Filename string
Box string
NumberOfPages int
ScaleX float64
ScaleY float64
W int
H int
PageNumber int // The requested page number for PDF images (1-based)
}You can create an image node from this image object with
imgNode := f.Doc.CreateImageNodeFromImagefile(imgfile, 1, "/MediaBox")Optionally set the width and the height:
imgNode.Width = width
imgNode.Height = heightTo show only a part of the image, set its Crop to a region in the units of the image’s natural size, measured from its top left corner: pixels for a bitmap, points of the page box for a PDF page. The region fills the image’s box, and the image is clipped to the box:
type ImageCrop struct {
X, Y, Width, Height float64
}imgNode.Crop = &node.ImageCrop{X: 100, Y: 50, Width: 400, Height: 300}Once you have this image node, put it in a vlist node by calling
vl := node.Vpack(imgNode)and place it on the page with
p.OutputAt(0, bag.MustSP("297mm"), vl)