{"id":13588981,"url":"https://github.com/cloudify/sPDF","last_synced_at":"2025-04-08T07:31:33.002Z","repository":{"id":10259582,"uuid":"12369589","full_name":"cloudify/sPDF","owner":"cloudify","description":"Create PDFs from Scala using plain old HTML and CSS. Uses wkhtmltopdf on the back-end which renders HTML using Webkit.","archived":false,"fork":false,"pushed_at":"2024-04-24T13:56:28.000Z","size":82,"stargazers_count":199,"open_issues_count":15,"forks_count":53,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-11-06T08:43:25.675Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudify.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":"2013-08-26T02:19:03.000Z","updated_at":"2024-05-28T05:53:55.000Z","dependencies_parsed_at":"2023-01-13T15:50:05.136Z","dependency_job_id":"35fe7b21-f23c-4e5e-b091-f6851ace5b84","html_url":"https://github.com/cloudify/sPDF","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudify%2FsPDF","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudify%2FsPDF/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudify%2FsPDF/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudify%2FsPDF/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudify","download_url":"https://codeload.github.com/cloudify/sPDF/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247796147,"owners_count":20997521,"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":[],"created_at":"2024-08-01T16:00:17.113Z","updated_at":"2025-04-08T07:31:32.690Z","avatar_url":"https://github.com/cloudify.png","language":"Scala","readme":"# sPDF #\n\nsPDF ( pronounced _speedy-f_ ) is a Scala library that makes it super easy to create complex PDFs from plain old HTML, CSS and Javascript.\n\nOn the backend it uses [wkhtmltopdf](http://wkhtmltopdf.org) which renders HTML using Webkit.\n\n__sPDF__ is heavily inspired by Ruby's [PdfKit](https://github.com/pdfkit/pdfkit) gem.\n\nThe main features of __sPDF__ are:\n\n* full support of `wkhtmltopdf` extended parameters (see the source of the `PdfConfig` trait)\n* can read HTML from several sources: `java.io.File`, `java.io.InputStream`, `java.net.URL`, `scala.xml.Elem`, and `String`\n* can write PDFs to `File` and `OutputStream`\n\nThe source HTML can reference to images and stylesheet files as long as the URLs point to the absolute path of the source file.\nIt's also possible to embed javascript code in the pages, `wkhtmltopdf` will wait for the document ready event before generating the PDF.\n\n## Installation ##\n\nAdd the following to your sbt build for Scala 2.10, 2.11 and 2.12:\n\n```scala\nlibraryDependencies += \"io.github.cloudify\" %% \"spdf\" % \"1.4.0\"\n```\n\nAdd the following to your sbt build for Scala 2.9:\n\n```scala\nlibraryDependencies += \"io.github.cloudify\" %% \"spdf\" % \"1.3.1\"\n```\n\n## Usage ##\n\n```scala\n\timport io.github.cloudify.scala.spdf._\n\timport java.io._\n\timport java.net._\n\n\t// Create a new Pdf converter with a custom configuration\n\t// run `wkhtmltopdf --extended-help` for a full list of options\n\tval pdf = Pdf(new PdfConfig {\n\t  orientation := Landscape\n\t  pageSize := \"Letter\"\n\t  marginTop := \"1in\"\n\t  marginBottom := \"1in\"\n\t  marginLeft := \"1in\"\n\t  marginRight := \"1in\"\n\t})\n\n\tval page = \u003chtml\u003e\u003cbody\u003e\u003ch1\u003eHello World\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e\n\n\t// Save the PDF generated from the above HTML into a Byte Array\n\tval outputStream = new ByteArrayOutputStream\n\tpdf.run(page, outputStream)\n\n\t// Save the PDF of Google's homepage into a file\n\tpdf.run(new URL(\"http://www.google.com\"), new File(\"google.pdf\"))\n```\n\nIf you want to use sPDF in headless mode on debian you'll need to call to wkhtmltopdf through a virtualizer like xvfb-run.\nThis is because wkhtmltopdf does not support running in headless mode on debian through the apt package. To use sPDF\nin this kind of environment you need to use WrappedPdf instead of Pdf. For Example:\n\n```scala\n\timport io.github.cloudify.scala.spdf._\n\timport java.io._\n\timport java.net._\n\n\t// Create a new Pdf converter with a custom configuration\n\t// run `wkhtmltopdf --extended-help` for a full list of options\n\tval pdf = WrappedPdf(Seq(\"xvfb-run\", \"wkhtmltopdf\"), new PdfConfig {\n\t  orientation := Landscape\n\t  pageSize := \"Letter\"\n\t  marginTop := \"1in\"\n\t  marginBottom := \"1in\"\n\t  marginLeft := \"1in\"\n\t  marginRight := \"1in\"\n\t})\n\n\tval page = \u003chtml\u003e\u003cbody\u003e\u003ch1\u003eHello World\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e\n\n\t// Save the PDF generated from the above HTML into a Byte Array\n\tval outputStream = new ByteArrayOutputStream\n\tpdf.run(page, outputStream)\n\n\t// Save the PDF of Google's homepage into a file\n\tpdf.run(new URL(\"http://www.google.com\"), new File(\"google.pdf\"))\n```\n\n## Installing wkhtmltopdf ##\n\nVisit the [wkhtmltopdf downloads page](http://wkhtmltopdf.org/downloads.html) and install the appropriate package for your platform.\n\n## Troubleshooting ##\n\n### NoExecutableException ###\n\nMake sure `wkhtmltopdf` is installed and your JVM is running with the correct `PATH` environment variable.\n\nIf that doesn't work you can manually set the path to `wkhtmltopdf` when you create a new `Pdf` instance:\n\n```scala\n\nval pdf = Pdf(\"/opt/bin/wkhtmltopdf\", PdfConfig.default)\n\n```\n\n### Resources aren't included in the PDF ###\n\nImages, CSS, or JavaScript does not seem to be downloading correctly in the PDF. This is due to the fact that `wkhtmltopdf` does not know where to find those files. Make sure you are using absolute paths (start with forward slash) to your resources. If you are using PDFKit to generate PDFs from a raw HTML source make sure you use complete paths (either file paths or urls including the domain).\n\n## Notes ##\n\n### Asynchronous conversion ###\n\n__sPDF__ relyies on Scala's `scala.sys.process.Process` class to execute `wkhtmltopdf` and pipe input/output data.\n\nThe execution of `wkhtmltopdf` and thus the conversion to PDF is blocking. If you need the processing to be asynchronous you can wrap the call inside a `Future`.\n\n```scala\n\nval pdf = Pdf(PdfConfig.default)\n\nval result = Future { pdf.run(new URL(\"http://www.google.com\"), new File(\"google.pdf\")) }\n\n```\n\n## Contributing ##\n\n* Fork the project.\n* Make your feature addition or bug fix.\n* Add tests for it. This is important so I don't break it in a future version unintentionally.\n* Commit, do not mess with build settings, version, or history.\n* Send me a pull request. Bonus points for topic branches.\n\n### Release / Publish ###\n\n* `release cross with-defaults`\n* check out released version\n* `publishSigned`\n* `sonatypeRelease`\n\n## Roadmap ##\n\n- [X] Full support for extended options\n- [X] Full support for input types\n- [ ] Streaming API (with `scalaz-stream`)\n- [ ] Simplified API with implicits\n- [ ] Integration with Play for streaming PDFs in HTTP responses\n\n## Copyright ##\n\nCopyright (c) 2013, 2014 Federico Feroldi. See `LICENSE` for details.\n","funding_links":[],"categories":["SCALA","Libraries"],"sub_categories":["Misc/Multi-language"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudify%2FsPDF","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudify%2FsPDF","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudify%2FsPDF/lists"}