how to export to pdf with syntax highlighting?
Asked Answered
H

4

8

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.

Homonym answered 12/11, 2022 at 22:26 Comment(2)
convert your code to an HTML page with a pre tag and add a JavaScript based syntax highlighter, convert (print) this page with a browser to pdfEclampsia
What are some recommended syntax highlighters?Mood
J
2

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.

Jordan answered 14/11, 2022 at 7:19 Comment(2)
Well, it works. Its not very functional when you have a lot of files and it's not exactly what i was looking for, but i think that what i want doesn't really exists, but yeah, thank you!Homonym
I don't see File > Export on 1.85.0-insider on cpe:/o:opensuse:tumbleweed:20231130.Hypsometry
O
11

1. Install extension with name Print

Extension Id : pdconsec.vscode-print

Visual Studio Extension Link

2. Create HTML in Browser

View -> Command Pallete -> Print

3. Print as PDF from Browser

Ormazd answered 16/12, 2022 at 12:20 Comment(1)
Doesthis still work? I'm getting this error in the browser when I try to print a python notebook TypeError: Cannot read properties of undefined (reading 'build') Cecilius
J
2

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.

Jordan answered 14/11, 2022 at 7:19 Comment(2)
Well, it works. Its not very functional when you have a lot of files and it's not exactly what i was looking for, but i think that what i want doesn't really exists, but yeah, thank you!Homonym
I don't see File > Export on 1.85.0-insider on cpe:/o:opensuse:tumbleweed:20231130.Hypsometry
W
2

I recently created a VSCode extension that allows you to export source code as HTML with syntax highlighting.
This extension also has the ability to export PDFs and images, so if you are interested, please see the following pages.

https://marketplace.visualstudio.com/items?itemName=Aniny.codetohtml
https://github.com/Aniny21/CodeToHTML

Warfarin answered 15/2, 2024 at 18:48 Comment(0)
B
0

View > Command Palette (Ctrl + Shift + P) > Export to PDF

This will export the whole file as PDF (Note: You will need to have installed 'xelatex' or just export as HTML and print to PDF using the your browser).

Bacchus answered 10/9, 2024 at 8:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.