Skip to content

Instantly share code, notes, and snippets.

@notyal
Last active January 26, 2023 02:07
Show Gist options
  • Save notyal/69242672f180e4cc774c3509bfbf904d to your computer and use it in GitHub Desktop.
Save notyal/69242672f180e4cc774c3509bfbf904d to your computer and use it in GitHub Desktop.
Remove annoying popup messages on VW PDFs downloaded from erWin
#!/usr/bin/env python
def remove_popups(filename) -> None:
with open(filename, 'rb') as fb:
s = fb.read()
fb.close()
s = s.replace(b'showUSAPopup=true', b'showUSAPopup=0;;;')
s = s.replace(b'showPopup=true', b'showPopup=0;;;')
s = s.replace(b'showUSAPopup', b'nonoUSAPopup')
with open(filename, 'wb') as fb:
fb.write(s)
fb.close()
del s
def usage() -> None:
print(f"Usage: {sys.argv[0]} [directory]")
print("\t[directory] is the directory containing PDFs with popup message to be removed.")
if __name__ == "__main__":
import os
import sys
if len(sys.argv) != 2:
usage()
exit(1)
if not os.path.isdir(sys.argv[1]):
print(f"Error: Invalid directory provided: '{sys.argv[1]}'")
exit(1)
for root, dirs, files in os.walk(sys.argv[1]):
print(f"[{root}]")
for file in files:
if file.endswith(".pdf"):
print(f"\t{file}")
remove_popups(os.path.join(root, file))
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment