25 lines
1.0 KiB
Python
Executable File
25 lines
1.0 KiB
Python
Executable File
import argparse
|
|
import fitz # PyMuPDF
|
|
|
|
def remove_text_from_pdf(input_pdf_path, output_pdf_path, watermark):
|
|
doc = fitz.open(input_pdf_path)
|
|
for page in doc:
|
|
text_instances = page.search_for(watermark)
|
|
for text in text_instances:
|
|
print(f'Rect found: {text}')
|
|
page.add_redact_annot(text)
|
|
|
|
page.apply_redactions(fitz.PDF_REDACT_IMAGE_NONE)
|
|
|
|
doc.save(output_pdf_path, garbage=4, deflate=True, deflate_images=True, deflate_fonts=True)
|
|
doc.close()
|
|
print(f"Processed PDF saved as '{output_pdf_path}'.")
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="Remove specified text and links from a PDF.")
|
|
parser.add_argument("input_pdf", help="Path to the source PDF file.")
|
|
parser.add_argument("output_pdf", help="Path to the destination PDF file.")
|
|
parser.add_argument("watermark", help="Text to remove from the output PDF file.")
|
|
args = parser.parse_args()
|
|
remove_text_from_pdf(args.input_pdf, args.output_pdf, args.watermark)
|