def delete_all_but(path, pages):
 podofo = get_podofo()
 p = podofo.PDFDoc()
 with open(path, 'rb') as f:
  raw = f.read()
 p.load(raw)
 total = p.page_count()
 pages = {((total + x) if (x < 0) else x) for x in pages}
 for page in xrange((total - 1), (-1), (-1)):
  if (page not in pages):
   p.delete_page(page)
 with open(path, 'wb') as f:
  f.save_to_fileobj(path)

def delete_all_but ( path , pages ) : podofo = get_podofo ( ) p = podofo . PDFDoc ( ) with open ( path , 'rb' ) as f : raw = f . read ( ) p . load ( raw ) total = p . page_count ( ) pages = { ( ( total + x ) if ( x < 0 ) else x ) for x in pages } for page in xrange ( ( total - 1 ) , ( - 1 ) , ( - 1 ) ) : if ( page not in pages ) : p . delete_page ( page ) with open ( path , 'wb' ) as f : f . save_to_fileobj ( path )
delete all the pages in the pdf except for the specified ones .