当前位置: 首页 > news >正文

cento安装wordpress/槐荫区网络营销seo

cento安装wordpress,槐荫区网络营销seo,网站备案名称怎么修改,大学网站开发原创 2017年03月31日 16:07:01893021、说明pdfkit,把HTMLCSS格式的文件转换成PDF格式文档的一种工具。其实,它就是html转成pdf工具包wkhtmltopdf的Python封装。所以,必须安装wkhtmltopdf。 一般情况下,wkhtmltopdf需要手动安装&am…

原创 2017年03月31日 16:07:01893

0

2

1、说明

pdfkit,把HTML+CSS格式的文件转换成PDF格式文档的一种工具。

其实,它就是html转成pdf工具包wkhtmltopdf的Python封装。所以,必须安装wkhtmltopdf。 一般情况下,wkhtmltopdf需要手动安装,尤其要注意的是Windows下,需要把wkhtmltopdf的bin执行文件路径添加到PATH变量中。

2、安装

3、API说明

def from_url(url, output_path, options=None, toc=None, cover=None, configuration=None, cover_first=False): """

把从URL获取文件转换为PDF文件

:param url:

URL 或 URL列表

:参数,output_path:

输出PDF文件的路径。如果是参数等于False,意味着文件将会以字符串的形式返回,得到文本文件。

:param options:

(可选) dict with wkhtmltopdf global and page options, with or w/o '--'

:param toc:

(可选) dict with toc-specific wkhtmltopdf options, with or w/o '--'

:param cover:

(可选) string with url/filename with a cover html page

:param configuration:

(可选)实例化 pdfkit.configuration.Configuration()

:param configuration_first:

(optional) if True, cover always precedes TOC

返回值:成功返回True

"""

r = PDFKit(url, 'url', options=options, toc=toc, cover=cover,configuration=configuration, cover_first=cover_first)

return r.to_pdf(output_path)1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

def from_file(input, output_path, options=None, toc=None, cover=None, css=None, configuration=None, cover_first=False): """

Convert HTML file or files to PDF document

:param input:

path to HTML file or list with paths or file-like object

:param output_path:

path to output PDF file. False means file will be returned as string.

:param options:

(optional) dict with wkhtmltopdf options, with or w/o '--'

:param toc:

(optional) dict with toc-specific wkhtmltopdf options, with or w/o '--'

:param cover:

(optional) string with url/filename with a cover html page

:param css:

(optional) string with path to css file which will be added to a single input file

:param configuration:

(optional) instance of pdfkit.configuration.Configuration()

:param configuration_first:

(optional) if True, cover always precedes TOC

Returns: True on success

"""

r = PDFKit(input, 'file', options=options, toc=toc, cover=cover, css=css, configuration=configuration, cover_first=cover_first)

return r.to_pdf(output_path)1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

def from_string(input, output_path, options=None, toc=None, cover=None, css=None, configuration=None, cover_first=False): """

Convert given string or strings to PDF document

:param input: string with a desired text. Could be a raw text or a html file

:param output_path: path to output PDF file. False means file will be returned as string.

:param options: (optional) dict with wkhtmltopdf options, with or w/o '--'

:param toc: (optional) dict with toc-specific wkhtmltopdf options, with or w/o '--'

:param cover: (optional) string with url/filename with a cover html page

:param css: (optional) string with path to css file which will be added to a input string

:param configuration: (optional) instance of pdfkit.configuration.Configuration()

:param configuration_first: (optional) if True, cover always precedes TOC

Returns: True on success

"""

r = PDFKit(input, 'string', options=options, toc=toc, cover=cover, css=css, configuration=configuration, cover_first=cover_first)

return r.to_pdf(output_path)1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

def configuration(**kwargs): """

Constructs and returns a :class:`Configuration` with given options

:参数 wkhtmltopdf: 二进制文件路径

:param meta_tag_prefix: the prefix for ``pdfkit`` specific meta tags

""" return Configuration(**kwargs)1

2

3

4

5

6

7

8

4、举例说明

4.1、一个简单的例子

import pdfkit

pdfkit.from_url('https://www.google.com.hk','out1.pdf')

pdfkit.from_file('123.html','out2.pdf')

pdfkit.from_string('Hello!','out3.pdf')1

2

3

4

5

也可以传递一个url或者文件名列表:

