As a Ruby developer, you can convert your HTML files to PDF documents programmatically on the cloud using GroupDocs.Conversion Cloud API. HTML to PDF converter software is helpful for reading offline articles or sharing converted files in a portable form. In this article, we will learn how to convert HTML to PDF using REST API in Ruby.
The following topics shall be covered in this tutorial:
- HTML to PDF Conversion REST API and Ruby SDK Installation
- Convert HTML to PDF in Ruby using REST API
- HTML to PDF Conversion using Advanced Options in Ruby
- Online HTML to PDF Converter for Free
HTML to PDF Conversion REST API and Ruby SDK Installation
To begin to convert HTML to PDF without losing formatting, we will be using the Ruby SDK of GroupDocs.Conversion Cloud API by retaining the original text and layouts of your web page. Hence printing your documents will not result to a perplexed layout. Our API allows you to convert your documents and images of any supported file format to any format you need. You can easily convert between more than 50 types of documents and images such as Word, PowerPoint, Excel, PDF, HTML, CAD, raster images, etc.
You can install GroupDocs.Conversion html to pdf library free into your Ruby application. Use the below command in rails console for convert html to pdf free download gem:
gem install groupdocs_conversion_cloud
Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, please add in the code as shown below:
Convert HTML to PDF in Ruby using REST API
You can convert your HTML format to PDF file to View and Read Offline by following the simple steps mentioned below:
Upload the File
Firstly, upload the HTML document to the cloud storage for html2pdf multiple pages conversion using the code example given below:
As a result, the uploaded HTML file will be available in the files section of your dashboard on the cloud.
Convert HTML to PDF in Ruby
You can easily convert HTML document to PDF programmatically by following the steps given below:
- Create an instance of ConvertApi
- Create an instance of the ConvertSettings
- Set the HTML file path and output fileformat as “pdf”
- Create an instance of the HtmlLoadOptions
- Set the page_numbering to true
- Assign load options settings
- Set the output file path “html-to-pdf”
- Create ConvertDocumentRequest with ConvertSettings
- Finally, call the convert_document() method with ConvertDocumentRequest
The following code example shows how to convert from HTML file to PDF document using REST API.
Download the Converted File
The above code sample will save the html2pdf format file on the cloud. You can download it using the following code sample:
HTML to PDF Conversion using Advanced Options in Ruby
You can also convert HTML to PDF documents using advance options programmatically by following the steps given below:
- Create an instance of ConvertApi
- Create an instance of the ConvertSettings
- Set the HTML file path and output fileformat as “pdf”
- Create an instance of the HtmlLoadOptions
- Set the page_numbering to true
- Create an instance of the PdfConvertOptions
- Set various convertOptions center_window, from_page, margin_top etc.
- Assign load options settings and convert options settings
- Provide the output file path “html-to-pdf”
- Create ConvertDocumentRequest with ConvertSettings
- Now finally call the convert_document() method with ConvertDocumentRequest
The following code example shows how to convert chrome HTML document to PDF document with advance settings using REST API in Ruby. Please follow the steps mentioned earlier to upload and download the files.
Online HTML to PDF Converter for Free
How to convert HTML file to PDF online free? Convert HTML to PDF online free and in one click using our best html to pdf converter free. It is easy-to-use chrome html to pdf converter online free. This free html to pdf converter was developed using the above convert html to pdf API. Please try the following chrome html document to pdf converter online free.
Conclusion
In this article, we have learned how to convert chrome HTML to PDF documents using Ruby best html to pdf library on the cloud. This article also explained how to convert html to pdf with images using advance options. Moreover, this article also explained how to programmatically upload the HTML file to the cloud and then download the converted PDF file from the cloud. You can learn more about GroupDocs.Conversion file converter API using the documentation. We also provide an API Reference section that lets you visualize and communicate with our APIs directly through the browser.
Ask a question
If you have any queries aboutfree HTML to PDF converter or GroupDocs.Conversion Cloud REST APIs, please feel free to ask us on the Forum.