{"id":"6acc3789-5e28-4a10-ae41-ccac6dc177fe","slug":"gofpdf","kind":"mcp","name":"gofpdf","summary":"A PDF document generator with high level support for text, drawing and images","owner":"lvillar","repoUrl":"https://github.com/lvillar/gofpdf","license":"MIT","licenseTier":"permissive","trust":"community","stars":1,"match":null,"fewStars":true,"format":"mcp","createdAt":"2026-02-16T17:32:48.000Z","addedAt":"2026-10-21T20:36:59.014Z","logoUrl":"https://avatars.githubusercontent.com/u/26603357?u=577f11fd95ec43a798598c38ea3524291576cbe2&v=4","linkOnly":false,"collection":null,"skillPath":null,"categories":["files-documents"],"tags":[],"runtime":"go","local":true,"cloudCapable":false,"cloudCapability":"unknown","cloudReadyOnPlatform":false,"needsApiKey":false,"reviewed":false,"syncedAt":"2026-10-23T07:24:11.180Z","sample":false,"url":"https://conduits.dev/tools/gofpdf","language":"Go","transports":["stdio"],"install":{},"requirements":{"env":[],"upstreamMayCharge":false},"tools":null,"readme":"# GoFPDF - The Most Productive PDF Library for Go\n\n[![MIT\nlicensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/lvillar/gofpdf/master/LICENSE)\n[![Go Reference](https://pkg.go.dev/badge/github.com/lvillar/gofpdf.svg)](https://pkg.go.dev/github.com/lvillar/gofpdf)\n[![Go 1.23+](https://img.shields.io/badge/Go-1.23+-00ADD8.svg)](https://go.dev/)\n\nA comprehensive PDF library for Go — generate, read, merge, fill forms, sign, and more.\n\n## Features\n\n### PDF Generation (core)\n- UTF-8 TrueType fonts and right-to-left language support\n- Choice of measurement unit, page format and margins\n- Page header/footer management, automatic page breaks\n- Text, drawing, images (JPEG, PNG, GIF, TIFF, SVG paths)\n- Colors, gradients, alpha channel transparency\n- Outline bookmarks, internal/external links\n- Lines, Bezier curves, arcs, ellipses, rotation, scaling, clipping\n- Document protection (password encryption)\n- Layers, templates, barcodes, charting\n- Import existing PDFs as templates\n\n### PDF Reader (`reader/`)\n- Parse and inspect existing PDF documents\n- Extract text content from pages\n- Access document metadata (title, author, etc.)\n- Navigate page tree, resolve cross-references\n- Decompress FlateDecode streams\n- **Decrypt password-protected PDFs** (RC4 40-bit, RC4 128-bit)\n\n### High-Level Tables (`table/`)\n- Declarative table creation with functional options\n- Automatic column width calculation and text wrapping\n- Styled headers, alternating row colors, cell alignment\n- Multi-page tables with repeated headers\n\n### Page Operations (`pageops/`)\n- **Merge** multiple PDFs into one\n- **Split** PDFs by page ranges\n- **Rotate** pages (90, 180, 270 degrees)\n- **Add watermarks** (text overlays on every page)\n\n### Interactive Forms (`form/`)\n- **Create** forms with text fields, checkboxes, dropdowns, radio buttons\n- **Fill** existing PDF forms programmatically\n- **Flatten** forms (convert interactive fields to static content)\n\n### Digital Signatures (`sign/`)\n- **Sign** PDFs with PKCS#7 detached signatures\n- **Verify** signatures and detect tampering\n- Support for ECDSA and RSA keys\n- Signature metadata: reason, location, timestamp\n\n### JSON Template DSL (`doctpl/`)\n- Create PDFs from declarative **JSON templates** — ideal for LLM-generated content\n- Headings (h1–h6), paragraphs, tables, lists, images, horizontal rules, spacers\n- Custom fonts, colors, margins, headers, and footers\n- JSON round-trip: templates can be serialized, stored, and re-rendered\n\n### MCP Server (`mcp/`, `cmd/gofpdf-mcp/`)\n- **Model Context Protocol** server for AI assistants (Claude Desktop, etc.)\n- 10 tools: `create_pdf`, `read_pdf`, `read_pdf_text`, `merge_pdfs`, `add_watermark`, `add_page_numbers`, `fill_form`, `flatten_form`, `rotate_pages`, `pdf_info`\n- 4 resources: `pdf://text`, `pdf://metadata`, `pdf://pages`, `pdf://form-fields`\n- JSON-RPC 2.0 over stdio — zero external dependencies\n\n## Installation\n\n```shell\ngo get github.com/lvillar/gofpdf\n```\n\nRequires **Go 1.23** or later.\n\n## Quick Start\n\n### Generate a PDF\n\n```go\npackage main\n\nimport gofpdf \"github.com/lvillar/gofpdf\"\n\nfunc main() {\n    pdf := gofpdf.New(\"P\", \"mm\", \"A4\", \"\")\n    pdf.AddPage()\n    pdf.SetFont(\"Helvetica\", \"B\", 16)\n    pdf.Cell(40, 10, \"Hello, world\")\n    pdf.OutputFileAndClose(\"hello.pdf\")\n}\n```\n\n### Read a PDF\n\n```go\ndoc, err := reader.Open(\"document.pdf\")\nif err != nil {\n    log.Fatal(err)\n}\nfmt.Printf(\"Pages: %d\\n\", doc.NumPages())\n\nfor i, page := range doc.Pages() {\n    text, _ := page.ExtractText()\n    fmt.Printf(\"Page %d: %s\\n\", i, text)\n}\n```\n\n### Create a Table\n\n```go\npdf := gofpdf.New(\"P\", \"mm\", \"A4\", \"\")\npdf.AddPage()\npdf.SetFont(\"Helvetica\", \"\", 10)\n\ntbl := table.New(pdf,\n    table.WithColumns(\"Name\", \"Role\", \"Status\"),\n    table.WithHeaderStyle(table.CellStyle{FillColor: table.RGB(41, 128, 185), TextColor: table.RGB(255, 255, 255)}),\n)\ntbl.Row(\"Alice\", \"Engineer\", \"Active\")\ntbl.Row(\"Bob\", \"Designer\", \"On Leave\")\ntbl.Done()\n```\n\n### Merge PDFs\n\n```go\nerr := pageops.MergeFiles([]string{\"a.pdf\", \"b.pdf\", \"c.pdf\"}, \"merged.pdf\")\n```\n\n### Fill a Form\n\n```go\nerr := form.FillFile(\"template.pdf\", \"filled.pdf\", map[string]string{\n    \"name\":    \"John Doe\",\n    \"email\":   \"john@example.com\",\n    \"country\": \"USA\",\n})\n```\n\n### Sign a Document\n\n```go\nerr := sign.Sign(input, output, sign.Options{\n    Certificate: cert,\n    PrivateKey:  key,\n    Reason:      \"Approved\",\n    Location:    \"New York\",\n})\n```\n\n### Open an Encrypted PDF\n\n```go\ndoc, err := reader.OpenWithPassword(\"secret.pdf\", \"mypassword\")\nif err != nil {\n    log.Fatal(err)\n}\nmeta := doc.Metadata()\nfmt.Println(\"Title:\", meta[\"Title\"])\n```\n\n### Create a PDF from a JSON Template\n\n```go\ntemplate := `{\n    \"title\": \"Invoice #1234\",\n    \"pageSize\": \"A4\",\n    \"pages\": [{\n        \"elements\": [\n            {\"type\": \"heading\", \"text\": \"Invoice #1234\", \"level\": 1},\n            {\"type\": \"paragraph\", \"text\": \"Date: 2024-01-15\\nBill To: John Doe\"},\n            {\"type\": \"table\",\n             \"columns\": [\n                {\"header\": \"Item\", \"width\": 80},\n                {\"header\": \"Qty\", \"width\": 20, \"align\": \"C\"},\n                {\"header\": \"Price\", \"width\": 30, \"align\": \"R\"}\n             ],\n             \"rows\": [\n                [\"Widget A\", \"10\", \"$5.00\"],\n                [\"Widget B\", \"5\", \"$12.00\"]\n             ]},\n            {\"type\": \"paragraph\", \"text\": \"Total: $110.00\", \"align\": \"R\",\n             \"font\": {\"style\": \"B\", \"size\": 14}}\n        ]\n    }]\n}`\n\nvar buf bytes.Buffer\ndoctpl.Render(&buf, []byte(template))\nos.WriteFile(\"invoice.pdf\", buf.Bytes(), 0644)\n```\n\n### Use with AI Assistants (MCP)\n\nInstall the MCP server:\n\n```shell\ngo install github.com/lvillar/gofpdf/cmd/gofpdf-mcp@latest\n```\n\nAdd to your Claude Desktop configuration (`~/.config/claude/claude_desktop_config.json`):\n\n```json\n{\n  \"mcpServers\": {\n    \"gofpdf\": {\n      \"command\": \"gofpdf-mcp\"\n    }\n  }\n}\n```\n\nOnce configured, you can ask Claude to:\n- *\"Create a PDF invoice for Acme Corp with these line items...\"*\n- *\"Extract the text from report.pdf\"*\n- *\"Merge these 3 PDFs and add a CONFIDENTIAL watermark\"*\n- *\"Fill the form fields in application.pdf with this data...\"*\n- *\"What are the form fields in this PDF?\"*\n\n## Package Overview\n\n| Package | Description |\n|---------|-------------|\n| `gofpdf` (root) | PDF document generator — the core library |\n| `reader/` | PDF parser — open, inspect, extract text |\n| `table/` | High-level table builder with styling |\n| `pageops/` | Merge, split, rotate, watermark operations |\n| `form/` | Create, fill, and flatten interactive forms |\n| `sign/` | Digital signatures — sign and verify |\n| `doctpl/` | JSON template DSL — declarative PDF generation |\n| `mcp/` | MCP server — expose PDF tools to AI assistants |\n| `cmd/gofpdf-mcp/` | MCP server binary for Claude Desktop |\n| `contrib/` | Community contributions (barcodes, etc.) |\n| `makefont/` | Font definition file generator |\n\n## Migration from jung-kurt/gofpdf\n\nThis is a maintained fork of `jung-kurt/gofpdf` with full backward compatibility.\nTo migrate, update your import paths:\n\n```go\n// Before\nimport \"github.com/jung-kurt/gofpdf\"\n\n// After\nimport \"github.com/lvillar/gofpdf\"\n```\n\nAll existing code continues to work. The new packages (`reader`, `table`, `pageops`, `form`, `sign`, `doctpl`, `mcp`) are additive — they don't change the core API.\n\n## JSON Template Schema Reference\n\nThe `doctpl` package accepts JSON documents with the following structure:\n\n```json\n{\n  \"title\": \"string\",\n  \"author\": \"string\",\n  \"subject\": \"string\",\n  \"pageSize\": \"A4 | Letter | Legal\",\n  \"unit\": \"mm | cm | in | pt\",\n  \"margin\": {\"top\": 0, \"right\": 0, \"bottom\": 0, \"left\": 0},\n  \"font\": {\"family\": \"Helvetica\", \"style\": \"\", \"size\": 11},\n  \"header\": {\"text\": \"...\", \"align\": \"L|C|R\"},\n  \"footer\": {\"text\": \"Page {page}\", \"align\": \"C\"},\n  \"pages\": [{\"elements\": [...]}]\n}\n```\n\n### Supported Element Types\n\n| Type | Key Fields | Description |\n|------|-----------|-------------|\n| `heading` | `text`, `level` (1–6), `align`, `font`, `color` | Section heading with automatic sizing |\n| `paragraph` | `text`, `align`, `font`, `color` | Body text with word wrapping |\n| `table` | `columns` [{header, width, align}], `rows` [[...]], `headerStyle`, `cellStyle` | Data table with styled headers and alternating rows |\n| `list` | `items` [...], `ordered`, `bullet` | Bulleted or numbered list |\n| `image` | `src`, `x`, `y`, `width`, `height` | Embedded image (JPEG, PNG, GIF) |\n| `line` | `x1`, `y1`, `x2`, `y2`, `lineWidth`, `color` | Arbitrary line |\n| `rect` | `x`, `y`, `width`, `height`, `fillColor`, `border` | Rectangle shape |\n| `spacer` | `spacerHeight` | Vertical whitespace |\n| `hr` | `lineWidth`, `color` | Horizontal rule across the page |\n\n## MCP Server Reference\n\nThe `gofpdf-mcp` binary exposes the following tools and resources via the Model Context Protocol:\n\n### Tools\n\n| Tool | Description |\n|------|-------------|\n| `create_pdf` | Create a PDF from a JSON template. Accepts `template` (object) and optional `outputPath` (string). |\n| `read_pdf` | Read PDF metadata (version, page count, title, author). Accepts `path`. |\n| `read_pdf_text` | Extract text content from specific or all pages. Accepts `path` and optional `pages` array. |\n| `merge_pdfs` | Merge multiple PDFs into one. Accepts `inputPaths` array and `outputPath`. |\n| `add_watermark` | Add a text watermark. Accepts `inputPath`, `outputPath`, `text`, and optional `fontSize`, `opacity`, `angle`. |\n| `add_page_numbers` | Add page numbers. Accepts `inputPath`, `outputPath`, and optional `format`, `position`. |\n| `fill_form` | Fill form fields. Accepts `inputPath`, `outputPath`, and `values` object (field name to value). |\n| `flatten_form` | Flatten form fields to static content. Accepts `inputPath` and `outputPath`. |\n| `rotate_pages` | Rotate pages by 90/180/270 degrees. Accepts `inputPath`, `outputPath`, `angle`, and optional `pages` array. |\n| `pdf_info` | Get detailed PDF info (metadata, pages, form fields, dimensions). Accepts `path`. |\n\n### Resources\n\n| URI | Description |\n|-----|-------------|\n| `pdf://text?path=...` | Full text content of a PDF |\n| `pdf://metadata?path=...` | Document metadata (title, author, version, page count) |\n| `pdf://pages?path=...` | Page dimensions and rotation info |\n| `pdf://form-fields?path=...` | Form field names, types, values, and options |\n\n## Error Handling\n\nThe core `Fpdf` type uses an error accumulation pattern — if an error occurs,\nsubsequent method calls are no-ops until you check `Output()` or `Error()`:\n\n```go\npdf := gofpdf.New(\"P\", \"mm\", \"A4\", \"\")\npdf.AddPage()\npdf.SetFont(\"Helvetica\", \"\", 12)\npdf.Cell(40, 10, \"Hello\")\nerr := pdf.OutputFileAndClose(\"out.pdf\") // check error here\n```\n\nThe newer packages (`reader`, `table`, `pageops`, `form`, `sign`) return errors\ndirectly following standard Go conventions.\n\n## Contributing\n\nContributions are welcome. Please ensure your changes:\n\n- Are compatible with the MIT License\n- Are formatted with `go fmt`\n- Pass `go vet` without warnings\n- Include tests for new functionality\n- Don't diminish test coverage\n\n## License\n\nMIT License. See [LICENSE](LICENSE) for details.\n\n## Acknowledgments\n\nThis library is based on the excellent work of Kurt Jung and all\ncontributors to the original [jung-kurt/gofpdf](https://github.com/jung-kurt/gofpdf),\nwhich itself is derived from the [FPDF](http://www.fpdf.org/) library by Olivier Plathey.\n"}