Documentation
HTML-to-PDF with Ruby
Test API Key: YOUR_API_KEY_HERE
Code Examples
Installation
Add the following to your Gemfile
.
gem "docraptor"
Then run:
bundle install
Basic Usage
DocRaptor.configure do |config|
config.username = "YOUR_API_KEY_HERE"
# config.debugging = true
end
$docraptor = DocRaptor::DocApi.new
response = $docraptor.create_doc(
test: true, # test documents are free but watermarked
document_content: "<html><body>Hello World</body></html>", # supply content directly
# document_url: "http://docraptor.com/examples/invoice.html", # or use a url
name: "docraptor-ruby.pdf", # help you find a document later
document_type: "pdf", # pdf or xls or xlsx
# javascript: true, # enable JavaScript processing
# prince_options: {
# media: "screen", # use screen styles instead of print styles
# baseurl: "http://hello.com", # pretend URL when using document_content
# },
)
Next Steps
- Optionally store and get a URL for your converted document with document hosting
- View more code examples with error handling, asynchronous creation, file saving, and document hosting.
- Perfect your document styling with our knowledge base, style and formatting reference, and API reference. Easily add headers and footers, page breaks, page numbers, table of contents, and much more!
With DocRaptor, it's fast and painless to convert HTML, CSS, and JavaScript into PDF and XLS documents with Ruby. Below are working Ruby examples for creating documents. Our API reference lists all the generation options and our style and formatting guide will help make it look perfect.