//右对齐 func (pdf *ZCMPdf) WriteInRight(text string) *ZCMPdf { wide, _ := pdf.MeasureTextWidth(text) //2.居中定位,写 // offset := (PAGEWIDE - pdf.GetX() - wide) / 2 offset := pdf.Config.PAGEWIDE - pdf.Config.SIDE - wide pdf.SetX(offset) pdf.Cell(nil, text) pdf.DoBR(utils.GetBR(DEFAULTFONTSIZE)) return pdf }
func (pdf *ZCMPdf) WriteInCenter(text string, fontSize int) *ZCMPdf { //1.设置字体 pdf.SetFontSize(fontSize) wide, _ := pdf.MeasureTextWidth(text) //2.居中定位,写 // offset := (PAGEWIDE - pdf.GetX() - wide) / 2 offset := (pdf.Config.PAGEWIDE - wide) / 2 pdf.SetX(offset) pdf.Cell(nil, text) pdf.DoBR(utils.GetBR(fontSize)) if fontSize != DEFAULTFONTSIZE { //3.字体设置回默认的 pdf.SetDefaultFontSize() } return pdf }