douchuilai2355 2018-07-11 06:06
浏览 66
已采纳

将HTML转换为PDF并下载PDF文件[关闭]

I need to download html tables in pdf format for generating report. Is there any way so that I can convert my html tables to pdf and download it instead of viewing in browser?

  • 写回答

2条回答 默认 最新

  • drd99007 2018-07-11 06:39
    关注

    Try this library I've used it before to convert html to pdf and it works fine for most of our cases https://github.com/SebastiaanKlippert/go-wkhtmltopdf

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • drr25281 2018-07-11 07:21
    关注

    In my case, using an online API like PDFShift works fine:

    package main
    
    import (
        "fmt"
        "strings"
        "net/http"
        "io/ioutil"
    )
    
    func main() {
    
        url := "https://api.pdfshift.io/v2/convert"
        var jsonStr = []byte(`{"source":"your_html_content_here"}`)
    
        req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
        req.SetBasicAuth("Your_API_KEY", "")
        res, _ := http.DefaultClient.Do(req)
    
        defer res.Body.Close()
        body, _ := ioutil.ReadAll(res.Body)
    
        fmt.Println(res)
        fmt.Println(string(body))
    }
    
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 win10商店接入问题
  • ¥15 java 这种树形框吗
  • ¥40 找同学帮敲Python代码
  • ¥15 MYSQL 订单的商品明细重复计算问题
  • ¥15 微信实时共享位置修改
  • ¥100 TG的session协议号转成直登号号后客户端登录几分钟后自动退出设备
  • ¥50 共模反馈回路的小信号增益
  • ¥15 arduino ssd1306函数与tone函数放歌代码不兼容问题
  • ¥70 0.96版本hbase的row_key里含有双引号,无法deleteall
  • ¥15 诊断性META分析合并效能的检验