code2pdf icon indicating copy to clipboard operation
code2pdf copied to clipboard

Font size of pdf as optional argument

Open cibinjoseph opened this issue 6 years ago • 8 comments

The possibility of passing font size (or scaling) of the generated pdf as an option while invoking code2pdf would be a great addition.

cibinjoseph avatar Jan 28 '18 09:01 cibinjoseph

Thanks for your suggestion, @cibinjoseph.

Feel free to submit a PR! 🙂

lucascaton avatar Jan 28 '18 09:01 lucascaton

How do I change font-size in the library code? It seems the font size is being defined by Rouge Gem

vaibhavgeek avatar Oct 01 '18 12:10 vaibhavgeek

hey @vaibhavgeek - have a look here: https://github.com/coderhs/code2pdf/blob/f53a2461e8d6102dc207be410f0e3a060fd743b0/lib/code2pdf/convert_to_pdf.rb#L34

lucascaton avatar Oct 03 '18 22:10 lucascaton

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.

vaibhavgeek avatar Oct 04 '18 11:10 vaibhavgeek

It would be better to go for a monospaced font by default because it is code :smile:

biwin avatar Oct 15 '18 05:10 biwin

I am looking for coloured fonts.

vaibhavgeek avatar Oct 15 '18 11:10 vaibhavgeek

Would colored font make any sense with code in a PDF file? I guess they are for typography design . :laughing:

biwin avatar Oct 15 '18 18:10 biwin

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

juanyunis avatar Mar 31 '20 20:03 juanyunis