django-wkhtmltopdf: Command returned non-zero exit status 1

I ran this wkhtmltopdf on commandline and it is working fine but in django-wkhtmltopdf it is not working.

Here is my view:

from wkhtmltopdf.views import PDFTemplateView

class PdfView(PDFTemplateView):
    template_name = 'foo.html'

   def get_context_data(self,  **kwargs):
        context = super(PdfView, self).get_context_data(**kwargs)
        context['bar'] = 'asdf'
        return context 

Here is the full traceback

/home/k3/.virtualenvs/pearl/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
                response = response.render() ...
▶ Local vars
/home/k3/.virtualenvs/pearl/local/lib/python2.7/site-packages/django/template/response.py in render
            self.content = self.rendered_content ...
▶ Local vars
/home/k3/.virtualenvs/pearl/local/lib/python2.7/site-packages/wkhtmltopdf/views.py in rendered_content
                    prefix='wkhtmltopdf', suffix='.html',
                    delete=(not debug)
                )
                footer_filename = footer_file.name
            return self.convert_to_pdf(filename=input_file.name,
                                       header_filename=header_filename,
                                       footer_filename=footer_filename) ...
        finally:
            # Clean up temporary files
            for f in filter(None, (input_file, header_file, footer_file)):
                f.close()
▶ Local vars
/home/k3/.virtualenvs/pearl/local/lib/python2.7/site-packages/wkhtmltopdf/views.py in convert_to_pdf
        # Clobber header_html and footer_html only if filenames are
        # provided. These keys may be in self.cmd_options as hardcoded
        # static files.
        if header_filename is not None:
            cmd_options['header_html'] = header_filename
        if footer_filename is not None:
            cmd_options['footer_html'] = footer_filename
        return wkhtmltopdf(pages=[filename], **cmd_options) ...
    @property
    def rendered_content(self):
        """Returns the freshly rendered content for the template and context
        described by the PDFResponse.
▶ Local vars
/home/k3/.virtualenvs/pearl/local/lib/python2.7/site-packages/wkhtmltopdf/utils.py in wkhtmltopdf
    ck_args = list(chain(cmd.split(),
                         _options_to_args(**options),
                         list(pages),
                         [output]))
    ck_kwargs = {'env': env}
    if hasattr(sys.stderr, 'fileno'):
        ck_kwargs['stderr'] = sys.stderr
    return check_output(ck_args, **ck_kwargs) ...
def content_disposition_filename(filename):
    """
    Sanitize a file name to be used in the Content-Disposition HTTP
    header.
▶ Local vars
/usr/lib/python2.7/subprocess.py in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
    output, unused_err = process.communicate()
    retcode = process.poll()
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = popenargs[0]
        raise CalledProcessError(retcode, cmd, output=output) ...
    return output
def list2cmdline(seq):
    """
    Translate a sequence of arguments into a command line
▶ Local vars

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 24 (11 by maintainers)

Most upvoted comments

Solution.

You MUST specify a ‘STATIC_ROOT’ in settings.py. It must be different from STATIC_DIRS.

Then, you have to run: python manage.py collectstatic

Hope this helps.

@meshy It seems that the css files which are external, wkhtmltopdf is not able to generate the pdf.

@ChillarAnand have you solved the issue? I am getting the same error.