python-删除PDF空白页
from PyPDF4 import PdfFileReader, PdfFileWriter,PdfFileMerger def delPdfPage(self,pdf_file_path): ''' 删除pdf 空白页 ''' pdf_file_path = os.path.join(self.pdf_dir, pdf_file_path) logger.info("path = {},pdf删除空白页开始时刻:{}".format(pdf_file_path, str(datetime.now()))) pdf_name = random_name(12) + "_" + datetime.now().strftime("%Y%m%d%H%M%S%f")+".pdf" path_output = get_pdf_file_path(pdf_name) reader = PdfFileReader(open(pdf_file_path, 'rb')) writer = PdfFileWriter() pages = reader.getNumPages() for i in range(pages): page = reader.getPage(i) text = page.extractText() if text: writer.addPage(page) writer.write(open(path_output, 'wb')) logger.info("path = {},pdf删除空白页结束时刻:{}".format(pdf_file_path, str(datetime.now()))) return pdf_name