Last active
March 8, 2021 18:57
-
-
Save Romern/71f7ee987ab03a6dc3497045b8f1fd51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pikepdf | |
import sys | |
if len(sys.argv)<3: | |
print(f"Usage {sys.argv[0]} input.pdf output.pdf") | |
exit(1) | |
input = sys.argv[1] | |
output = sys.argv[2] | |
""" | |
StudyDrive Logo: | |
<pikepdf.Stream(stream_dict={ | |
"/BitsPerComponent": 8, | |
"/ColorSpace": "/DeviceRGB", | |
"/DecodeParms": { | |
"/BitsPerComponent": 8, | |
"/Colors": 3, | |
"/Columns": 816, | |
"/Predictor": 15 | |
}, | |
"/Filter": "/FlateDecode", | |
"/Height": 107, | |
"/Length": 16330, | |
"/SMask": pikepdf.Stream(stream_dict={ | |
"/BitsPerComponent": 8, | |
"/ColorSpace": "/DeviceGray", | |
"/DecodeParms": { | |
"/BitsPerComponent": 8, | |
"/Colors": 1, | |
"/Columns": 816, | |
"/Predictor": 15 | |
}, | |
"/Filter": "/FlateDecode", | |
"/Height": 107, | |
"/Length": 6233, | |
"/Subtype": "/Image", | |
"/Type": "/XObject", | |
"/Width": 816 | |
}, data=<...>), | |
"/Subtype": "/Image", | |
"/Type": "/XObject", | |
"/Width": 816 | |
}, data=<...>)> | |
Annotation: | |
/A: | |
pikepdf.Dictionary({ | |
"/S": "/URI", | |
"/URI": "https://www.studydrive.net/de?utm_source=Document&utm_medium=Watermark&utm_campaign=Watermark_DE" | |
}) | |
""" | |
pdf = pikepdf.open(input) | |
for p in pdf.pages: | |
study_drive_logo = [key for (key,i) in p.get("/Resources",dict()).get("/XObject",dict()).items() if i.get("/Height") == 107 and i.get("/Length") == 16330 ] | |
if study_drive_logo: | |
del p["/Resources"]["/XObject"][study_drive_logo[0]] | |
study_drive_anno = [i for i, val in enumerate(p.get("/Annots",[])) if "https://www.studydrive.net/de?utm_source=Document&utm_medium=Watermark" in str(val.get("/A",dict()).get("/URI"))] | |
if study_drive_anno: | |
del p["/Annots"][study_drive_anno[0]] | |
pdf.save(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment