Skip to content

Instantly share code, notes, and snippets.

@roboyoshi
Created January 22, 2018 16:28
Show Gist options
  • Save roboyoshi/8d7ab7061d9b48b71d44b3b27f018823 to your computer and use it in GitHub Desktop.
Save roboyoshi/8d7ab7061d9b48b71d44b3b27f018823 to your computer and use it in GitHub Desktop.
remove watermark from wowebooks (fuck those guys)
import os
from PyPDF2 import PdfFileReader, PdfFileWriter
from PyPDF2.generic import NameObject, NullObject
"""
This Script overwrites the Watermark which is embedded as a Form on each page with a NullObject
Requires PyPDF2 (> python -m pip install pypdf2)
"""
def remove_wow_watermark(inputFile):
fileName, fileExt = os.path.splitext(inputFile)
outFile = fileName + '.strip' + fileExt
source = PdfFileReader(open(inputFile, "rb"))
output = PdfFileWriter()
# For each page
for i in range(source.getNumPages()):
# Get the current page and it's contents
# Path = /Page/Resources/XObject/Fm0 => Stream
page = source.getPage(i)
page_resources_obj = page['/Resources'].getObject()
page_resources_xobject_obj = page_resources_obj['/XObject'].getObject()
page_resources_xobject_obj.__setitem__(NameObject('/Fm0'), NullObject())
page.__setitem__(NameObject('/Resources'), page_resources_obj)
output.addPage(page)
outputStream = open(outFile, "wb")
output.write(outputStream)
# Put your file here and execute the script in the directory with the book.
remove_wow_watermark('watermarked.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment