一文掌握Python建立 PDF 编辑器

360影视 2025-01-26 08:38 2

摘要:from pypdf import PdfReader, PdfWriter# rotate pdf filereader = PdfReader("dummy.pdf")page = reader.pages[0]page.rotate(270)writer

from pypdf import PdfReader, PdfWriter# rotate pdf filereader = PdfReader("dummy.pdf")page = reader.pages[0]page.rotate(270)writer = PdfWriterwriter.add_page(page)writer.write('tilt.pdf')# run python3 pdf_merger.py dummy.pdf twopage.pdf wtr.pdfimport sysfrom pypdf import PdfWriterinputs = sys.argv[1:]# merge pdf filesdef pdf_merger(pdf_list): merger = PdfWriter for pdf in pdf_list: merger.append(pdf) merger.write("merged-pdf.pdf") merger.closepdf_merger(inputs)from pypdf import PdfWriter, PdfReaderwatermark = PdfReader("wtr.pdf").pages[0]writer = PdfWriter(clone_from="twopage.pdf")for page in writer.pages: page.merge_page(watermark, over=False) # here set to False for watermarkingwriter.write("add_watermark.pdf")import sysfrom pypdf import PdfReader, PdfWriter# run python3 pdf_add_watermark.py # run python3 pdf_remove_watermark.py add_watermark.pdforiginal_pdf = sys.argv[1]with open(original_pdf, "rb") as input_file, open('remove_watermark.pdf', "wb") as output_file: reader = PdfReader(input_file) writer = PdfWriter for n in range(len(reader.pages)): page = reader.pages[n] del page["/Contents"][0] writer.add_page(page) writer.write(output_file)

来源:自由坦荡的湖泊AI

相关推荐