Esempio n. 1
0
func pdf(w http.ResponseWriter, r *http.Request) *appError {
	w.Header().Set("Content-type", "application/pdf")

	// Initialize the graphic context on an pdf document
	dest := draw2dpdf.NewPdf("L", "mm", "A4")
	gc := draw2dpdf.NewGraphicContext(dest)

	// Draw sample
	android.Draw(gc, 65, 0)

	err := dest.Output(w)
	if err != nil {
		return &appError{err, fmt.Sprintf("Can't write: %s", err), 500}
	}
	return nil
}
Esempio n. 2
0
func imgPng(w http.ResponseWriter, r *http.Request) *appError {
	w.Header().Set("Content-type", "image/png")

	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
	gc := draw2dimg.NewGraphicContext(dest)

	// Draw sample
	android.Draw(gc, 65, 0)

	err := png.Encode(w, dest)
	if err != nil {
		return &appError{err, fmt.Sprintf("Can't encode: %s", err), 500}
	}

	return nil
}