Package: nightmare_pdf
django-nightmare-pdfConvert HTML to pdf with django using nightmareRequirementsPython (2.7) (Need to be tested for 3.x)Django (1.10, 1.9) (Need to be tested for previous versions)DependenciesThis django app depends onNightmare, you need to
first install it usingnpm:npm install nightmareInstallationInstall usingpip:pip install nightmare_pdfAddnightmare_pdfto your INSTALLED_APPS setting.INSTALLED_APPS = (
    ...
    'nightmare_pdf',
)create a directory to hold pdf files created by Nightmare, default topdf_temp:mkdir pdf_tempExampleGenerate a pdf from an url and save it to database, or retrieve it as a
ContentFile, or return it inside an HttpResponse :from nightmare_pdf.generators import PDFGenerator

pdf = PDFGenerator(url="https://github.com/charlesthk/django-nightmare-pdf",

# Save it to database and retrieve a PdfDoc Object (database):
pdf.save(
        filename='nightmare_pdf',
        title="nightmare_pdf on github",
        description="Convert HTML to pdf with django using nightmare")

# Get the PDf as a Django ContentFile named 'my_pdf_file.pdf' :
pdf_content_file = pdf.get_content_file('my_pdf_file')

# Return a Django HttpResponse with the PDF Attached named 'my_pdf_file.pdf':
return pdf.get_http_response('my_pdf_file')PDFGeneratoroptionsThePDFGeneratorclass accepts the following arguments :url [required]timeout [Optional] default to 1000, defines the timeout between the
opening and the rendering of the url by nightmarepage_size [Optional] default to ‘A4’, accepts options are A3, A4,
A5, Legal, Letter or Tabloidlandscape [Optional] default to 0, defines whether rendering pdf in
landscape modeprint_background [Optional] default to 1, defines whether printing
backgroundmargins_type [Optional] default to 1, defines which margins to use.
Uses 0 for default margin, 1 for no margin, and 2 for minimum margin.script [Optional] default to DEFAULT_RENDER_SCRIPT, defines which
render script to use.temp_dir [Optional] default to DEFAULT_TEMP_DIR, defines which
temp dir to use.Model use for saving PDFWhen usingsave(filename,title='',description='')method ofPDFGenerator, the following model is used:class PdfDoc(models.Model):
    """
    Store each generated pdf
    """
    title = models.CharField(verbose_name=_("Title"), max_length=255, blank=True)
    description = models.TextField(verbose_name=_("Description"), blank=True)
    document = models.FileField(verbose_name=_("Document PDF"), upload_to=pdf_settings.UPLOAD_TO)
    created_at = models.DateTimeField(auto_now=False, auto_now_add=True, verbose_name=_('Creation'))
    updated_at = models.DateTimeField(auto_now=True, auto_now_add=False, verbose_name=_('Update'))SettingsAdd your settings to your main django settings file. The settings are
set by default to :NIGHTMARE_PDF = {
    'UPLOAD_TO': 'pdfs',
    'NODE_PATH': 'node',
    'DEFAULT_RENDER_SCRIPT': os.path.join(NIGHTMARE_PDF_DIR, 'render_pdf.js'),
    'DEFAULT_TEMP_DIR': os.path.join(settings.BASE_DIR, 'pdf_temp')
}UPLOAD_TODefine the directory or the function to be used when saving PDFs,
default topdfs.NODE_PATHDefine the path to Node binary, default tonode.DEFAULT_RENDER_SCRIPTDefine which render_script to use by default, default torender_pdf.jsinside the package.DEFAULT_TEMP_DIRDefine the directory to use for temporarily generated pdf by Nightmare.
default topdf_temp.SupportIf you are having issues, please let us know or submit a pull request.LicenseThe project is licensed under the MIT License.