Search code examples
visual-studio-codeintellij-ideapdf-generationsyntax-highlighting

how to export to pdf with syntax highlighting?


I need an extension in intellij or vscode or some app to transform my codes into pdf.

I tried to use the app notion but it doesn't export with syntax highlighting.

*Edit: I know it seems to have a very easy answer, but I was thinking exclusively about Intellij Community. I have to export my code into a legible PDF with syntax highlights without having to leave the IDEA. The current way to achieve exactly what I want is to copy the code in Intellij, paste it into Visual Studio Code (to get the syntax right), copy it again and paste it into Google Docs to change the background color (since I prefer to code in darker colors and want this in the PDF as well), and then save as a PDF.

This is a lot of steps for a simple task. The closest I can get is using Notion, where I can paste and copy the code into a Notion file (in the code area using markdown), and then simply save the file as a PDF. However, the syntax highlighting is ignored when exported to PDF.


Solution

  • IntelliJ IDEA doesn't have settings for printing PDFs directly, but you can try the following solutions:

    • Use File | Export | File or Selection to HTML to export code to an HTML file. Open this file in a browser, and use the print feature in the browser to print a pdf.

    • Install software that emulates printer in your system and creates PDF as output and run File | Print action from the IDE.