Font size of pdf as optional argument
The possibility of passing font size (or scaling) of the generated pdf as an option while invoking code2pdf would be a great addition.
Thanks for your suggestion, @cibinjoseph.
Feel free to submit a PR! 🙂
How do I change font-size in the library code? It seems the font size is being defined by Rouge Gem
hey @vaibhavgeek - have a look here: https://github.com/coderhs/code2pdf/blob/f53a2461e8d6102dc207be410f0e3a060fd743b0/lib/code2pdf/convert_to_pdf.rb#L34
It just changes the file path font style. I came up with a hack but the problem is that the code refactoring goes away when one does that.
def pdf
html ||= ''
codestyle = 'font-size: 16px;'
style = 'size: 19px; font-family: Helvetica, sans-serif;'
read_files.each do |file|
html += "<strong style='#{style}'>File: #{file.first}</strong></br></br>"
html += "<code style='#{codestyle}'><pre>" + prepare_line_breaks(file.last).to_s + "</pre></code>"
html += add_space(30)
end
@kit = PDFKit.new(html, page_size: 'A4')
@kit
end
I looked into Rouge Gem but that didn't help much either. Let me know how to work this out, I am looking forward to create a pull request.
It would be better to go for a monospaced font by default because it is code :smile:
I am looking for coloured fonts.
Would colored font make any sense with code in a PDF file? I guess they are for typography design . :laughing:
I know this is an old issue, but for anyone that wants to customize font, colors and other css attributes, the way i did it is to use Rouge legacy formatter and to have a syntax.css file at the root of the project because PDFKit will load it.
To get a sample css file, you can run rougify style base16.light > syntax.css in the root of the project and you will be able to customize that css.
I have attached my /lib/code2pdf/convert_to_pdf.rb file here