How to save output from GraphViz.jl to pdf?

Hi,

Could someone show an example of printing the output generated from GraphViz.jl to a pdf file? Let’s say just use the example below. Thank you!

dot"""
graph graphname {
     // The label attribute can be used to change the label of a node
     a [label="Foo"];
     // Here, the node shape is changed.
     b [shape=box];
     // These edges both have different line properties
     a -- b -- c [color=blue];
     b -- d [style=dotted];
 }
"""
using GraphViz, FileIO, Cairo
g =
dot"""
graph graphname {
     // The label attribute can be used to change the label of a node
     a [label="Foo"];
     // Here, the node shape is changed.
     b [shape=box];
     // These edges both have different line properties
     a -- b -- c [color=blue];
     b -- d [style=dotted];
 }
"""
FileIO.save("examplegraph.png", g)
FileIO.save("examplegraph.svg", g)

You can either convert the SVG or PNG file to PDF.

1 Like

Thanks for the reply!

I initially thought there would be a way to directly generate a pdf from GraphViz. But, it seems that only SVG and PNG formats are implemented at this moment.

I thought that if the ImageMagick package was installed, one should be able to save the graph directly to a PDF file via the FileIO.save function. But ImageMagick encounters an error in this case. Perhaps it’s worth submitting an issue to either FileIO? (or ImageMagick?)

Yes, I guess I have to bother the package authors to take a look at this aspect.