This page describes how to use the Pdfcrowd online API to convert images to PDF
in Ruby.
The API is user-friendly and can be integrated into your application with just a few lines of code.
Installation
You can install the client library from rubygems.org
Here are Ruby examples for quickly getting started with the API.
See more examples.
require"pdfcrowd"begin# create the API client instanceclient=Pdfcrowd::ImageToPdfClient.new("your_username","your_apikey")# run the conversion and write the result to a fileclient.convertFileToFile("/path/to/logo.png","logo.pdf")rescuePdfcrowd::Error=>whySTDERR.puts"Pdfcrowd Error: #{why}"raiseend
require"pdfcrowd"begin# create the API client instanceclient=Pdfcrowd::ImageToPdfClient.new("your_username","your_apikey")# run the conversion and write the result to a fileclient.convertUrlToFile("https://pdfcrowd.com/static/images/logo.png","logo.pdf")rescuePdfcrowd::Error=>whySTDERR.puts"Pdfcrowd Error: #{why}"raiseend
require"pdfcrowd"begin# create the API client instanceclient=Pdfcrowd::ImageToPdfClient.new("your_username","your_apikey")# run the conversion and write the result to a fileclient.convertRawDataToFile(open('/path/to/logo.png','rb').read(),"logo.pdf")rescuePdfcrowd::Error=>whySTDERR.puts"Pdfcrowd Error: #{why}"raiseend
Authentication
The credentials to access the API are your Pdfcrowd username and the API key.
Error Handling
It is recommended that you implement error handling to catch errors
that the API may return, see the example code below. A list of status
codes and their description can be found
here.
begin# call the API rescuePdfcrowd::Error=>why# print the errorSTDERR.puts"Pdfcrowd Error: #{why}"# print the error codeSTDERR.puts"Pdfcrowd Error Code: #{why.getCode()}"# print the error messageSTDERR.puts"Pdfcrowd Error Message: #{why.getMessage()}"end