3

I'm looking for a tool to display code examples in PDF file. I mean that I would like to colorize and indent code in my PDF (it's for lessons).

I'm not able to find anything on the web or on StackOverflow. It's full of tutorials to use code to make PDF but not to display code in PDF. When I search for 'display' it gives me how to display PDF in web/applications.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
Spoke44
  • 968
  • 10
  • 24
  • Well how are you creating PDF? From word? From html? – Bogdan Kuštan Jan 12 '15 at 14:42
  • The top should be using word. The problem is copy/paste code works but it's horrible to maintain. I don't know very well Latex, is it a solution ? – Spoke44 Jan 12 '15 at 14:51
  • 1
    I'd use something like GeSHi to create colored code versions in HTML and then use a tool to convert HTML into PDF to make the PDF. However: this question is off-topic on StackOverflow as you are asking people to recommend a tool. – Bruno Lowagie Jan 12 '15 at 15:07
  • 1
    On second thought: this is not related to the output format "PDF"! You should be looking for a solution in Word. Try [Super User](http://superuser.com/) or alternatively [graphicsdesign.se]. – Jongware Jan 12 '15 at 15:17
  • Ok thanks to you for your replies. I was still searching and I found :http://stackoverflow.com/questions/387453/how-do-you-display-code-snippets-in-ms-word-preserving-format-and-syntax-highlig – Spoke44 Jan 12 '15 at 15:40
  • That thread contains some excellent tips ... So thank you back for finding it! – Jongware Jan 12 '15 at 15:56
  • @BrunoLowagie: Well, the OP is not directly asking for a tool recommendation. But, since there is now way to colorize and indent code in a PDF (once it is created), the only useful answer is to recommend a tool or toolchain that supports for the source, pre-PDF document stage what the OP wants... – Kurt Pfeifle Jan 12 '15 at 17:20

1 Answers1

2

Sorry to disappoint you, but:

  • There is no such thing as you are looking for!

If you want code samples on a PDF page to be syntax highlighted, you must look for a tool that does do this within the source document which was used to generate the PDF file from.

There is no tool in the world, neither Free and Open Source Software, nor commercial payware, that lets you edit a PDF and convert the source samples on its pages into properly syntax highlighted parts. (The only thing you can possibly do on this level is adding specific comments -- here you have to manually highlight specific words or sentences with a background color of your choice.)

If you are looking for a toolchain that makes it easy to generate PDFs from scratch containing syntax-highlighted code samples, look at:

  • Markdown: a very lean text markup language to write the document in (use any text editor you like)

  • Pandoc: a powerfull Markdown-to-Anything converter. It's a command line tool available for all major OS platforms. Its output may be PDF, HTML, EPUB, LaTeX (all of the previous with syntax highlighting), as well as ODT, DOCX, DocBook (no syntax highlighting supported so far for the last few) and a few more...

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345