Ad

Turning Binary Into PDF In Ruby On Rails

- 1 answer

I'm integrating with a third party ID verification provider. Once the ID verification checks have run a report is generated, which I can access with a get request.

The response is binary text (screenshot attached), which I want to save to a PDF file.

Function:

def generate_pdf
  resources = "applicants/61f84499b7b92f00014d5c6d/summary/report?report=applicantReport"
  response = RestClient.get(request_env_url(resources), signed_header(resources, nil, 'GET', 'application/pdf'))

  puts response
end

How do I take the binary response, create a new file and add the binary into that file in a friendly and readable format?

Response

Ad

Answer

If you can access a filesystem, you might just want to write that data to a file:

File.open("thing.pdf", "wb") { |f| f.write response }
Ad
source: stackoverflow.com
Ad