To save a file in a given format, you need to specify the format as parameter
canvas->Print("filename.pdf","pdf");