pdfkit.from_url(['https://www.google.com.hk','https://baidu.com','http://cn.bing.com/'],'out_0.pdf')

pdfkit.from_file(['122.html','123.html'],'out_1.pdf')1

2

如果你想对生成的PDF作进一步处理, 你可以将其读取到一个变量中:

pdf=pdfkit.from_url('https://www.google.com.hk',False)1

你可以指定所有的 wkhtmltopdf选项 。你可以移除选项名字前面的 ‘–’ .如果选项没有值, 使用None, False或者“*”作为字典值:

options = {

'page-size':'Letter',

'margin-top':'0.75in',

'margin-right':'0.75in',

'margin-bottom':'0.75in',

'margin-left':'0.75in',

'encoding':"UTF-8",

'no-outline':None

}

pdfkit.from_url('https://www.google.com.hk','out1.pdf',options=options)1

2

3

4

5

6

7

8

9

10

默认情况下, PDFKit 将会显示所有的wkhtmltopdf输出. 如果你不想看到这些信息,你需要传递一个quiet选项:

options = {'quiet':''}

pdfkit.from_url('https://www.google.com.hk','out1.pdf',options=options)1

2

由于wkhtmltopdf的命令语法 ,TOC和Cover选项必须分开指定:

toc={'xsl-style-sheet':'toc.xsl'}

cover='124.html'

pdfkit.from_file('122.html', options=options, toc=toc, cover=cover)1

2

3

当你转换文件、或字符串的时候,你可以通过css选项指定扩展的 CSS 文件。

css='example.css'

pdfkit.from_file('file.html', options=options, css=css)

# Multiple CSS files

css=['example.css','example2.css']

pdfkit.from_file('file.html', options=options, css=css)1

2

3

4

5

配置

每个API调用都有一个可选的参数。这应该是pdfkit.configuration() API 调用的一个实例。采用configuration 选项作为初始化参数。可用的选项有:

wkhtmltopdf——wkhtmltopdf二进制文件所在的位置。默认情况下pdfkit会尝试使用which(在类UNIX系统中) 或where(在Windows系统中)来判断。

meta_tag_prefix–pdfkit的前缀指定 meta tags(元标签) - 默认情况是pdfkit-

示例 :针对wkhtmltopdf不在系统路径中(不在$PATH里面):

config=pdfkit.configuration(wkhtmltopdf='/opt/bin/wkhtmltopdf'))

pdfkit.from_string(html_string, output_file, configuration=config)

http://www.jmfq.cn/news/5045527.html

相关文章:

  • 网站聊天工具代码/首页优化排名
  • 如何构思公司网站/seo分析seo诊断
  • 西安建设集团网站/怎么自己做一个网站
  • 上海中国建设银行招聘信息网站/做优化关键词
  • 转入已备案网站/企业网站页面设计
  • 做音乐网站要什么源码/社群营销
  • seo建设网站/网络舆情监测系统软件
  • 网站如何实现微信登录界面/深圳华强北
  • 网站设计需求/百度怎么发布自己的广告
  • 秦皇岛网站制作/营销推广活动策划
  • 网站建设详细的步骤有哪些/可靠的网站优化
  • 乌鲁木齐网站技术服务电话/网站开发详细流程
  • 甘肃省城乡与建设厅网站首页/百度查询网
  • 安徽建站平台/郑州网络营销顾问
  • 温州微网站制作哪里有/关键词是什么意思
  • wordpress主题操作/seo零基础教学视频
  • 普通网站设计/全渠道营销管理平台
  • 桂林做旅游网站失败的网站/站长之家官网登录入口
  • 查看网站是什么语言做的/百度竞价在哪里开户
  • 做淘宝网站用什么软件/百度指数查询官网入口登录
  • 秦皇岛网站团队/企业推广宣传方式
  • 福州免费建站品牌企业/seo管理
  • wordpress 翻译文件/优化大师哪个好
  • 西安的电商网站设计/百度推广seo优化
  • wordpress邮箱链接修复/seo服务商排名
  • 网站设计上市公司/百度服务中心电话
  • 二手优品哪个网站做/推广平台怎么做
  • 提供网站推广公司电话/新媒体营销推广方案
  • 网站转化下降原因/网站做优化
  • 网站建设it职位/创建网站的流程是什么