{"id":20459742,"url":"https://github.com/rosbit/pdf-table-generator","last_synced_at":"2026-04-18T05:31:40.650Z","repository":{"id":47602876,"uuid":"514474385","full_name":"rosbit/pdf-table-generator","owner":"rosbit","description":"a utility to generate a PDF with table. 一个生成带表格数据的PDF工具包。","archived":false,"fork":false,"pushed_at":"2022-08-07T08:52:57.000Z","size":698,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-09T18:52:12.339Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rosbit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-16T04:15:20.000Z","updated_at":"2024-10-25T15:27:35.000Z","dependencies_parsed_at":"2022-08-12T13:41:05.156Z","dependency_job_id":null,"html_url":"https://github.com/rosbit/pdf-table-generator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rosbit/pdf-table-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fpdf-table-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fpdf-table-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fpdf-table-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fpdf-table-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosbit","download_url":"https://codeload.github.com/rosbit/pdf-table-generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fpdf-table-generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31957546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T12:17:08.437Z","updated_at":"2026-04-18T05:31:40.629Z","avatar_url":"https://github.com/rosbit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pdf table generator\n\n1. separate pdf output and data generation via interface.\n2. position to display values will be calculated.\n3. the result can be output to file or HTTP.\n\n## interface\n\n```go\ntype PDFGenerator interface {\n    // 在输出整个pdf之前调用，在这里可以做一些输出准备工作\n    Init()\n    // 输出结束时调用\n    Cleanup()\n\n    GetPageSize() (pageSize *Rect)  // 页面尺寸，比如A4\n\n    // 获取线条属性，比如 width=0.5, lineType=\"normal\"\n    GetLineAttr() (drawLine bool, width float64, lineType string)\n\n    // 获取字体名称及字体文件\n    GetFonts() (\u003c-chan *Font)\n\n    // 获取图片及属性\n    GetImages() (\u003c-chan *ImageAttr) // Image-Path =\u003e {Left-upper Point, width, height}\n\n    // 获取输出目标\n    GetWriter() io.Writer\n\n    // 获取pdf的标题、底部y坐标、字体名称、字体大小。(标题会在计算后居中显示)\n    GetTitle() (title string, y float64, fontFamily string, fontSize float64)\n\n    // 获取pdf的标题栏: 第一行的(x,y)坐标、高度、字体名称、字体大小、标题描述\n    GetColumnTitles() (x, y float64, height float64, fontFamily string, fontSize float64, titles []*Title)\n\n    // 获取所有的输出行: 第一行的y坐标、高度、字体名称、字体大小、输出行(标题Name =\u003e 值)的channel\n    GetRows() (firstY float64, height float64, fontFamily string, fontSize float64, rows \u003c-chan map[string]string)\n}\n```\n\n## usage\n\n```go\npackage main\n\nimport (\n    \"github.com/rosbit/pdf-table-generator\"\n    \"os\"\n    \"io\"\n    \"log\"\n)\n\nfunc main() {\n    pg := \u0026pdfTest{}\n    pdfgen.GeneratePDFTable(pg);\n}\n\n// ---- PDFTableGenerator implementation ----\ntype pdfTest struct {\n    pdfgen.A4PDFTableGenerator\n    o *os.File\n}\n\nfunc (t *pdfTest) Init() {\n    o, e := os.OpenFile(\"./a.pdf\", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)\n    if e != nil {\n        log.Printf(\"%v\\n\", e)\n        return\n    }\n    t.o = o\n}\n\nfunc (t *pdfTest) Cleanup() {\n    if t.o != nil {\n        t.o.Close()\n    }\n}\n\nfunc (t *pdfTest) GetFonts() (\u003c-chan *pdfgen.Font) {\n    c := make(chan *pdfgen.Font)\n    go func() {\n        c \u003c- \u0026pdfgen.Font{\n            Family: \"msyh\",\n            FontPath: \"./msyh.ttf\", // make sure the file exists\n        }\n        close(c)\n    }()\n\n    return c\n}\n\nfunc (t *pdfTest) GetImages() (\u003c-chan *pdfgen.ImageAttr) {\n    c := make(chan *pdfgen.ImageAttr)\n    go func(){\n        c \u003c- \u0026pdfgen.ImageAttr{\n            Point: pdfgen.Point{\n                X: 10,\n                Y: 10,\n            },\n            Rect: pdfgen.Rect{\n                W: 40,\n                H: 40,\n            },\n            ImagePath: \"./logo.png\", // make sure the file exists\n        }\n        close(c)\n    }()\n\n    return c\n}\n\nfunc (t *pdfTest) GetWriter() io.Writer {\n    return t.o\n}\n\nfunc (t *pdfTest) GetTitle() (title string, y float64, fontFamily string, fontSize float64) {\n    title = \"看看pdf标题是否居中\"\n    y = 40\n    fontFamily = \"msyh\"\n    fontSize = 20.0\n    return\n}\n\nfunc (t *pdfTest) GetColumnTitles() (x, y float64, height float64, fontFamily string, fontSize float64, titles []*pdfgen.Title) {\n    x, y = 30.0, 70.0\n    height = 30.0\n    fontFamily = \"msyh\"\n    fontSize = 12.0\n    titles = []*pdfgen.Title{\n        \u0026pdfgen.Title{\n            Name: \"序号\",\n            Width: 50,\n        },\n        \u0026pdfgen.Title{\n            Name: \"封号\",\n            Width: 70,\n        },\n        \u0026pdfgen.Title{\n            Name: \"外号\",\n            Width: 70,\n        },\n        \u0026pdfgen.Title{\n            Name: \"姓名\",\n            Width: 70,\n        },\n        \u0026pdfgen.Title{\n            Name: \"性别\",\n            Width: 70,\n        },\n        \u0026pdfgen.Title{\n            Name: \"签名\",\n            Width: 260,\n            ColumnValueAlignLeft: true,\n        },\n    }\n\n    return\n}\n\nfunc (t *pdfTest) GetRows() (firstY float64, height float64, fontFamily string, fontSize float64, rows \u003c-chan map[string]string) {\n    firstY = 100\n    height = 29.0\n    fontFamily = \"msyh\"\n    fontSize = 12.0\n\n    c := make(chan map[string]string)\n    go func() {\n        c \u003c- map[string]string{\n            \"序号\": \"1\",\n            \"封号\": \"千手斗罗\",\n            \"外号\": \"千手斗罗\",\n            \"姓名\": \"唐三\",\n            \"性别\": \"男\",\n            \"签名\": \"过去的，...；未来的，...；现在的，...。\",\n        }\n        c \u003c- map[string]string{\n            \"序号\": \"2\",\n            \"封号\": \"柔骨斗罗\",\n            \"外号\": \"柔骨斗罗\",\n            \"姓名\": \"小舞\",\n            \"性别\": \"女\",\n            \"签名\": \"不乱...，不困...。不畏...，不念...。\",\n        }\n        close(c)\n    }()\n\n    rows = c\n    return\n}\n```\n\n## result\n\n![result image](a.png \"pdf -\u003e png\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fpdf-table-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosbit%2Fpdf-table-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fpdf-table-generator/lists"}