function to convert buffer to pdf