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
|
# File 'lib/riven/wkhtmltopdf.rb', line 13
public def generate_pdf(html_file, cover_html_file, output_file, options)
params = [
'--page-size A4',
'--margin-bottom 20mm',
'--margin-top 20mm',
'--margin-left 30mm',
'--margin-right 30mm',
'--footer-left "[section]"',
'--footer-right "[page] / [toPage]"',
'--footer-font-size 7',
'--footer-spacing 10'
]
unless options[:cover_file] === ''
params << "cover \"#{cover_html_file.file_name}\""
end
if options[:toc]
xsl = File.read(File.expand_path(File.dirname(__FILE__)) + '/../../toc.xsl')
xsl.gsub! '[[toc_headline]]', options[:toc_headline]
xsl_file_name = '_tmp_toc.xsl'
File.open(xsl_file_name, 'w') { |file| file.write(xsl) }
params << 'toc'
params << "--xsl-style-sheet \"#{xsl_file_name}\""
end
output = `wkhtmltopdf #{params.join(' ')} "#{html_file.file_name}" "#{output_file}" 2>&1`
File.delete xsl_file_name
return output
end
|