github.com/phpdave11/gofpdf@v1.4.2/makefont/makefont.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "github.com/phpdave11/gofpdf" 7 "os" 8 ) 9 10 func errPrintf(fmtStr string, args ...interface{}) { 11 fmt.Fprintf(os.Stderr, fmtStr, args...) 12 } 13 14 func showHelp() { 15 errPrintf("Usage: %s [options] font_file [font_file...]\n", os.Args[0]) 16 flag.PrintDefaults() 17 fmt.Fprintln(os.Stderr, "\n"+ 18 "font_file is the name of the TrueType file (extension .ttf), OpenType file\n"+ 19 "(extension .otf) or binary Type1 file (extension .pfb) from which to\n"+ 20 "generate a definition file. If an OpenType file is specified, it must be one\n"+ 21 "that is based on TrueType outlines, not PostScript outlines; this cannot be\n"+ 22 "determined from the file extension alone. If a Type1 file is specified, a\n"+ 23 "metric file with the same pathname except with the extension .afm must be\n"+ 24 "present.") 25 errPrintf("\nExample: %s --embed --enc=../font/cp1252.map --dst=../font calligra.ttf /opt/font/symbol.pfb\n", os.Args[0]) 26 } 27 28 func tutorialSummary(f *gofpdf.Fpdf, fileStr string) { 29 if f.Ok() { 30 fl, err := os.Create(fileStr) 31 defer fl.Close() 32 if err == nil { 33 f.Output(fl) 34 } else { 35 f.SetError(err) 36 } 37 } 38 if f.Ok() { 39 fmt.Printf("Successfully generated %s\n", fileStr) 40 } else { 41 errPrintf("%s\n", f.Error()) 42 } 43 } 44 45 func main() { 46 var dstDirStr, encodingFileStr string 47 var err error 48 var help, embed bool 49 flag.StringVar(&dstDirStr, "dst", ".", "directory for output files (*.z, *.json)") 50 flag.StringVar(&encodingFileStr, "enc", "cp1252.map", "code page file") 51 flag.BoolVar(&embed, "embed", false, "embed font into PDF") 52 flag.BoolVar(&help, "help", false, "command line usage") 53 flag.Parse() 54 if help { 55 showHelp() 56 } else { 57 args := flag.Args() 58 if len(args) > 0 { 59 for _, fileStr := range args { 60 err = gofpdf.MakeFont(fileStr, encodingFileStr, dstDirStr, os.Stderr, embed) 61 if err != nil { 62 errPrintf("%s\n", err) 63 } 64 // errPrintf("Font file [%s], Encoding file [%s], Embed [%v]\n", fileStr, encodingFileStr, embed) 65 } 66 } else { 67 errPrintf("At least one Type1 or TrueType font must be specified\n") 68 showHelp() 69 } 70 } 71 }