2017-08-03 29 views
0

背景信息

我有以下我想用来生成PDF文件的Python代码。它使用pdfkit library如何使用python中的pdfkit库在页脚上方显示页脚行?

import pdfkit    # import python module 

if __name__=="__main__": 


    options = { 
     'page-size': 'Letter', 
     'margin-top': '0.5in', 
     'margin-right': '0.75in', 
     'margin-bottom': '0.5in', 
     'margin-left': '0.75in', 
     'encoding': "UTF-8", 
     'footer-left': "This is a footer", 
     'footer-font-size':'7', 
     'footer-right': '[page] of [topage]', 

     'custom-header' : [ 
      ('Accept-Encoding', 'gzip') 
     ], 
     'no-outline': None 
    } 

    ##this is the path of the whkhtmltopdf.exe in order for the library to 
    ##work on a Windows OS 
    path_wkthmltopdf = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe' 
    config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf) 

    pdfkit.from_url('http://google.com', 'Report.pdf',options=options,configuration=config)) 

产生的PDF如下。我所需要的只是一条线以上的是一个页脚。 The Resulting PDF

根据以下站点,我可以使用属性footer-line添加一个页脚行页脚之上,但我不理解如何实现它在Python

https://wkhtmltopdf.org/usage/wkhtmltopdf.txt

语法

简要

问题如何修改options属性包括:footer-line

options = { 
     'page-size': 'Letter', 
     'margin-top': '0.5in', 
     'margin-right': '0.75in', 
     'margin-bottom': '0.5in', 
     'margin-left': '0.75in', 
     'encoding': "UTF-8", 
     'footer-left': "This is a footer", 
     'footer-font-size':'7', 
     'footer-right': '[page] of [topage]', 

     'custom-header' : [ 
      ('Accept-Encoding', 'gzip') 
     ], 
     'no-outline': None 
    } 

回答

0

显然,你只需要添加的属性,并传递一个空参数

所以对options属性,你只需要添加'footer-line':'' 所以它成为以下

 options = { 
     'page-size': 'Letter', 
     'margin-top': '0.5in', 
     'margin-right': '0.75in', 
     'margin-bottom': '0.5in', 
     'margin-left': '0.75in', 
     'encoding': "UTF-8", 
     'footer-left': "This is a footer", 
     'footer-line':'', 
     'footer-font-size':'7', 
     'footer-right': '[page] of [topage]', 

     'custom-header' : [ 
      ('Accept-Encoding', 'gzip') 
     ], 
     'no-outline': None 
    } 

如果有更好的请让我知道的方法