Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jbd0101/ruby-gotenberg-client
https://github.com/jbd0101/ruby-gotenberg-client
Last synced: 29 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jbd0101/ruby-gotenberg-client
- Owner: jbd0101
- License: mit
- Created: 2022-08-25T19:39:44.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-08T20:22:08.000Z (about 2 years ago)
- Last Synced: 2024-12-20T01:36:27.777Z (about 2 months ago)
- Language: Ruby
- Size: 540 KB
- Stars: 8
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-gotenberg - Ruby - jbd0101/ruby-gotenberg-client
README
# Gotenberg client for Ruby
[Gotenberg] is awesome, but using it with Ruby is complicated.
This gem is not intended to wrap the whole api of Gotenberg but to make
the creation of PDFs easy in Ruby / Ruby on Rails.This gem is young and needs a lot of updates and improvements. (Work in progress, be patient, or contribute :-) )
## Install
First download and run Gotenberg:
```
docker run --rm -p 3000:3000 gotenberg/gotenberg:7
```Install `gotenberg-client` gem
```
gem install gotenberg-client
```or add `gotenberg-client` to your Gemfile.
## Usage
You will probably use this gem to generate PDFs in a Ruby on Rails background job or in a Ruby file.
Therefore, this gem does not (yet) integrate with any Ruby on Rails tools.
```ruby
require "gotenberg"api_endpoint = "http://localhost:3000" # change it with your specific port and address.
gb = Gotenberg::Client.new(api_endpoint)# check whether your endpoint is working
gb.up? # true if workingoutput_pdf = Tempfile.new("my-pdf.pdf")
html = "my html
"
gb.html(html, output_pdf)# Do not forget to destroy your tempfile
output_pdf.close
output_pdf.unlink
```If you want to use Rails views, the easiest way is to use [`ActionController::Base#render_to_string`][render_to_string].
Say you have a view file `app/views/test.html.erb` that requires a `@customer` variable.
```ruby
gb = Gotenberg::Client.new(api_endpoint)output_pdf = Tempfile.new("my-pdf.pdf")
ac = ActionController::Base.new
ac.instance_variable_set(:@customer, Customer.find(params[:id]))
gb.html(ac.render_to_string("/test.html.erb"), output_pdf)
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/jbd0101/ruby-gotenberg-client.
## License
do whatever you want with it
[Gotenberg]: https://gotenberg.dev/
[render_to_string]: https://api.rubyonrails.org/classes/AbstractController/Rendering.html#method-i-render_to_string