I’m looking to write a simple script that runs docraptor on a file in my _site folder (after Jekyll has processed it) and then saves the returned PDF to the _site folder so that it can be consumed on the internet.
This was my first thought:
Jekyll::Hooks.register :site, :post_render do
require "bundler/setup"
Bundler.require
DocRaptor.configure do |dr|
dr.username = "--REDACTED--" # this key works for test documents
# dr.debugging = true
end
$docraptor = DocRaptor::DocApi.new
begin
# https://docraptor.com/documentation/api#api_general
create_response = $docraptor.create_doc(
test: true, # test documents are free but watermarked
# document_content: "<html><body>Hello World</body></html>", # supply content directly
document_url: "https://theatren.com/programs", # or use a url
name: "docraptor-ruby.pdf", # help you find a document later
document_type: "pdf", # pdf or xls or xlsx
# javascript: true, # enable JavaScript processing
# prince_options: {
# media: "screen", # use screen styles instead of print styles
# baseurl: "http://hello.com", # pretend URL when using document_content
# },
)
File.open("/Users/ryanhayden/ktch/theatren/_site/programs.pdf", "wb") do |file|
file.write(create_response)
end
puts "Wrote PDF to /Users/ryanhayden/ktch/theatren/_site/programs.pdf"
rescue DocRaptor::ApiError => error
puts "#{error.class}: #{error.message}"
puts error.code # HTTP response code
puts error.response_body # HTTP response body
puts error.backtrace[0..3].join("\n")
end
end
When I run this, I get undefined method 'downcase' for nil:NilClass
I’m definitely not a ruby expert, so I may be missing something obvious. Is this how you would even go about this?