{"id":14008064,"url":"https://github.com/stephenafamo/goldmark-pdf","last_synced_at":"2025-03-15T11:33:08.392Z","repository":{"id":57577580,"uuid":"359908227","full_name":"stephenafamo/goldmark-pdf","owner":"stephenafamo","description":"A PDF renderer for the goldmark markdown parser.","archived":false,"fork":false,"pushed_at":"2023-12-07T11:54:32.000Z","size":127,"stargazers_count":129,"open_issues_count":16,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T01:09:05.924Z","etag":null,"topics":["commonmark","go","golang","goldmark","goldmark-extension","markdown","pdf"],"latest_commit_sha":null,"homepage":"","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/stephenafamo.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-04-20T18:05:22.000Z","updated_at":"2025-02-25T09:51:23.000Z","dependencies_parsed_at":"2023-02-06T05:31:42.405Z","dependency_job_id":"940f8a0a-b38f-405c-a19d-26af69b3dc1d","html_url":"https://github.com/stephenafamo/goldmark-pdf","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenafamo%2Fgoldmark-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenafamo%2Fgoldmark-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenafamo%2Fgoldmark-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenafamo%2Fgoldmark-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephenafamo","download_url":"https://codeload.github.com/stephenafamo/goldmark-pdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243725026,"owners_count":20337660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["commonmark","go","golang","goldmark","goldmark-extension","markdown","pdf"],"created_at":"2024-08-10T11:01:11.835Z","updated_at":"2025-03-15T11:33:08.076Z","avatar_url":"https://github.com/stephenafamo.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# goldmark-pdf\n\ngoldmark-pdf is a renderer for [goldmark](http://github.com/yuin/goldmark) that allows rendering to PDF.\n\n![goldmark-pdf screenshot](https://res.cloudinary.com/stephenafamo/image/upload/v1618945448/goldmark-pdf%20screenshot.png)\n\n## Reference\n\nSee \u003chttps://pkg.go.dev/github.com/stephenafamo/goldmark-pdf\u003e\n\n## Usage\n\nCare has been taken to match the semantics of goldmark and its extensions.\n\nThe PDF renderer can be initiated with `pdf.New()` and the returned value satisfies `goldmark`'s `renderer.Renderer` interface, so it can be passed to `goldmark.New()` using the `goldmark.WithRenderer()` option.\n\n```go\nmarkdown := goldmark.New(\n    goldmark.WithRenderer(pdf.New()),\n)\n```\n\nOptions can also be passed to `pdf.New()`, the options interface to be satisfied is:\n\n```go\n// An Option interface is a functional option type for the Renderer.\ntype Option interface {\n\tSetConfig(*Config)\n}\n```\n\nHere is the `Config` struct that is to be modified:\n\n```go\ntype Config struct {\n\tContext context.Context\n\n\tPDF PDF\n\n\t// A source for images\n\tImageFS fs.FS\n\n\t// All other options have sensible defaults\n\tStyles Styles\n\n\t// A cache for the fonts\n\tFontsCache fonts.Cache\n\n\t// For debugging\n\tTraceWriter io.Writer\n\n\tNodeRenderers util.PrioritizedSlice\n}\n```\n\n\u003e Some helper functions for adding options are already provided. See [`option.go`](https://github.com/stephenafamo/goldmark-pdf/blob/master/option.go)\n\nAn example with some more options: \n\n```go\ngoldmark.New(\n    goldmark.WithRenderer(\n        pdf.New(\n            pdf.WithTraceWriter(os.Stdout),\n            pdf.WithContext(context.Background()),\n            pdf.WithImageFS(os.DirFS(\".\")),\n            pdf.WithLinkColor(\"cc4578\"),\n            pdf.WithHeadingFont(pdf.GetTextFont(\"IBM Plex Serif\", pdf.FontLora)),\n            pdf.WithBodyFont(pdf.GetTextFont(\"Open Sans\", pdf.FontRoboto)),\n            pdf.WithCodeFont(pdf.GetCodeFont(\"Inconsolata\", pdf.FontRobotoMono)),\n        ),\n    ),\n)\n```\n\n## Fonts\n\nThe fonts that can be used in the PDF are based on the `Font` struct\n\n```go\n// Represents a font.\ntype Font struct {\n\tCanUseForText bool\n\tCanUseForCode bool\n\n\tCategory string\n\tFamily   string\n\n\tFileRegular    string\n\tFileItalic     string\n\tFileBold       string\n\tFileBoldItalic string\n\n\tType fontType\n}\n```\n\nTo be used for text, a font should have regular, italic, bold and bold-italic styles. Each of these has to be loaded separately.\n\nTo ease this process, variables have been generated for all the Google fonts that have these styles. For example: \n\n```go\nvar FontRoboto = Font{\n\tCanUseForCode:  false,\n\tCanUseForText:  true,\n\tCategory:       \"sans-serif\",\n\tFamily:         \"Roboto\",\n\tFileBold:       \"700\",\n\tFileBoldItalic: \"700italic\",\n\tFileItalic:     \"italic\",\n\tFileRegular:    \"regular\",\n\tType:           fontTypeGoogle,\n}\n```\n\nFor codeblocks, if any other style is missing, the regular font is used in place.\n\n```go\nvar FontMajorMonoDisplay = Font{\n\tCanUseForCode:  true,\n\tCanUseForText:  false,\n\tCategory:       \"monospace\",\n\tFamily:         \"Major Mono Display\",\n\tFileBold:       \"regular\",\n\tFileBoldItalic: \"regular\",\n\tFileItalic:     \"regular\",\n\tFileRegular:    \"regular\",\n\tType:           fontTypeGoogle,\n}\n```\n\nWhen loading the fonts, they are downloaded on the fly using the [`fonts`](https://github.com/go-swiss/fonts).\n\nIf you'd like to use a font outside of these, you should pass your own font struct which have been loaded into the `PDF` object you set in the `Config`. Be sure to set the `FontType` to `FontTypeCustom` so that we do not attempt to download it.\n\n## Contributing\n\nHere's a list of things that I'd love help with:\n\n* [ ] More documentation\n* [ ] Testing\n* [ ] Finish the (currently buggy) implementation based on [`gopdf`](https://github.com/signintech/gopdf)\n\n\n## License\n\nMIT\n\n## Author \n\n[Stephen Afam-Osemene](https://stephenafamo.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenafamo%2Fgoldmark-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephenafamo%2Fgoldmark-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenafamo%2Fgoldmark-pdf/lists"}