Supposing I have a diagram like the one in this example that displays a flowchart

How do I add code to send this diagram to the printer and print out only this diagram?

First, for an introduction to printing, please read

Second, you’ll notice that the SVG that is generated in that sample, by the “Render as SVG” button, can also be printed by the user. The SVG is vector-based, so it should print without any of the problems that a screen resolution PNG image would have when printed.

Ok, thanks!

Is there a way to add a print button rather than to right click on the SVG and select the print option from the browser’s context menu?

Yes, I believe so – I suggest you search the web for how to do that and how to control what is printed, since it is not specific to GoJS.