import os
from PyPDF2 import PdfFileReader, PdfFileWriter
for i in os.listdir(os.getcwd()):
if 'ps2pdf' in i:
continue
if 'ps' in i:
os.system("pstopdf "+i)
pdffile = i.split('.ps', 1)[0]+".pdf"
print (pdffile)
pdf_writer = PdfFileWriter()
with open(pdffile, 'rb') as fh:
pdf_reader = PdfFileReader(fh)
print(pdf_reader.getNumPages())
page = pdf_reader.getPage(0).rotateClockwise(90)
pdf_writer.addPage(page)
with open("rotate_"+pdffile, 'wb') as f:
pdf_writer.write(f)