{"id":16158593,"url":"https://github.com/ktmouk/markup-pdf-rs","last_synced_at":"2025-07-26T21:11:12.393Z","repository":{"id":191637552,"uuid":"584612744","full_name":"ktmouk/markup-pdf-rs","owner":"ktmouk","description":"Make a PDF file by writing kind of like HTML and CSS.","archived":false,"fork":false,"pushed_at":"2023-01-03T06:24:49.000Z","size":1539,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-02T19:11:18.224Z","etag":null,"topics":["pdf","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ktmouk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-01-03T03:58:43.000Z","updated_at":"2023-07-12T00:10:56.000Z","dependencies_parsed_at":"2023-08-30T21:59:54.639Z","dependency_job_id":null,"html_url":"https://github.com/ktmouk/markup-pdf-rs","commit_stats":null,"previous_names":["ktmouk/markup-pdf-rs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ktmouk/markup-pdf-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktmouk%2Fmarkup-pdf-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktmouk%2Fmarkup-pdf-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktmouk%2Fmarkup-pdf-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktmouk%2Fmarkup-pdf-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktmouk","download_url":"https://codeload.github.com/ktmouk/markup-pdf-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktmouk%2Fmarkup-pdf-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267236821,"owners_count":24057657,"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","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"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":["pdf","rust"],"created_at":"2024-10-10T01:54:34.048Z","updated_at":"2025-07-26T21:11:12.373Z","avatar_url":"https://github.com/ktmouk.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# markup-pdf-rs\n\nThe Rust library for making a PDF files by writing kind of like HTML and CSS.\nInspired by [Satori](https://github.com/vercel/satori) and [React-pdf](https://github.com/diegomura/react-pdf). \nThis library makes a PDF file with [taffy](https://github.com/DioxusLabs/taffy) and [printpdf](https://github.com/fschutt/printpdf).\n\n\u003e :warning: This library is a prototype so we don't recommend using it in production.\n\n## Usage\n\n```rust main.rs\nuse std::{\n    fs::{File},\n    io::BufWriter,\n};\n\nuse markup_pdf_rs::{assets::Assets, document::Document, dom, style::Style};\nuse taffy::{\n    prelude::{Rect, Size},\n    style::{\n        Dimension::{self, Points},\n        FlexDirection, JustifyContent,\n    },\n};\n\nfn main() {\n    // Define styles like CSS used by XML.\n    let mut assets = Assets::default();\n    assets.styles.add(\n        // Specify the name of the style\n        // You can use this style by setting the `style` attribute to an element\n        // e.g. `\u003cLayer style=\"page\" /\u003e`\n        \"page\",\n        Style {\n            // These styles are basically the same as taffy.\n            size: Size {\n                width: Points(210.0),\n                height: Points(297.0),\n            },\n            ..Style::DEFAULT\n        },\n    );\n    assets.styles.add(\n        \"main\",\n        Style {\n            gap: Size {\n                width: Dimension::Auto,\n                height: Points(6.0),\n            },\n            flex_grow: 1.0,\n            flex_direction: FlexDirection::Column,\n            justify_content: JustifyContent::FlexStart,\n            padding: Rect::from_points(15.0, 15.0, 15.0, 15.0),\n            ..Style::DEFAULT\n        },\n    );\n    assets.styles.add(\n        \"title\",\n        Style {\n            font_size: 20.0,\n            size: Size {\n                width: Dimension::Auto,\n                height: Points(10.0),\n            },\n            ..Style::DEFAULT\n        },\n    );\n    assets.styles.add(\n        \"paragraph\",\n        Style {\n            size: Size {\n                width: Dimension::Auto,\n                height: Points(15.0),\n            },\n            ..Style::DEFAULT\n        },\n    );\n    assets.styles.add(\n        \"blockquote\",\n        Style {\n            background_color: Some(\"#eeeeee\"),\n            size: Size {\n                width: Dimension::Auto,\n                height: Points(23.0),\n            },\n            ..Style::DEFAULT\n        },\n    );\n    assets.styles.add(\n        \"blockquote-text\",\n        Style {\n            flex_grow: 1.0,\n            margin: Rect::from_points(5.0, 5.0, 5.0, 5.0),\n            size: Size {\n                width: Dimension::Auto,\n                height: Points(20.0),\n            },\n            ..Style::DEFAULT\n        },\n    );\n\n    // Define fonts\n    assets.fonts.add(\n        // You can use this font by setting the `font-family` property to a style\n        // The name of `default` means the default font if `font-family` is not specified\n        \"default\",\n        include_bytes!(\"assets/fonts/Roboto-Regular.ttf\").as_slice(),\n    );\n\n    // Pass a XML string to `dom::parse`.\n    let root = dom::parse(r#\"\n        \u003cDocument title=\"recipe\"\u003e\n            \u003cPage style=\"page\"\u003e\n                \u003cLayer style=\"main\"\u003e\n                    \u003cText style=\"title\"\u003eLorem Ipsum\u003c/Text\u003e\n                    \u003cText style=\"paragraph\"\u003eLorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sollicitudin mollis ipsum, eu aliquam est consequat vitae.\u003c/Text\u003e\n                    \u003cLayer style=\"blockquote\"\u003e\n                        \u003cText style=\"blockquote-text\"\u003eDonec nunc erat, porttitor eu massa blandit, pulvinar aliquam turpis. Maecenas augue justo, auctor ornare eleifend sed, suscipit ut mauris.\u003c/Text\u003e\n                    \u003c/Layer\u003e\n                    \u003cText style=\"paragraph\"\u003eLorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sollicitudin mollis ipsum, eu aliquam est consequat vitae.\u003c/Text\u003e\n                    \u003cText style=\"paragraph\"\u003eMauris in mattis lectus. Nulla eget iaculis ligula, eu pulvinar leo.\u003c/Text\u003e\n                    \u003cText style=\"paragraph\"\u003evitae laoreet erat mauris sed ipsum.\u003c/Text\u003e\n                \u003c/Layer\u003e\n            \u003c/Page\u003e\n        \u003c/Document\u003e\n    \"#).unwrap();\n\n    // Build `PdfDocumentReference` (this struct is in printpdf) by passing a XML and assets.\n    let doc = Document::new(\u0026root, assets)\n        .unwrap()\n        .build()\n        .unwrap();\n\n    // Call the `save` to export a PDF.\n    let buf = \u0026mut BufWriter::new(File::create(\"dist/simple.pdf\").unwrap());\n    doc.save(buf).unwrap();\n}\n```\n\nThe code above will make a PDF like below.\n\n|Result|\n| ---- |\n|\u003cimg src=\".github/simple.png\" width=\"200\" /\u003e |\n\n\n## Try with examples\n\nYou can try this library by running example codes included in the repository.\n\n```sh\n# Clone this repository.\n$ git clone git@github.com:ktmouk/markup-pdf-rs.git\n$ cd markup-pdf-rs\n\n# Download some fonts from Google Fonts and put them on the `examples/assets/fonts/` dir.\n$ ./examples/assets/fonts/install.sh\n\n# Try some example codes that make a PDF file.\n# PDF files will be made in the `dist/` dir.\n$ cargo run --example recipe\n$ cargo run --example resume\n```\n\n## Examples\n\n|Simple|Nikujaga Recipe (JP)|Japanese Resume (JP)|\n| ---- | ---- | ---- |\n| \u003cimg src=\".github/simple.png\" width=\"200\" /\u003e| \u003cimg src=\".github/recipe.png\" width=\"200\" /\u003e | \u003cimg src=\".github/resume.png\" width=\"200\" /\u003e |\n|[Code](examples/simple.rs)|[Code](examples/recipe.rs)|[Code](examples/resume.rs)|\n\n## Elements\n\n|Name|Usage|\n| ---- | ---- |\n|`\u003cDocument\u003e`|XML must start with this element. It can have only `\u003cPage\u003e` elements as children.|\n|`\u003cPage\u003e`|This element means one page of PDF. It should have a fixed size defined in the style to determined the page size. It can have `\u003cLayer\u003e` and `\u003cText\u003e` elements as children.|\n|`\u003cLayer\u003e`|This element is like `\u003cdiv\u003e` of HTML. You can use it for setting the styles. It can have `\u003cLayer\u003e` and `\u003cText\u003e` elements as children.|\n|`\u003cText\u003e`|You can use this element to write texts. It can have only string as a child. :warning: Currently, this element doesn't support calculating the width and height basing on the text automatically, so you need to specify the width and height by hand.|\n\n## Styles\nStyles are basically the same as [taffy](https://github.com/DioxusLabs/taffy) apart from some of property for specifying colors.\nYou can check the [style.rs](src/style.rs).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktmouk%2Fmarkup-pdf-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktmouk%2Fmarkup-pdf-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktmouk%2Fmarkup-pdf-rs/lists"}