If I was to take a wild guess, because you've not actually explained the error that you're having on the post (which you should), I'd say it's because you're calling an asynchronous method synchronously. You make a call to:
public static async Task PrintToPdfAsync(string path)
But you don't
this method, so this part:
Will call the method
and then immediately
. You need to await the print method.