Ejemplo n.º 1
-1
// This examples tests corner cases as reported by the gocov tool.
func ExampleFpdf_SetKeywords() {
	var err error
	fileStr := exampleFilename("Fpdf_SetKeywords")
	err = gofpdf.MakeFont(fontFile("CalligrapherRegular.pfb"),
		fontFile("cp1252.map"), cnFontDir, nil, true)
	if err == nil {
		err = gofpdf.MakeFont(fontFile("calligra.ttf"),
			fontFile("cp1252.map"), cnFontDir, nil, true)
		if err == nil {
			pdf := gofpdf.New("", "", "", "")
			pdf.SetFontLocation(cnFontDir)
			pdf.SetTitle("世界", true)
			pdf.SetAuthor("世界", true)
			pdf.SetSubject("世界", true)
			pdf.SetCreator("世界", true)
			pdf.SetKeywords("世界", true)
			pdf.AddFont("Calligrapher", "", "CalligrapherRegular.json")
			pdf.AddPage()
			pdf.SetFont("Calligrapher", "", 16)
			pdf.Writef(5, "\x95 %s \x95", pdf)
			err = pdf.OutputFileAndClose(fileStr)
		}
	}
	summary(err, fileStr)
	// Output:
	// Successfully generated pdf/Fpdf_SetKeywords.pdf
}
Ejemplo n.º 2
-1
func main() {
	var dstDirStr, encodingFileStr string
	var err error
	var help, embed bool
	flag.StringVar(&dstDirStr, "dst", ".", "directory for output files (*.z, *.json)")
	flag.StringVar(&encodingFileStr, "enc", "cp1252.map", "code page file")
	flag.BoolVar(&embed, "embed", false, "embed font into PDF")
	flag.BoolVar(&help, "help", false, "command line usage")
	flag.Parse()
	if help {
		showHelp()
	} else {
		args := flag.Args()
		if len(args) > 0 {
			for _, fileStr := range args {
				err = gofpdf.MakeFont(fileStr, encodingFileStr, dstDirStr, os.Stderr, embed)
				if err != nil {
					errPrintf("%s\n", err)
				}
				// errPrintf("Font file [%s], Encoding file [%s], Embed [%v]\n", fileStr, encodingFileStr, embed)
			}
		} else {
			errPrintf("At least one Type1 or TrueType font must be specified\n")
			showHelp()
		}
	}
}
Ejemplo n.º 3
-1
// CompileFont takes a font file in Report.FontSourcePath and converts it into
// .json format if it doesn't exist in Report.FontCompiledPath.
func (r *Report) CompileFont(filename, encoding string) (string, error) {
	fontFilename := path.Join(r.FontSourcePath, filename)
	// replacing ext with json
	extLen := len(path.Ext(filename))
	compiledFilename := filename[:len(filename)-extLen] + ".json"
	encodingFilename, err := r.CompileEncoding(encoding)
	if err != nil {
		return compiledFilename, err
	}
	err = gofpdf.MakeFont(fontFilename, encodingFilename, r.FontCompiledPath, nil, true)
	return compiledFilename, err
}
Ejemplo n.º 4
-1
// Test the corner cases as reported by the gocov tool
func ExampleFpdf_tutorial10() {
	gofpdf.MakeFont(fontFile("calligra.ttf"), fontFile("cp1252.map"), cnFontDir, nil, true)
	pdf := gofpdf.New("", "", "", "")
	pdf.SetFontLocation(cnFontDir)
	pdf.SetTitle("世界", true)
	pdf.SetAuthor("世界", true)
	pdf.SetSubject("世界", true)
	pdf.SetCreator("世界", true)
	pdf.SetKeywords("世界", true)
	pdf.AddFont("Calligrapher", "", "calligra.json")
	pdf.AddPage()
	pdf.SetFont("Calligrapher", "", 16)
	pdf.Writef(5, "\x95 %s \x95", pdf)
	pdf.OutputAndClose(docWriter(pdf, 10))
	// Output:
	// Successfully generated pdf/tutorial10.pdf
}