Пример #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
}
Пример #2
0
func test(t *testing.T, draw sample) {
	// Initialize the graphic context on an pdf document
	dest := draw2dpdf.NewPdf("L", "mm", "A4")
	gc := draw2dpdf.NewGraphicContext(dest)
	// Draw sample
	output, err := draw(gc, "pdf")
	if err != nil {
		t.Errorf("Drawing %q failed: %v", output, err)
		return
	}
	/*
		// Save to pdf only if it doesn't exist because of git
		if _, err = os.Stat(output); err == nil {
			t.Skipf("Saving %q skipped, as it exists already. (Git would consider it modified.)", output)
			return
		}
	*/
	err = draw2dpdf.SaveToPdfFile(output, dest)
	if err != nil {
		t.Errorf("Saving %q failed: %v", output, err)
	}
}