- if output_dir is not None:
- try:
- os.makedirs(output_dir)
- except OSError:
- pass
- if slug:
- output_path = os.path.join(output_dir, '%s.pdf' % slug)
- else:
- output_path = os.path.join(output_dir, os.path.splitext(os.path.basename(file_path))[0] + '.pdf')
- shutil.move(pdf_path, output_path)
- else:
- if hasattr(output_file, 'write'):
- # file-like object
- with open(pdf_path) as f:
- output_file.write(f.read())
- output_file.close()
- else:
- # path to output file
- shutil.copy(pdf_path, output_file)