Search code examples
pythonpdfsvgvtk

How can I export a VTK screenshot to a PDF or a vectorized image?


I wrote a python script to render a VTK object and save its figure as PNG using the vtkPNGWriter() functions. Is there a way to save it as a PDF or a svg file?


Solution

  • It is possible to export a PDF image of the render window using the function vtk.vtkGL2PSExporter(). Here a working snippet of code:

    pdfExporter = vtk.vtkGL2PSExporter()
    pdfExporter.SetRenderWindow(render_window)
    
    
    outputFilename = "file_name"
    
    pdfExporter.SetFileFormatToPDF()  #save as pdf
    pdfExporter.SetFilePrefix(outputFilename)
    pdfExporter.Write()