-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcreate_pdf_thumbnail.rb
More file actions
29 lines (23 loc) · 650 Bytes
/
create_pdf_thumbnail.rb
File metadata and controls
29 lines (23 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'convert_api'
require 'tmpdir'
ConvertApi.configure do |config|
config.api_credentials = ENV['API_TOKEN'] # your api token
end
# Example of extracting first page from PDF and then chaining conversion PDF page to JPG.
# https://www.convertapi.com/pdf-to-extract
# https://www.convertapi.com/pdf-to-jpg
pdf_result = ConvertApi.convert(
'extract',
{File: 'files/test.pdf',
PageRange: 1}
)
jpg_result = ConvertApi.convert(
'jpg',
{File: pdf_result,
ScaleImage: true,
ScaleProportions: true,
ImageHeight: 300,
ImageWidth: 300}
)
saved_files = jpg_result.save_files(Dir.tmpdir)
puts "The thumbnail saved to #{saved_files}"