{"id":30842014,"url":"https://github.com/codaea/simpleprint","last_synced_at":"2025-09-06T20:32:01.313Z","repository":{"id":310900997,"uuid":"1041677517","full_name":"Codaea/simpleprint","owner":"Codaea","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-20T21:57:19.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-20T23:35:47.016Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Codaea.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-20T21:08:02.000Z","updated_at":"2025-08-20T21:57:23.000Z","dependencies_parsed_at":"2025-08-20T23:35:51.467Z","dependency_job_id":"996cbd87-3687-48f5-9167-fc6da75110f2","html_url":"https://github.com/Codaea/simpleprint","commit_stats":null,"previous_names":["codaea/simpleprint"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Codaea/simpleprint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codaea%2Fsimpleprint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codaea%2Fsimpleprint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codaea%2Fsimpleprint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codaea%2Fsimpleprint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Codaea","download_url":"https://codeload.github.com/Codaea/simpleprint/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codaea%2Fsimpleprint/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273958390,"owners_count":25198043,"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-09-06T02:00:13.247Z","response_time":2576,"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":"2025-09-06T20:31:03.414Z","updated_at":"2025-09-06T20:32:01.303Z","avatar_url":"https://github.com/Codaea.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimplePrint\n\nA lightweight HTTP API server for thermal receipt printers using ESC/POS protocol. SimplePrint provides a simple REST interface to control thermal printers for receipt printing, QR codes, barcodes, and images.\n\n## Features\n\n- 🖨️ **Thermal Printer Support** - Works with ESC/POS compatible thermal printers via USB\n- 📄 **Multiple Content Types** - Print text, QR codes, barcodes, and images\n- 🔧 **Flexible Formatting** - Control fonts, sizes, alignment, and styling\n- 🔒 **Thread-Safe** - Handles concurrent print requests safely\n- 🚀 **Easy Integration** - Simple HTTP REST API\n\n## Installation\n\n### Prerequisites\n\n- Go 1.23.5 or later\n- ESC/POS compatible thermal printer connected via USB\n\n### Build from Source\n\n```bash\ngit clone https://github.com/codaea/simpleprint.git\ncd simpleprint\ngo mod download\ngo build -o simpleprint\n\n```\n\n### Configuration\nSimplePrint uses environment variables for configuration. You can set these in a .env file in the project root.\n\n| Variable      | Default   | Description                                      |\n|---------------|-----------|--------------------------------------------------|\n| `GIN_MODE`    | release   | Gin server mode (`release` or `debug`)           |\n| `PORT`        | 3000      | Port for the HTTP server                         |\n| `PRINTER_PATH`| (empty)   | USB path to the printer (optional, Linux only)   |\n\nCopy `.env.sample` to `.env` and adjust as needed.\n\n\n### Run the Server\n\n```bash\n./simpleprint\n```\n\nThe server will start on port `5010` by default.\n\n## API Reference\n\n### Base URL\n```\nhttp://localhost:5010\n```\n\n### Print Receipt\n\n**Endpoint:** `POST /print`\n\n**Description:** Sends a print job to the thermal printer. The request contains an array of print commands that will be executed sequentially.\n\n**Request Body:**\n```json\n{\n  \"receipt\": [\n    {\n      \"type\": \"line\",\n      \"content\": \"Restaurant Name\",\n      \"font_size\": 4,\n      \"font\": \"A\",\n      \"alignment\": \"center\",\n      \"underline\": false\n    },\n    {\n      \"type\": \"qr\",\n      \"code\": \"https://example.com/receipt/12345\",\n      \"size\": 8\n    }\n  ]\n}\n```\n\nThe `receipt` field is an array of print command objects. Each command represents a different element to print.\n\n## Print Command Types\n\n### Text Line (`line`)\n\nPrints a single line of text with formatting options.\n\n```json\n{\n  \"type\": \"line\",\n  \"content\": \"Hello World\",\n  \"font_size\": 2,\n  \"font\": \"A\",\n  \"alignment\": \"center\",\n  \"underline\": false\n}\n```\n\n**Parameters:**\n- `content` (string): The text to print\n- `font_size` (integer): Font size multiplier (1-8)\n- `font` (string): Font type - `\"A\"`, `\"B\"`, or `\"C\"`\n- `alignment` (string): Text alignment - `\"left\"`, `\"center\"`, or `\"right\"`\n- `underline` (boolean): Whether to underline the text\n\n### Multi-line Text (`text`)\n\nPrints text that can span multiple lines (supports `\\n` newlines).\n\n```json\n{\n  \"type\": \"text\",\n  \"content\": \"Multi-line text\\nwith newlines\\nSupported here\",\n  \"font_size\": 1,\n  \"font\": \"A\",\n  \"alignment\": \"left\",\n  \"underline\": false\n}\n```\n\n**Parameters:** Same as `line` type, but `content` can contain newline characters.\n\n### Line Feed (`feed`)\n\nAdvances the paper by the specified number of lines.\n\n```json\n{\n  \"type\": \"feed\",\n  \"lines\": 3\n}\n```\n\n**Parameters:**\n- `lines` (integer): Number of lines to feed\n\n### QR Code (`qr`)\n\nPrints a QR code with the specified data.\n\n```json\n{\n  \"type\": \"qr\",\n  \"code\": \"https://example.com/order/12345\",\n  \"size\": 8\n}\n```\n\n**Parameters:**\n- `code` (string): The data to encode in the QR code\n- `size` (integer): QR code size (1-16, where larger numbers create bigger codes)\n\n### Barcode (`barcode`)\n\nPrints a barcode with the specified data and format.\n\n```json\n{\n  \"type\": \"barcode\",\n  \"code\": \"123456789012\",\n  \"barcode_type\": \"CODE128\"\n}\n```\n\n**Parameters:**\n- `code` (string): The data to encode in the barcode\n- `barcode_type` (string): Barcode format - `\"UPCA\"`, `\"UPCE\"`, `\"EAN13\"`, `\"EAN8\"`, `\"CODE39\"`, or `\"CODE128\"`\n\n### Image (`image`)\n\nPrints an image from base64-encoded data.\n\n```json\n{\n  \"type\": \"image\",\n  \"data\": \"data:image/png;base64,iVBORw0KGgoAAAANSU...\",\n  \"alignment\": \"center\",\n  \"dither_mode\": \"floydsteinberg\"\n}\n```\n\n**Parameters:**\n- `data` (string): Base64-encoded image data (PNG format recommended)\n- `alignment` (string): Image alignment - `\"left\"`, `\"center\"`, or `\"right\"`\n- `dither-mode` (string): Dithering algorithm - `\"none\"` or `\"floydsteinberg\"`\n\n## Response Codes\n\n### Success Response\n**Status Code:** `200 OK`\n```json\n{\n  \"success\": true\n}\n```\n\n### Error Responses\n\n**Status Code:** `400 Bad Request`\n```json\n{\n  \"error\": \"Invalid JSON format or missing required fields\"\n}\n```\n\n**Status Code:** `503 Service Unavailable`\n```json\n{\n  \"error\": \"Printer is busy\",\n  \"message\": \"Another print job is currently in progress. Please try again later.\"\n}\n```\n\n## Complete Example\n\nHere's a complete example that demonstrates printing a receipt with multiple elements:\n\n```json\n{\n  \"receipt\": [\n    {\n      \"type\": \"line\",\n      \"content\": \"RECEIPT\",\n      \"font_size\": 4,\n      \"font\": \"A\",\n      \"alignment\": \"center\",\n      \"underline\": true\n    },\n    {\n      \"type\": \"feed\",\n      \"lines\": 1\n    },\n    {\n      \"type\": \"line\",\n      \"content\": \"Coffee Shop\",\n      \"font_size\": 2,\n      \"font\": \"A\",\n      \"alignment\": \"center\",\n      \"underline\": false\n    },\n    {\n      \"type\": \"line\",\n      \"content\": \"123 Main St, City\",\n      \"font_size\": 1,\n      \"font\": \"A\",\n      \"alignment\": \"center\",\n      \"underline\": false\n    },\n    {\n      \"type\": \"feed\",\n      \"lines\": 2\n    },\n    {\n      \"type\": \"text\",\n      \"content\": \"Order #12345\\nDate: 2025-08-20\\nTime: 14:30\",\n      \"font_size\": 1,\n      \"font\": \"A\",\n      \"alignment\": \"left\",\n      \"underline\": false\n    },\n    {\n      \"type\": \"feed\",\n      \"lines\": 1\n    },\n    {\n      \"type\": \"line\",\n      \"content\": \"--------------------------------\",\n      \"font_size\": 1,\n      \"font\": \"A\",\n      \"alignment\": \"center\",\n      \"underline\": false\n    },\n    {\n      \"type\": \"text\",\n      \"content\": \"1x Latte         $4.50\\n1x Croissant     $3.25\\nTax              $0.62\",\n      \"font_size\": 1,\n      \"font\": \"A\",\n      \"alignment\": \"left\",\n      \"underline\": false\n    },\n    {\n      \"type\": \"line\",\n      \"content\": \"--------------------------------\",\n      \"font_size\": 1,\n      \"font\": \"A\",\n      \"alignment\": \"center\",\n      \"underline\": false\n    },\n    {\n      \"type\": \"line\",\n      \"content\": \"TOTAL: $8.37\",\n      \"font_size\": 2,\n      \"font\": \"A\",\n      \"alignment\": \"center\",\n      \"underline\": false\n    },\n    {\n      \"type\": \"feed\",\n      \"lines\": 2\n    },\n    {\n      \"type\": \"qr\",\n      \"code\": \"https://coffeeshop.com/receipt/12345\",\n      \"size\": 6\n    },\n    {\n      \"type\": \"feed\",\n      \"lines\": 1\n    },\n    {\n      \"type\": \"line\",\n      \"content\": \"Thank you for your visit!\",\n      \"font_size\": 1,\n      \"font\": \"A\",\n      \"alignment\": \"center\",\n      \"underline\": false\n    }\n  ]\n}\n```\n\n## Usage with cURL\n\n```bash\ncurl -X POST http://localhost:5010/print \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"receipt\": [\n      {\n        \"type\": \"line\",\n        \"content\": \"Hello World!\",\n        \"font_size\": 2,\n        \"font\": \"A\",\n        \"alignment\": \"center\",\n        \"underline\": false\n      }\n    ]\n  }'\n```\n\n## Troubleshooting\n\n### Printer Not Found\nIf you see \"No Printa Found!!\" when starting the server, ensure:\n- Your thermal printer is connected via USB\n- The printer is powered on\n- You have the necessary permissions to access USB devices\n- The printer uses ESC/POS protocol\n\n### Print Jobs Hanging\nIf print jobs seem to hang:\n- Check that the printer has paper\n- Ensure the printer is not in an error state (paper jam, cover open, etc.)\n- Restart the SimplePrint server\n\n## Dependencies\n\n- [gin-gonic/gin](https://github.com/gin-gonic/gin) - HTTP web framework\n- [mect/go-escpos](https://github.com/mect/go-escpos) - ESC/POS printer library\n- [makeworld-the-better-one/dither](https://github.com/makeworld-the-better-one/dither) - Image dithering\n\n## License\n\nThis project is open source. Please check the license file for details.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodaea%2Fsimpleprint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodaea%2Fsimpleprint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodaea%2Fsimpleprint/lists"}