{"id":16512995,"url":"https://github.com/n6g7/httpdf","last_synced_at":"2025-03-21T08:31:31.301Z","repository":{"id":36043361,"uuid":"147260899","full_name":"n6g7/httpdf","owner":"n6g7","description":"PDF as React components, props over HTTP","archived":false,"fork":false,"pushed_at":"2023-07-18T20:15:38.000Z","size":7944,"stargazers_count":19,"open_issues_count":11,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T23:02:50.556Z","etag":null,"topics":["docker","express","generation","microservice","node","pdf","react","react-pdf"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/n6g7/httpdf/","language":"JavaScript","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/n6g7.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}},"created_at":"2018-09-03T22:52:13.000Z","updated_at":"2024-12-18T23:20:07.000Z","dependencies_parsed_at":"2024-10-28T10:14:13.605Z","dependency_job_id":"02d7b081-b4d3-4626-9d31-985fe6273640","html_url":"https://github.com/n6g7/httpdf","commit_stats":{"total_commits":360,"total_committers":3,"mean_commits":120.0,"dds":0.3222222222222222,"last_synced_commit":"11852fade0c4f1ee2c1768932287aa3e65d61498"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n6g7%2Fhttpdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n6g7%2Fhttpdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n6g7%2Fhttpdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n6g7%2Fhttpdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/n6g7","download_url":"https://codeload.github.com/n6g7/httpdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244765064,"owners_count":20506754,"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":["docker","express","generation","microservice","node","pdf","react","react-pdf"],"created_at":"2024-10-11T16:06:52.629Z","updated_at":"2025-03-21T08:31:26.289Z","avatar_url":"https://github.com/n6g7.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# htt*pdf*\n\n[![CircleCI](https://circleci.com/gh/n6g7/httpdf.svg?style=svg)](https://circleci.com/gh/n6g7/httpdf)\n[![Docker Hub](https://badgen.net/docker/pulls/n6g7/httpdf)](https://hub.docker.com/r/n6g7/httpdf/)\n\nA small HTTP microservice to generate PDFs.\n\n[react-pdf](https://react-pdf.org/) + [Express](https://expressjs.com/) + [Docker](https://www.docker.com/)\n\n## Getting started\n\n- Extend the [`n6g7/httpdf` image](https://hub.docker.com/r/n6g7/httpdf/) and copy your own PDF documents source:\n  ```Dockerfile\n  FROM n6g7/httpdf:latest\n  COPY ./documents $HTTPDF_DOCUMENTS_SRC\n  RUN yarn prebuild\n  ```\n- Build and run:\n  ```sh\n  docker build . -t my_httpf\n  docker run my_httpf -p 8000:80\n  ```\n- Generate pdf with HTTP requests:\n  ```sh\n  http localhost:8000/doc?a=Hello\u0026b=World \u003e doc.pdf\n  http POST localhost:8000/doc a=Hello b=World \u003e doc.pdf #equivalent\n  ```\n\nSee the [example directory](./example) for a full example with docker-compose.\n\n## Features\n\n### Props\n\nQuery parameters and body data sent with the request are passed to the react components as props.\n\nThey are validated using [prop-types](https://github.com/facebook/prop-types) and, if there are any, errors are returned with a 400 HTTP response.\n\n```sh\n$ http \"localhost:8000/demo?a=a\" -p hb\nHTTP/1.1 400 Bad Request\nConnection: keep-alive\nContent-Disposition: attachment; filename=\"demo.pdf\"\nContent-Length: 90\nContent-Type: application/json; charset=utf-8\nDate: Sun, 04 Nov 2018 00:31:23 GMT\n\n{\n    \"errors\": [\n        \"The prop `b` is marked as required in `Test`, but its value is `undefined`.\"\n    ]\n}\n```\n\n### Custom filename\n\nBy default, the suggested filename of the generated pdf will be computed from the component's file name (`doc.js` -\u003e `doc.pdf`).\nIf you would like to receive a different filename, you can override it with the `filename` query parameter:\n\n```sh\n$ http \"localhost:8000/demo?filename=custom.pdf\" -p h\nHTTP/1.1 200 OK\nConnection: keep-alive\nContent-Disposition: attachment; filename=\"custom.pdf\"\nContent-Type: application/pdf\nDate: Sun, 04 Nov 2018 00:29:58 GMT\nTransfer-Encoding: chunked\n```\n\n### Watch mode\n\nUse the `HTTPDF_WATCH` environment variable while developing to watch and automatically reload files as you make changes:\n\n```Dockerfile\nFROM n6g7/httpdf:latest\nENV HTTPDF_WATCH 1\nCOPY ./documents $HTTPDF_DOCUMENTS_SRC\nRUN yarn prebuild\n```\n\n### Images\n\nCopy your image files anywhere on the docker image and you can use the react-pdf API to render images:\n\n```js\nimport { Image, View } from \"@react-pdf/renderer\";\n\nconst Component = ({ path, ...props }) =\u003e (\n  \u003cView {...props}\u003e\n    \u003cImage src={`/images/${path}`} /\u003e\n  \u003c/View\u003e\n);\n```\n\nSee [react-pdf docs](https://react-pdf.org/components#image) for the list of available props.\n\n### Custom fonts\n\nCopy your font files anywhere on the docker image and you can use the react-pdf API to use custom fonts:\n\n```js\nimport { Font, StyleSheet } from \"@react-pdf/renderer\";\n\nFont.register(\"/fonts/montserrat.ttf\", {\n  family: \"Montserrat\",\n});\n\nconst styles = StyleSheet.create({\n  page: {\n    flexDirection: \"row\",\n    fontFamily: \"Montserrat\",\n    backgroundColor: \"#E4E4E4\",\n  },\n});\n```\n\nBrowse the [test files](./__tests__/app.js) for a description of all the features.\n\n### Async props\n\nPerform asynchronous actions before rendering in the `getAsyncProps` export:\n\n```js\nexport default function AsyncPropsTest({ result }) {\n  return (\n    \u003cDocument\u003e\n      \u003cPage size=\"A4\"\u003e\n        \u003cText\u003e{result}\u003c/Text\u003e\n      \u003c/Page\u003e\n    \u003c/Document\u003e\n  );\n}\n\nexport const document = true;\n\nexport async function getAsyncProps(props) {\n  return {\n    result: await someAPIcall(),\n  };\n}\n```\n\n## Contributing\n\n- Running in dev: `yarn install \u0026\u0026 yarn`\n- Release: `yarn version`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn6g7%2Fhttpdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn6g7%2Fhttpdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn6g7%2Fhttpdf/lists"}