![]() ![]() # on dev machine I use Windows so it is no need to emulate X sereve and redefine pathĪlso if you need some extra fonts to support, e. Pdf = pdfkit.PDFKit(content, "string", options= options, configuration=config).to_pdf() join(settings.BASE_DIR, 'wkhtmltopdf_xfaked.sh').encode()) # on production we have no X server, that needed for wkhtmltopdf, so we will emulate it and so we need to use custom path to wkhtmltopdf executableĬonfig = nfiguration(wkhtmltopdf=os.path. Then we need to force pdfkit to use our wkhtmltopdf_xfaked.sh instead of default binary: If you can't or don't want install newer version, but need to run headless on servers where there is no X server, you can easily emulate it with xvfb:Ĭreate file named wkhtmltopdf_xfaked.sh in your Django project base dir - near manage.py (e.g. One drawback of this method is that Versions of wkhtmltopdf < 0.12.2.1 need X server. Solving problem with required X server for version < 0.12.2.1 If you want to add images from your server you can use path to file on server instead web URLs, e.g. If you want style like in example above you need add path to your some_your_style_that_you_need.css into TEMPLATES 'DIRS' setting in settings.py ![]() # change attachment to inline if you want open file in browser tab instead downloading Pdf = pdfkit.PDFKit(content, "string", options= options).to_pdf() pdfkit is a Python library that allows you to convert HTML to PDF using Webkit with wkhtmltopdf. Now, in Django you can create the next view: Restart programs that will run your app (e.g. if you use default install path you have to add c:\Program Files\wkhtmltopdf\bin\. You need to add path to wkhtmltopdf.exe into PATH variable. If you run Ubuntu do: sudo apt-get install wkhtmltopdf Pdfkit uses wkhtmltopdf binary so we also need to install it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |