Web/HTML To PDF REST API for Ruby Samples

Ruby-languageRuby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. Since its public release in 1995, Ruby has drawn devoted coders worldwide. In 2006, Ruby achieved mass acceptance. Ruby is also completely free. Not only free of charge, but also free to use, copy, modify, and distribute.

Because of its popularity, we are sure that a lot of you write your code in Ruby, so SelectPdf team decided to put together a few samples for our Html To Pdf API to make your life a little easier if you need to convert from web pages to pdf in your Ruby applications.

Exemple #1 – How to use Ruby to convert a webpage to PDF and save it on the disk

This code converts an url to pdf in Ruby using SelectPdf HTML To PDF API through a GET request. The content is saved into a file on the disk.

Exemple #2 – How to use Ruby to convert a webpage to PDF with a POST API request and save it on the disk

This code converts an url to pdf in Ruby using SelectPdf HTML To PDF REST API through a POST request. The parameters are url encoded. The content is saved into a file on the disk.

Exemple #3 – How to use Ruby to convert a web page to PDF with a POST API request and save it on the disk

This code converts an url to pdf in Ruby using SelectPdf HTML To PDF REST API through a POST request. The parameters are JSON encoded. The content is saved into a file on the disk.

The above samples use only the 2 mandatory parameters (key and url or html) for the html to pdf conversion. For the full list of optional parameters, take a look at SelectPdf HTML To PDF REST API page. Using the API optional parameters, you can control the page size, orientation and margins in the pdf document, the document information and security, the headers and footers and a lot more.

Hopefully these examples will help you to be on your way using the API for URL to PDF conversion in Ruby.

The above Ruby samples can also be found in the following GitHub repository:
https://github.com/selectpdf/selectpdf-api-ruby-samples