Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. var input = `Молоко и творог`
  2. var output = "test.pdf"
  3.  
  4. func main() {
  5. pf := mdtopdf.NewPdfRenderer("", "", output, "trace.log")
  6.  
  7. // if I want to stylize a simple paragraph then isn't `pf.Normal` intended for it?
  8. // What does it affect then?
  9.  
  10. pf.Normal = mdtopdf.Styler{Font: "Arial", Style: "", Size: 5, Spacing: 2,
  11. TextColor: mdtopdf.Color{Red: 0, Green: 0, Blue: 0}}
  12.  
  13. err := pf.ProcessString(input)
  14. if err != nil {
  15. log.Fatalf("pdf.OutputFileAndClose() error:%v", err)
  16. }
  17. }
  18.  
  19. // ProcessString takes the markdown content, parses it to generate the PDF
  20. func (r *PdfRenderer) ProcessString(content string) error {
  21. var f *os.File
  22. var err error
  23. if r.tracerFile != "" {
  24. f, err = os.Create(r.tracerFile)
  25. if err != nil {
  26. return fmt.Errorf("os.Create() on tracefile error:%v", err)
  27. }
  28. defer f.Close()
  29. r.w = bufio.NewWriter(f)
  30. defer r.w.Flush()
  31. }
  32.  
  33. content = strings.Replace(content, "\r\n", "\n", -1)
  34. _ = bf.Run([]byte(content), bf.WithRenderer(r))
  35.  
  36. err = r.Pdf.OutputFileAndClose(r.pdfFile)
  37. if err != nil {
  38. return fmt.Errorf("Pdf.OutputFileAndClose() error on %v:%v", r.pdfFile, err)
  39. }
  40. return nil
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement