Excel pdf 导出
坐标法
gopdf "github.com/signintech/gopdf" ) func xy2pdf() { pdf := gopdf.GoPdf{} pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4}) //595.28, 841.89 = A4 pdf.AddPage() err := pdf.AddTTFFont("arial", "./arial.ttf") if err != nil { log.Print(err.Error()) return } var fontSize float64 = 4 err = pdf.SetFont("arial", "", float64(fontSize)) if err != nil { log.Print(err.Error()) return } var padding float64 = 3 var xStartOrigin float64 = 30 var xStart float64 = 30 var yStart float64 = 30 var yStartOrigin float64 = 30 var lineHeight float64 = fontSize + padding pdf.SetXY(xStart, yStart) pdf.Text("signintech/gopdf") yStart += 2 * lineHeight var x float64 = 30 // 横竖 x y var y float64 = 40 var columnX []float64 var columnWidth float64 = 60 var columnNames []string = []string{ "No", "Building", "Room", "DeviceType", "DeviceIP", "Uptime Duration(hh:mm:ss)", "Uptime %", "Downtime Duration(hh:mm:ss)", "Downtime % ", "Downtime Frequency", } var columnNum int = len(columnNames) var lastX float64 for i := 0; i < columnNum; i++ { var x float64 switch i { case 0: x = 0.2 * columnWidth case 1: x = lastX + 0.3*columnWidth default: x = lastX + columnWidth } columnX = append(columnX, x) lastX = x } for i, x := range columnX { pdf.SetXY(x, yStart) pdf.Text(columnNames[i]) } yStart += 2 * lineHeight _, _ = x, y for j := 0; j < 320; j++ { for i, x := range columnX { pdf.SetXY(x, yStart) pdf.Text("j=" + fmt.Sprint(j) + "=" + "i=" + fmt.Sprint(i)) } yStart += lineHeight if j > 0 && j%110 == 0 { pdf.AddPage() xStart = xStartOrigin yStart = yStartOrigin } } pdf.SetXY(30, 70) pdf.Text("Link to second page") pdf.AddInternalLink("anchor", 27.5, 58, 120, 15) pdf.AddPage() pdf.SetXY(30, 100) pdf.SetAnchor("anchor") pdf.Text("Anchor position") pdf.WritePdf("html2pdfAAAA.pdf") }