Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ilovepdf

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ilovepdf

  • 1.3.4
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

iLovePDF Api - Ruby Library

Build Status GitHub version License: MIT

A library in ruby for iLovePDF Api

You can sign up for a iLovePDF account at https://developer.ilovepdf.com

Develop and automate PDF processing tasks like:

  • Compress PDF
  • Merge PDF
  • Split PDF
  • Convert Office to PDF
  • PDF to JPG
  • Images to PDF
  • Add Page Numbers
  • Rotate PDF
  • Unlock PDF
  • Protect PDF
  • Stamp a Watermark
  • Repair PDF
  • PDF to PDF/A
  • Validate PDF/A
  • Extract
  • Sign PDF

Each one with several settings to get your desired results.

Requirements

Ruby 2.6 or greater

Installation

Add this line to your application's Gemfile:

gem 'ilovepdf'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ilovepdf

Usage

Getting started

The quickest way to get started is to first get a set of API keys here and run the following code snippet:

public_key  = 'YOUR_PUBLIC_KEY'
private_key = 'YOUR_PRIVATE_KEY'
ilovepdf = Ilovepdf::Ilovepdf.new(public_key, private_key)
# Create a task with the tool you want to use:
task = ilovepdf.new_task :compress
# Add the files you want to upload...
file1 = task.add_file 'my_disk/my_example1.pdf'
file2 = task.add_file 'my_disk/my_example2.pdf'
file3 = task.add_file_from_url 'http://URL_TO_PDF'
# Once you are done uploading your files:
task.execute
task.download

That's it!

For a more in-depth usage, refer to the sample codes in this repository.

Signature Tool

The usage of this tool is different than the other tools, the following example shows how to create a signature using the iLovePDF API:

my_task = Ilovepdf::Tool::Signature.new(pub_key, priv_key)
# File object keeps information about its server_filename and the properties you can set
file  = my_task.add_file '/path/to/file/sample.pdf'

signer = Ilovepdf::Signature::Receiver.new(:signer,'name','email@email.com')

signature_element = Ilovepdf::Signature::SignatureElement.new(file)
signature_element.set_position(x: 20, y: -20)
signature_element.pages = "1"
signature_element.size = 40

signer << signature_element
body = my_task.send_to_sign.body

For a more in-depth usage, refer to all of the signature examples on the sample codes in this repository.

Documentation

HTTP API Calls

All PDF tools have the following methods that contact with the iLovePDF API:

MethodDescriptionNotes
add_file(file)Uploads a file to iLovepdf serversReturns boolean
add_file_from_url(url)Uploads a file to iLovepdf servers using a URLReturns boolean
delete_file(file)Deletes a file from ilovepdfReturns boolean
download(filepath)Downloads the processed fileReturns boolean; No need to specify a filepath
statusRetrieves the current status of the task being processedReturns Ilovepdf::Response
executeSends a request to Ilovepdf to begin processing the PDFsReturns Ilovepdf::Response
delete!Deletes the taskReturns Ilovepdf::Response

Example:

imagepdf_task = Ilovepdf::Tool::Imagepdf.new(public_key, secret_key)
http_response = imagepdf_task.execute
puts http_response.body
if imagepdf_task.download
  puts "Your file was downloaded successfully!"
end

Methods common to all tools

MethodDescriptionNotes
enable_file_encryption(boolean, key)The key will be used to decrypt the files before processing and re-encrypt them after processingIf no key provided, a random key is assigned (default: false)
assign_meta_value(key, value)More info
ignore_errorsMore info(default: true)
ignore_passwordMore info(default: true)
try_pdf_repairWhen a PDF to process fails we try to repair it automatically(default: true)
packaged_filenameThis allows you to specify the filename of the compressed file in case there is more than 1 file to be downloaded
output_filenameThe final name of the processed file
Methods to query after performing the execute API method:
  • result: It has stored the last Ilovepdf::Response
Methods to query after performing the download API method:
  • download_info: Returns a struct with the following info
    • :output_filename
    • :output_file
    • :output_filetype

Tool attributes

All tools have specific attributes you can access and modify. If you need want to know which params are available for a specific tool via the code, you can by looking at the API_PARAMS of that particular tool. For example for the Image to PDF tool:

puts Ilovepdf::Tool::Imagepdf::API_PARAMS
# => [:orientation, :margin, :pagesize]

To instantiate a Compress tool task directly do:

compress_task = Ilovepdf::Tool::Compress.new(public_key, secret_key)

Handling errors

Whenever there is an API Error in one of the endpoints, you can try to capture it the following way:

begin
  compress_task = Ilovepdf::Tool::Compress.new(public_key, secret_key)
  compress_task.execute # Oops, this raises an error! I forgot to upload a file!
  compress_taks.download
rescue Ilovepdf::ApiError => e
  # Let's check what went wrong with the API call:
  puts e.http_response.body
end

For a more complete example of error handling check samples/try_catch_errors.rb

Please see https://developer.ilovepdf.com/docs for up-to-date documentation.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 08 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc