Skip to content

Acke0/mdtopdf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mdtopdf

Converts Markdown to PDF

	md, err := os.Open("example.md")
	if err != nil{
		fmt.Println(err)
		return
	}
	defer md.Close()

	pdf, err := os.Create("example.pdf")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer pdf.Close()

	pageNumExtension := func(pdf *gofpdf.Fpdf) {
        pdf.SetFooterFunc(func() {
            left, _, right, bottom := pdf.GetMargins()
            width, height := pdf.GetPageSize()
            fontSize := 12.0

            pNum := fmt.Sprint(pdf.PageNo())
            pdf.SetXY(width-left/2-pdf.GetStringWidth(pNum), height-bottom/2)
            pdf.SetFontSize(fontSize)
            pdf.SetTextColor(200, 200, 200)
            pdf.SetFontStyle("B")
            pdf.SetRightMargin(0)
            pdf.Write(fontSize, pNum)
            pdf.SetRightMargin(right)
        })
    }

	err = mdtopdf.Convert(md, pdf, pageNumExtension)
	if err != nil {
		fmt.Println(err)
		return
	}

About

Converts Markdown to PDF

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Go 100.0%