从html转换为pdf的页码 - pdfkit,python/django

Vin*_*yak 5 html python django render pdfkit

我正在使用pdfkit和python/django将渲染的html转换为pdf.如何在pdf liike第1页中添加页码.我将html转换为字符串,然后将其传递给pdfkit的from_string方法.

小智 12

添加到上面的anwser

  options = { 
      'margin-bottom': '0.75in', 
      'footer-right': '[page] of [topage]',
     }  
pdfkit.from_string('Hello World', 'out.pdf', options=options)
Run Code Online (Sandbox Code Playgroud)

会给出输出 1 of 2

以下是可以替代的其他变量.

  • [页面]替换为当前正在打印的页数
  • [frompage]替换为要打印的第一页的编号
  • [topage]替换为要打印的最后一页的编号
  • [网页]替换为正在打印的页面的URL
  • [section]替换为当前部分的名称
  • [subsection]替换为当前小节的名称
  • [date]以系统本地格式替换为当前日期
  • [时间]以系统本地格式替换当前时间

参考.链接文档.这里


Woo*_*dsy 10

添加options应允许创建页码,如下所示:

options = {
   'margin-bottom': '0.75in',
   'footer-right': '[page]'
   }
pdfkit.from_string('Hello World', 'out.pdf', options=options)
Run Code Online (Sandbox Code Playgroud)

根据PDFKit的文档,您可以使用所有wkhtmltopdf的选项