<s> '''<STR_LIT>''' <EOL> import sys <EOL> import os <EOL> from reportlab . pdfgen . canvas import Canvas <EOL> from pdfrw import PdfReader <EOL> from pdfrw . buildxobj import pagexobj <EOL> from pdfrw . toreportlab import makerl <EOL> def read_and_double ( inpfn ) : <EOL> pages = PdfReader ( inpfn ) . pages <EOL> pages = [ pagexobj ( x ) for x in pages ] <EOL> if len ( pages ) & <NUM_LIT:1> : <EOL> pages . append ( pages [ <NUM_LIT:0> ] ) <EOL> xobjs = [ ] <EOL> while len ( pages ) > <NUM_LIT:2> : <EOL> xobjs . append ( ( pages . pop ( ) , pages . pop ( <NUM_LIT:0> ) ) ) <EOL> xobjs . append ( ( pages . pop ( <NUM_LIT:0> ) , pages . pop ( ) ) ) <EOL> xobjs += [ ( x , ) for x in pages ] <EOL> return xobjs <EOL> def make_pdf ( outfn , xobjpairs ) : <EOL> canvas = Canvas ( outfn ) <EOL> for xobjlist in xobjpairs : <EOL> x = y = <NUM_LIT:0> <EOL> for xobj in xobjlist : <EOL> x += xobj . BBox [ <NUM_LIT:2> ] <EOL> y = max ( y , xobj . BBox [ <NUM_LIT:3> ] ) <EOL> canvas . setPageSize ( ( x , y ) ) <EOL> if len ( xobjlist ) > <NUM_LIT:1> and xobjlist [ <NUM_LIT:0> ] == xobjlist [ - <NUM_LIT:1> ] : <EOL> xobjlist = xobjlist [ : <NUM_LIT:1> ] <EOL> x = xobjlist [ <NUM_LIT:0> ] . BBox [ <NUM_LIT:2> ] <EOL> else : <EOL> x = <NUM_LIT:0> <EOL> y = <NUM_LIT:0> <EOL> for xobj in xobjlist : <EOL> canvas . saveState ( ) <EOL> canvas . translate ( x , y ) <EOL> canvas . doForm ( makerl ( canvas , xobj ) ) <EOL> canvas . restoreState ( ) <EOL> x += xobj . BBox [ <NUM_LIT:2> ] <EOL> canvas . showPage ( ) <EOL> canvas . save ( ) <EOL> inpfn , = sys . argv [ <NUM_LIT:1> : ] <EOL> outfn = '<STR_LIT>' + os . path . basename ( inpfn ) <EOL> make_pdf ( outfn , read_and_double ( inpfn ) ) </s>
