<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def convertToPDF(self, from_page=0, to_page=-1, rotate=0):
 """Convert document to PDF selecting page range and optional rotation. Output bytes object."""

        if self.isClosed or self.isEncrypted:
            raise ValueError("operation illegal for closed / encrypted doc")

        return _fitz.Document_convertToPDF(self, from_page, to_page, rotate)