Live data from Hacker News

Show HN: Generate high-res images of code samples with Chrome Headless

github.com

1–10 of 92 posts

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#5

Wouldn't it be better as a PDF so that it can be selected? But somehow still retain the color / formatting.

I built this to generate PNGs to drop into a Keynote presentation, so PDFs don't quite work for my use case.

It seems like it should be pretty easy to print a PDF from Puppeteer though – they expose a #pdf method.

https://github.com/GoogleChrome/puppeteer/blob/master/docs/a...

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#6

Nice work. But I'm not looking forward to trying to select text only to drag an image

Thanks! I built this for Keynote presentations specifically. I wanted to be able to write code samples as snippet files, then generate a batch of images I can drop into my presentations.

If you're posting code on a website, you're right – you should prefer

 and prism.js or highlight.js :)

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#7
post #5

Wouldn't it be better as a PDF so that it can be selected? But somehow still retain the color / formatting.

I built this to generate PNGs to drop into a Keynote presentation, so PDFs don't quite work for my use case. It seems like it should be pretty easy to print a PDF from Puppeteer though – they expose a #pdf method. https://github.com/GoogleChrome/puppeteer/blob/master/docs/a...

Just curious why you'd want to use code screenshots vs text in a presentation. Did it have to do with missing fonts or something like that?

Re: Show HN: Generate high-res images of code samples with Chrome Headless

#10

Wouldn't it be better as a PDF so that it can be selected? But somehow still retain the color / formatting.

My workflow:

One time setup

    $ python -m venv ve
    $ source ve/bin/activate
    $ pip install pygments WeasyPrint
Then

    $ pygmentize -f html src.py | weasyprint - out.pdf
Both pygmentize and weasyprint have many options to play with. I find a set and create a shell script.

This also does pngs, etc:

    $ pygmentize -f html src.py | weasyprint - out.png
Post reply on HN