PDF Squeezer API Sign Up

Compress PDFs with the Ruby API

Use the PDF Squeezer PDF compression REST API from Ruby. Upload a PDF with Faraday or Net::HTTP and receive an optimized file.

require 'faraday'
require 'faraday/multipart'

api_key = ENV['PDF_SQUEEZER_KEY']
api_url = 'https://api.pdfsqueezer.io'

conn = Faraday.new(url: api_url) do |f|
  f.request :multipart
  f.request :url_encoded
  f.adapter Faraday.default_adapter
end

conn.headers['Authorization'] = "Bearer #{api_key}"

payload = {
  file: Faraday::Multipart::FilePart.new(
    File.open('original.pdf'),
    'application/pdf',
    'document.pdf'
  ),
  quality: 85,
  maxDimension: 1600,
  stripMetadata: true,
  convertToJpeg: true
}

response = conn.post('/v1/compress', payload)

if response.success?
  File.binwrite('optimized.pdf', response.body)
  puts "Ratio: #{response.headers['x-compression-ratio']}"
else
  puts "Error: #{response.body}"
end

Requires the faraday and faraday-multipart gems. Alternatively use rest-client or httparty with multipart support.

Full endpoint reference ยท Authentication

Get a free API key