Ejemplo n.º 1
0
func compareReferencePDF(s *RendererSuite, name string, data map[string]interface{}) {
	gofpdf.SetDefaultCatalogSort(true)
	gofpdf.SetDefaultCreationDate(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
	envPath, err := utils.EnvironmentPath()

	if err != nil {
		s.T().Errorf(err.Error())
	}

	filepath := path.Join(envPath + "/renderer/templates/fixtures/" + name + ".pdf")
	file, err := ioutil.ReadFile(filepath)

	if err != nil {
		s.T().Errorf(err.Error())
	}

	template, _ := templates.LoadJsonTemplate(name, data)

	f := pdf.NewGoFpdf(template.Layout())
	renderer.Render(template, f.Document())

	buffer := bytes.NewBufferString("")

	err = gofpdf.CompareBytes(f.Bytes(buffer), file)

	if err != nil {
		s.T().Errorf(err.Error())
	}
}
Ejemplo n.º 2
0
func DocumentsShow(w http.ResponseWriter, r *http.Request) {
	tplName := templateName(r)
	log.Println("Loading " + tplName)

	data, inputErr := userInput(r)
	if inputErr != nil {
		log.Println(tplName + ": " + inputErr.Error())
		w.Write([]byte(inputErr.Error()))
		return
	}

	template, tplErr := templates.LoadJsonTemplate(tplName, data)
	if tplErr != nil {
		log.Println(tplName + ": " + tplErr.Error())
		w.Write([]byte(tplErr.Error()))
		return
	}

	log.Println("Parsing " + tplName)
	f := pdf.NewGoFpdf(template.Layout())
	renderer.Render(template, f.Document())

	log.Println("Displaying " + tplName)
	buffer := bytes.NewBufferString("")
	w.Write(f.Bytes(buffer))
}
Ejemplo n.º 3
0
func DemoShow(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{
		"demo_text":  map[string]interface{}{"text": "JELMER SNOECK"},
		"demo_image": map[string]interface{}{"url": "https://golang.org/doc/gopher/frontpage.png"},
	}

	template, _ := templates.LoadJsonTemplate("demo", data)

	f := pdf.NewGoFpdf(template.Layout())
	renderer.Render(template, f.Document())

	buffer := bytes.NewBufferString("")
	w.Write(f.Bytes(buffer))
}