Skip to content

Instantly share code, notes, and snippets.

@AgustinParmisano
Last active November 9, 2015 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AgustinParmisano/2066215305755f48b901 to your computer and use it in GitHub Desktop.
Save AgustinParmisano/2066215305755f48b901 to your computer and use it in GitHub Desktop.
from pdfrw import PdfReader, PdfWriter, PageMerge
import StringIO
import os
output = PdfWriter()
marca = "_lf"
for i in os.listdir(os.getcwd()):
if i.endswith(".pdf"):
if (not marca in i) and (not '_backup' in i):
#print i
ipdf = PdfReader(i)
PdfWriter().write('.' + i[:-4] + '_backup' + '.pdf', ipdf)
wpdf = PdfReader("logo.pdf")
wmark = PageMerge().add(wpdf.pages[0])[0]
for page in ipdf.pages:
PageMerge(page).add(wmark).render()
# finally, write "output" to document-output.pdf
PdfWriter().write(i[:-4] + marca + '.pdf', ipdf)
file_path = os.path.join(os.getcwd(), i)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
#elif os.path.isdir(file_path): shutil.rmtree(file_path)
except Exception, e:
print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment