Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
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:
Each one with several settings to get your desired results.
Ruby 2.6 or greater
Add this line to your application's Gemfile:
gem 'ilovepdf'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ilovepdf
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.
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.
All PDF tools have the following methods that contact with the iLovePDF API:
Method | Description | Notes |
---|---|---|
add_file(file) | Uploads a file to iLovepdf servers | Returns boolean |
add_file_from_url(url) | Uploads a file to iLovepdf servers using a URL | Returns boolean |
delete_file(file) | Deletes a file from ilovepdf | Returns boolean |
download(filepath) | Downloads the processed file | Returns boolean; No need to specify a filepath |
status | Retrieves the current status of the task being processed | Returns Ilovepdf::Response |
execute | Sends a request to Ilovepdf to begin processing the PDFs | Returns Ilovepdf::Response |
delete! | Deletes the task | Returns 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
Method | Description | Notes |
---|---|---|
enable_file_encryption(boolean, key) | The key will be used to decrypt the files before processing and re-encrypt them after processing | If no key provided, a random key is assigned (default: false) |
assign_meta_value(key, value) | More info | |
ignore_errors | More info | (default: true) |
ignore_password | More info | (default: true) |
try_pdf_repair | When a PDF to process fails we try to repair it automatically | (default: true) |
packaged_filename | This allows you to specify the filename of the compressed file in case there is more than 1 file to be downloaded | |
output_filename | The final name of the processed file |
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)
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.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that ilovepdf demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.