1

I need to convert a HTML URL to pdf format using wkhtmltopdf tool on terminal.

 $ wkhtmltopdf --username 'arya_normal2' --password '1' http://localhost:8000/employee/arya_normal2-no-emp-code/certificates/53/show/   localhost.pdf

Its not getting authenticated/logined when hitting url. Its giving simple login pdf page.

I have checked with my google account , its showing login page in pdf.

Have anyone used username and password in wkhtmltopdf? Help me if I have given wrong command line arguments.

EDIT:

Modified command line Arguments :

  wkhtmltopdf --cookie 'csrftoken' 'JuQUFr9KLUdZLMAjLn3d8yakd6HOshTN' --cookie  'sessionid'  'xy3yacbe3nq1sbbtstkxfp34ah3imcmg'  --post username 'arya_normal2' --post password '1' http://localhost:8000/employee/arya_normal2-no-emp-code/certificates/all/   sample2.pdf

Now following error is coming :

Internal Server Error: /employee/arya_normal2-no-emp-code/certificates/all/
Traceback (most recent call last):
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 107, in get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/middleware/csrf.py", line 170, in process_view
    request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 146, in _get_post
    self._load_post_and_files()
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/http/request.py", line 219, in _load_post_and_files
    self._post, self._files = self.parse_file_upload(self.META, data)
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/http/request.py", line 183, in parse_file_upload
    parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding)
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 70, in __init__
    raise MultiPartParserError('Invalid boundary in multipart: %s' % boundary)
MultiPartParserError: Invalid boundary in multipart: None

Login form :

<form action="" method="post" enctype="multipart/form-data"  boundary=0xKhTmLbOuNdArY>
         {% csrf_token %}

         <input name="username" type="text" placeholder="Email-address" id="email"><br>
         <input name="password" type="password" placeholder="Password" id="password"><br>
         <input type="checkbox" id="remember" value="Remember Me" >&nbsp; <span>Remember Me</span>
         <a id="forget">Forgot your Password?</a><br>
           {% if error %}
          <i class="icon-warning"></i><span class="error">The username or password you entered is incorrect.</span>
         {% endif %}
         <input type="submit" value="LOGIN" id="login">
     </form>
Anil Arya
  • 3,100
  • 7
  • 43
  • 69

1 Answers1

0

The correct syntax for the --post parameters are --post username user_name_value --post password password_value

in your login form, try to change to id="username" instead of id="email"

username and password are both the id and the name of the input fields on the form

hope it helps!

see: Generate PDF Behind Authentication Wall

Community
  • 1
  • 1