PDF files are very useful and can be used as an alternative to many different types of data for storing documents. However, in certain cases, you have to convert PDF files to other file formats. For such cases, this article covers how to convert PDF files to popular image formats. Particularly, you will learn how to convert PDF files to PNG, JPEG, BMP, and TIFF images using Ruby. Our image converter provides better image quality than many other PDF to image converters.
The following topics shall be covered in this article:
- PDF Document to Images Converter API – Installation
- How to Convert PDF Document to PNG Image in Ruby
- How to Convert PDF File to JPEG Image Format in Ruby
- Convert PDF to BMP using REST API in Ruby
- Convert PDF Documents to TIFF Format in Ruby
PDF Document to Images Converter API – Installation
For converting PNG, JPEG, BMP, and TIFF images to Ruby, we will be using the Ruby SDK of GroupDocs.Conversion Cloud API. You can install it using the following command in the console:
gem install groupdocs_conversion_cloud
Firstly, get your Client ID and Secret from the dashboard before following the below mentioned steps. Once you have your ID and secret, add below code in your application as shown below:
How to Convert PDF Document to PNG Image in Ruby
We can convert PDF to PNG format programmatically by following the steps given below. Firstly, you need to upload the pdf document to the cloud using the following code sample. As a result, the uploaded file will be available in the files section of the dashboard on the cloud.
- Create an instance of the ConvertApi.
- Next, create an instance of the ConvertSettings
- Then, set the storage name and pdf file path
- Also, set “png” as output image format
- Create an instance of the PdfLoadOptions
- Set the pdf file password and load_options
- Create an instance of the PngConvertOptions
- Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf values
- Set convertOptions to settings
- Now, provide the output file path
- After that, create ConvertDocumentRequest with ConvertSettings as argument
- Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file
The following code example shows how to convert PDF to PNG format using REST API in Ruby:
The above code sample will save the converted PNG file on the cloud. You can also download it by adding the download file code to your application.
How to Convert PDF File to JPEG Image Format in Ruby
You can convert PDF to JPEG format programmatically by following the steps given below:
- Firstly, create an instance of the ConvertApi
- Next, create an instance of the ConvertSettings
- Then, set the pdf file path and storage name
- Also, assign “jpeg” as output image format
- Create an instance of the PdfLoadOptions
- Set the pdf file password and load_options
- Create an instance of the JpegConvertOptions
- Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf values etc
- Set convertOptions to settings
- Now, provide the output file path
- After that, create ConvertDocumentRequest with ConvertSettings as argument.
- Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file.
The following code sample shows how to convert PDF document to JPEG image using REST API in Ruby:
Convert PDF to BMP using REST API in Ruby
We can convert PDF to BMP format using advanced settings programmatically by following the steps given below:
- Create an instance of the ConvertApi
- Then, create an instance of the ConvertSettings
- Also, set the storage name and pdf file path
- Set “bmp” as output image format
- Create an instance of the PdfLoadOptions
- Set the pdf file password and load_options
- Create an instance of the BmpConvertOptions
- Define from_page and pages_count values
- Set convertOptions to settings
- Now, provide the output file path
- After that, create ConvertDocumentRequest with ConvertSettings as argument
- Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file
The following code example shows how to convert PDF to BMP image with advanced convert options:
Convert PDF Documents to TIFF Format in Ruby
We can convert PDF to TIFF programmatically by following the steps given below:
- Create an instance of the ConvertApi
- Next, create an instance of the ConvertSettings
- Then, set the pdf file path and storage name
- Also, set “tiff” as output image format
- Create an instance of the PdfLoadOptions
- Set the pdf file password and load_options
- Create an instance of the TiffConvertOptions
- Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf values
- Set convertOptions to settings
- Now, provide the output file path
- After that, create ConvertDocumentRequest with ConvertSettings as argument
- Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file
The following code sample shows how to convert PDF to TIFF file using REST API in Ruby. Please follow the steps mentioned earlier to upload a file:
Online PDF to Image Converter for Free
Please try the following free online PNG, JPEG, BMP, and TIFF Images conversion tool, which is developed using the above API https://products.aspose.app/pdf/convert-pdf-to-image.
Conclusion
In this article, we have learned how to:
- convert PDF file to PNG format using REST API in Ruby
- convert PDF document to JPEG image format in Ruby
- convert PDF documents to BMP using REST API in Ruby
- converting PDF file to TIFF file format in Ruby
You can learn more about GroupDocs.Conversion Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.
Ask a question
If you have any questions about PDF to images converter, please feel free to ask us on the Forum.