-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakepdf.rb
More file actions
28 lines (23 loc) · 802 Bytes
/
makepdf.rb
File metadata and controls
28 lines (23 loc) · 802 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
class PdfMaker < Middleman::Extension
def after_build(builder)
begin
require 'pdfkit'
kit = PDFKit.new(File.new('build/index.html'),
:page_size => 'A4',
:margin_top => 10,
:margin_bottom => 10,
:margin_left => 10,
:margin_right => 10,
:disable_smart_shrinking => false,
:print_media_type => true,
:dpi => 96
)
file = kit.to_file('build/index.pdf')
rescue Exception =>e
builder.trigger :pdfmaker, "Error: #{e.message}"
raise
end
builder.trigger :pdfmaker, "PDF file available at build/index.pdf"
end
end
::Middleman::Extensions.register(:pdfmaker, PdfMaker)