"""
Mamangment command used to generate testing pdf.
"""
from django.core.management.base import BaseCommand
from rldjango.apps.binder.utils import generate_single_pdf_brochure
from django.conf import settings

class Command(BaseCommand):
    """
    Mamangment command used to generate section pages images.
    """
    help = "Generate pages images from section for flip book."

    def handle(self, *args, **options):
        """
        document options!
        """
        if not args:
            print 'usage:  generate_pdf DOCUMENTNAME'
            return
        arg = args[0]
        filename = 'output_%s.pdf' % arg
        print 'creating', filename, '...',
        
        data = generate_single_pdf_brochure(
            save_pdf=False, 
            pdf_name=arg,
            )
        _file = open(filename, 'wb')
        _file.write(data)
        _file.close()
        print 'done.'
