How can I print a sketch with coloured keywords?

Sketches are displayed in the Arduino app with coloured key words. When I choose File>print the printout is black and white. I tried "copy for forum" and pasted it into a TextEdit (Macintosh) but it did not retain the coloured text. How can I print a sketch with coloured keywords?

Did you try the print option from the IDE instead?

You probably can't. I based this on trying File|Print, directed to a PDF, with colour printing selected. No dice, black and white only.
C

Screen shot and print as a picture. Or more labour intensive would be to use the find function in your word processor and change all to a coloured text.

Initially I chose "Print" from the Arduino File menu. When that produced a B&W print I tried opening with another text editor but got the same results. I have a little programming experience with "Real Studio" where B&W or Colour printing of code were options found under the apps Preferences item.
I didn't see that option in the Arduino Preferences. I am trying to understand the Sketch syntax and coloured prints would be a great help. Any suggestions would be gratefully appreciated.

Unfortunately, colouring it yourself, in something like a word processor, seems to be it. Since it won't print, and any form of export(e.g. copy, paste) is plain text, you're pretty toasted. I expect what's happening is that the colour of the text is assigned by the IDE at display time based on keywords, so the colour attribute isn't present in the .ino file. Accordingly, the only thing that could carry over the colour is the printing process, and it clearly isn't. But I could be wrong, I just don't think so.

if you right click in the code window in the IDE, you can "copy as HTML"
(here in French in my IDE)

then open a text document, paste the HTML and save as code.htm
it should print or save as PDF with the colors

2 Likes

That's the winner.
Works on Windows.


Save the copied HTML to a file, open in browser, and print.

This looks promising. After you copied as HTML did you paste it into a text editor and saved it as PDF? Or did you print as PDF? I saved as pdf after pasting into a text editor. I then opened the pdf in my browser which displayed only the HTML text.

Save it as an html file
Open the html file in a browser
Print from the browser

As yet I can't find a way to save as HTML but I now know how to solve the problem.
Many thanks to all.

Copy it into a text editor and save it as an html file

Bit of a sledgehammer job but … get a download of visual studio and cut and paste your code into a new project , print from that and will be coloured in

Not so obvious on a Mac but can be solved with TextEdit. Here is the Mac solution.

  1. In TextEdit create a blank plain text page (File>New)
  2. In Arduino copy sketch as HTML (Right click on the sketch)
  3. Paste the HTML sketch into the blank TextEdit window
  4. Save the file as plain text
  5. In finder change the file type from .txt to .html
  6. Open the .html file from Safari
  7. Print the page from Safari.
    Thanks to J-M-L and Er Name Not Found , I was able to print a Sketch with coloured Keywords.

Text editor Notepad++ can do this.

2 Likes

I love Notepad++, but I don't think it's available for mac.

Open new file in TextEdit, press cmd SHIFT ⇧t To make it plain text.
Paste the html
Save as code.htm directly to have the right extension /file type and close that window
Reopen that file so that it’s interpreted as HTML (TextEdit knows how to display the HTML, you don't need Safari although the double click will open Safari)
Then you can print or save as PDF

Use Arduino Code Highlighter => Copy to MS Word or Powerpoint => PDF

Thanks J-M-L for the correction. I couldn't stop TextEdit from adding .txt after saving as .html. I now see that I should have saved as .htm.
Copy to MS Word or PowerPoint is better but I don't have those apps.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.