def save(self, filename=None, overwrite=False):
"""
Applies the bates numbers and saves to file.
Args:
filename (str): Path where the PDF should be saved.
overwrite (bool): Switch to allow overwriting of existing files.
Returns:
str: Path where the file was saved.
Raises:
FileExistsError: When the file already exists and overwrite is not enabled.
"""
filename = filename or "{begin}.pdf".format(begin=self.begin)
if os.path.exists(filename) and not overwrite:
raise FileExistsError("PDF file {} already exists and overwrite is disabled.".format(filename))
with open(filename, "wb") as out_file:
writer = PdfFileWriter()
for page in self:
page.apply()
writer.addPage(page.page)
writer.write(out_file)
return filename
评论列表
文章目录