Last active
November 9, 2015 18:23
-
-
Save AgustinParmisano/2066215305755f48b901 to your computer and use it in GitHub Desktop.
This file contains 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
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