def do_pdf_pages(filename, options):
    'output is in options.filename + ".pdf-pages.pdf"'
    filename = os.path.realpath(filename)
    tdir = tempfile.mkdtemp('-pdf-pages')
    if options.debug:
        sys.stderr.write('%s: working dir: "%s"\n' % (program_name(), tdir))
    try:
        old_dir = os.getcwd()
        os.chdir(tdir)
        
        # work around for using Unicode filenames in Tex
        os.link(filename, 'input.pdf')

        pdfpages_options = dict( (k, bool_to_latex(v)) 
                for (k, v) in options.__dict__.iteritems())
        pdfpages_options['filename'] = 'input.pdf'
        t = file('pdfpages.tex', 'w')
        t.write(TEMPLATE % pdfpages_options)
        t.close()
        if options.debug:
            sys.stderr.write(TEMPLATE % pdfpages_options)

        run_cmd_quiet(['pdflatex', 'pdfpages.tex'])
        shutil.move('pdfpages.pdf',
                    os.path.join(old_dir,
                    os.path.splitext(os.path.basename(filename))[0] + '-pdf-pages.pdf'))
    finally:
        if not options.debug:
            shutil.rmtree(tdir)
output is in options.filename + ".pdf-pages.pdf"
recipes/Python/496808_pdfpages_Include_only_specified_pages_arrange/recipe-496808.py