{"id":35644705,"url":"https://github.com/kallefrombosnia/tinypdf-php","last_synced_at":"2026-01-13T23:42:28.304Z","repository":{"id":329978569,"uuid":"1121197411","full_name":"kallefrombosnia/tinypdf-php","owner":"kallefrombosnia","description":"Minimal PDF creation library for PHP 8.2+. Zero dependencies, strongly typed, clean code.","archived":false,"fork":false,"pushed_at":"2026-01-05T10:52:26.000Z","size":1798,"stargazers_count":22,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-13T19:50:54.647Z","etag":null,"topics":["document","markdown","pdf","php","tinypdf"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/kallefrombosnia.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-22T15:38:22.000Z","updated_at":"2026-01-08T15:58:20.000Z","dependencies_parsed_at":"2025-12-24T03:06:23.999Z","dependency_job_id":null,"html_url":"https://github.com/kallefrombosnia/tinypdf-php","commit_stats":null,"previous_names":["kallefrombosnia/tinypdf-php"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kallefrombosnia/tinypdf-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kallefrombosnia%2Ftinypdf-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kallefrombosnia%2Ftinypdf-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kallefrombosnia%2Ftinypdf-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kallefrombosnia%2Ftinypdf-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kallefrombosnia","download_url":"https://codeload.github.com/kallefrombosnia/tinypdf-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kallefrombosnia%2Ftinypdf-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405320,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["document","markdown","pdf","php","tinypdf"],"created_at":"2026-01-05T12:22:22.001Z","updated_at":"2026-01-13T23:42:28.299Z","avatar_url":"https://github.com/kallefrombosnia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinyPDF-PHP\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"art/preview.png\" alt=\"TinyPDF-PHP Preview\" width=\"800\"\u003e\n\u003c/p\u003e\n\n[![Tests](https://github.com/kallefrombosnia/tinypdf-php/actions/workflows/tests.yml/badge.svg)](https://github.com/kallefrombosnia/tinypdf-php/actions/workflows/tests.yml)\n[![Issues](https://img.shields.io/github/issues/kallefrombosnia/tinypdf-php.svg?style=flat-square)](https://github.com/kallefrombosnia/tinypdf-php/issues)\n\nMinimal PDF creation library for PHP 8.2+. Zero dependencies, strongly typed, clean code architecture.\n\nPort of [tinypdf](https://github.com/Lulzx/tinypdf) from TypeScript to PHP.\n\n## Features\n\n- Create PDFs from scratch with zero dependencies\n- Strongly typed with PHP 8.2+ type declarations\n- Clean architecture with interfaces and value objects\n- Support for text, rectangles, lines, JPEG images, and clickable links\n- Built-in markdown to PDF conversion\n- Text measurement and alignment\n- Color support (hex format)\n\n## Installation\n\n```bash\ncomposer require kallefrombosnia/tinypdf-php\n```\n\n## Usage\n\n### Basic PDF Creation\n\n```php\nuse TinyPdf\\TinyPdf;\nuse TinyPdf\\TextOptions;\nuse TinyPdf\\TextAlign;\n\n$pdf = TinyPdf::create();\n\n// Add a page (default US Letter: 612x792 points)\n$pdf-\u003epage(function ($ctx) {\n    // Add text\n    $ctx-\u003etext('Hello World!', 50, 700, 24);\n\n    // Text with options\n    $ctx-\u003etext(\n        'Centered text',\n        50,\n        650,\n        16,\n        new TextOptions(\n            align: TextAlign::CENTER,\n            width: 500,\n            color: '#0066cc'\n        )\n    );\n\n    // Draw a rectangle\n    $ctx-\u003erect(50, 600, 200, 100, '#ffcc00');\n\n    // Draw a line\n    $ctx-\u003eline(50, 580, 250, 580, '#000000', 2);\n});\n\n// Custom page size\n$pdf-\u003epage(595, 842, function ($ctx) { // A4 size\n    $ctx-\u003etext('A4 Page', 50, 700, 18);\n});\n\n// Build and save\n$pdfContent = $pdf-\u003ebuild();\nfile_put_contents('output.pdf', $pdfContent);\n```\n\n### Adding Images\n\n```php\n$pdf = TinyPdf::create();\n\n$pdf-\u003epage(function ($ctx) {\n    $jpegData = file_get_contents('image.jpg');\n    $ctx-\u003eimage($jpegData, 50, 500, 200, 150);\n});\n\nfile_put_contents('output.pdf', $pdf-\u003ebuild());\n```\n\n### Markdown to PDF\n\n```php\nuse TinyPdf\\MarkdownConverter;\n\n$markdown = \u003c\u003c\u003cMD\n# Document Title\n\nThis is a paragraph with **bold** text.\n\n## Section Header\n\n- List item 1\n- List item 2\n- List item 3\n\n1. Numbered item\n2. Another item\n\n---\n\nAnother paragraph after a horizontal rule.\nMD;\n\n$converter = new MarkdownConverter(\n    width: 612,    // US Letter width\n    height: 792,   // US Letter height\n    margin: 72     // 1 inch margins\n);\n\n$pdfContent = $converter-\u003econvert($markdown);\nfile_put_contents('document.pdf', $pdfContent);\n```\n\n### Adding Clickable Links\n\n```php\nuse TinyPdf\\LinkOptions;\n\n$pdf = TinyPdf::create();\n\n$pdf-\u003epage(function ($ctx) {\n    $ctx-\u003etext('GitHub Repository', 50, 700, 12, new TextOptions(color: '#0066cc'));\n    $ctx-\u003elink('https://github.com/kallefrombosnia/tinypdf-php', 50, 695, 115, 20, new LinkOptions(underline: '#0066cc'));\n\n    $ctx-\u003etext('Check out Webflow agency', 50, 650, 12, new TextOptions(color: '#95a5a6'));\n    $ctx-\u003elink('https://www.flowout.com/', 50, 645, 150, 20);\n});\n\nfile_put_contents('output.pdf', $pdf-\u003ebuild());\n```\n\n### Text Measurement\n\n```php\nuse TinyPdf\\TinyPdf;\n\n$width = TinyPdf::measureText('Hello World', 24);\necho \"Text width: {$width} points\\n\";\n```\n\n## Examples\n\nThe library includes several complete examples in the `examples/` directory:\n\n### Running Examples\n\nRun all examples at once:\n```bash\nphp example.php\n```\n\nOr run individual examples:\n```bash\n# Basic text and shapes\nphp examples/basic/basic.php\n\n# Professional invoice\nphp examples/invoice/invoice.php\n\n# Markdown to PDF\nphp examples/markdown/markdown.php\n\n# Multi-page document\nphp examples/multipage/multipage.php\n```\n\n### Available Examples\n\nEach example includes its own README with detailed information and generated PDF output.\n\n- **[Basic](examples/basic/)** - Text rendering, shapes, colors, alignment, and links ([preview](examples/basic/output.pdf))\n- **[Invoice](examples/invoice/)** - Professional invoice template ([preview](examples/invoice/output.pdf))\n- **[Receipt](examples/receipt/)** - Sales receipt template ([preview](examples/receipt/output.pdf))\n- **[Report](examples/report/)** - Business report with charts ([preview](examples/report/output.pdf))\n- **[Shipping Label](examples/shipping-label/)** - Package shipping label ([preview](examples/shipping-label/output.pdf))\n- **[Markdown](examples/markdown/)** - Convert markdown to PDF ([preview](examples/markdown/output.pdf))\n- **[Multi-Page](examples/multipage/)** - Multi-page documents ([preview](examples/multipage/output.pdf))\n- **[Ticket](examples/ticket/)** - Event ticket design ([preview](examples/ticket/output.pdf))\n- **[Data Export](examples/data-export/)** - Export data tables ([preview](examples/data-export/output.pdf))\n- **[Service Agreement](examples/service-agreement/)** - Contract template ([preview](examples/service-agreement/output.pdf))\n\n## API Reference\n\nFor detailed API documentation, see the inline documentation in the source code:\n- [TinyPdf](src/TinyPdf.php) - Main factory class\n- [PageContextInterface](src/Contracts/PageContextInterface.php) - Drawing operations (text, rect, line, image, link)\n- [TextOptions](src/TextOptions.php) - Text rendering options\n- [LinkOptions](src/LinkOptions.php) - Link configuration\n- [MarkdownConverter](src/MarkdownConverter.php) - Markdown to PDF conversion\n\n## Coordinate System\n\nPDF uses a coordinate system where:\n- Origin (0, 0) is at the bottom-left corner\n- X increases to the right\n- Y increases upward\n- Units are in points (1/72 inch)\n\nCommon page sizes:\n- US Letter: 612 x 792 points\n- A4: 595 x 842 points\n\n## Testing \u0026 Quality\n\n```bash\ncomposer test              # Run all tests\ncomposer test:coverage     # Run tests with coverage\ncomposer phpstan          # Run static analysis\n```\n\n**77 tests** with comprehensive coverage including unit tests, architecture tests, and integration tests.\n\nFor detailed information about the test suite, coverage, and quality standards, see [tests/README.md](tests/README.md).\n\n## License\n\nMIT\n\n## Credits\n\nThis is a PHP port of [tinypdf](https://github.com/Lulzx/tinypdf) by Lulzx.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkallefrombosnia%2Ftinypdf-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkallefrombosnia%2Ftinypdf-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkallefrombosnia%2Ftinypdf-php/lists"}