-
Notifications
You must be signed in to change notification settings - Fork 2
/
makepdf.rb
49 lines (42 loc) · 1.64 KB
/
makepdf.rb
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module PdfMaker
class << self
def registered(app)
app.after_build do |builder|
active_resume = data.active_resume.name
@resume_data = eval("data.#{active_resume}")
begin
require 'pdfkit'
kit = PDFKit.new(File.new('build/pdf.html'),
:page_size => 'Letter',
:viewport_size => '2480x3508',
:zoom => 0.7,
# :dpi => 300
:encoding => 'TEXT',
:print_media_type => false
)
kit.to_file("build/#{@resume_data.pdf.filename}.pdf")
builder.say_status "PDF Maker", "PDF file available at build/#{@resume_data.pdf.filename}.pdf"
rescue Exception =>e
builder.say_status "PDF Maker", "Error: #{e.message}", Thor::Shell::Color::RED
raise
end
begin
kit = PDFKit.new(File.new('build/pdf-brief.html'),
:page_size => 'Letter',
:viewport_size => '2480x3508',
:zoom => 0.7,
# :dpi => 300
:print_media_type => false
)
kit.to_file("build/#{@resume_data.pdf.filename}-brief.pdf")
builder.say_status "PDF Maker", "PDF file available at build/#{@resume_data.pdf.filename}-brief.pdf"
rescue Exception =>e
builder.say_status "PDF Maker", "Error: #{e.message}", Thor::Shell::Color::RED
raise
end
end
alias :included :registered
end
end
end
::Middleman::Extensions.register(:pdfmaker, PdfMaker)