首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用python中的pdfkit库显示页脚上方的页脚行?

如何使用python中的pdfkit库显示页脚上方的页脚行?
EN

Stack Overflow用户
提问于 2017-08-03 07:50:50
回答 1查看 3.6K关注 0票数 2

背景信息

我有下面的Python代码,我想用来生成一个pdf文件。它使用pdfkit库

代码语言:javascript
运行
复制
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如下。我只需要一条线以上,这是一个页脚。

根据下面的站点,我可以使用属性footer-line在页脚上方添加页脚行,但我不了解如何在python中实现它的语法。

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

简短的问题

如何修改options属性以包括footer-line

代码语言:javascript
运行
复制
 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
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-03 08:02:00

显然,您只需添加属性并将其传递给一个空参数。

因此,对于options属性,您只需添加'footer-line':'',它将变成以下内容

代码语言:javascript
运行
复制
     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
    }

如果有更好的方法,请告诉我

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45478048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档