把 html 文件转成 pdf - V2EX
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Ewig

把 html 文件转成 pdf

  •  
  •   Ewig Jan 4, 2019 5147 views
    This topic created in 2697 days ago, the information mentioned may be changed or developed.
    import pdfkit

    pdfkit.from_url('http://www.sec.gov/Archives/edgar/data/1754581/000119312518361084/d620103df1.htm','/home/shenjianlin/out.pdf')

    这个链接是打开的是 html,现在我通过程序转成 pdf 但是现在转换过程中报错了,大家有没有更好的方法,谢谢


    Traceback (most recent call last):
    File "timeout.py", line 3, in <module>
    pdfkit.from_url('http://www.sec.gov/Archives/edgar/data/1754581/000119312518361084/d620103df1.htm','/home/shenjianlin/out.pdf')
    File "/usr/lib/python3.4/site-packages/pdfkit/api.py", line 26, in from_url
    return r.to_pdf(output_path)
    File "/usr/lib/python3.4/site-packages/pdfkit/pdfkit.py", line 153, in to_pdf
    'https://github.com/JazzCore/python-pdfkit/wiki/Using-wkhtmltopdf-without-X-server' % stderr)
    OSError: wkhtmltopdf: cannot connect to X server

    You will need to run wkhtmltopdf within a "virtual" X server.
    Go to the link below for more information
    https://github.com/JazzCore/python-pdfkit/wiki/Using-wkhtmltopdf-without-X-server
    15 replies    2019-01-04 16:49:54 +08:00
    Kamitora
        1
    Kamitora  
       Jan 4, 2019 via iPhone   2
    chrome 打开,右键,打印,导出 pdf
    sethverlo
        2
    sethverlo  
       Jan 4, 2019
    wkhtmltopdf, pandoc, 还有个什么忘了,自己搜下吧,但是坑挺多的,不建议生产环境用,自己玩玩儿还是可以的
    sethverlo
        3
    sethverlo  
       Jan 4, 2019
    哦对了你这个 X server 指的是 x11
    binux
        5
    binux  
       Jan 4, 2019
    You will need to run wkhtmltopdf within a "virtual" X server.
    Go to the link below for more information
    https://github.com/JazzCore/python-pdfkit/wiki/Using-wkhtmltopdf-without-X-server
    519718366
        7
    519718366  
       Jan 4, 2019
    chrome 插件:Full Page Screen Capture
    Aprilming
        8
    Aprilming  
       Jan 4, 2019
    你这个更新到最新的 wkhtmltopdf,好像就可以了,这个我之前用过,需要 X server,但是服务器没有 X server,需要安装其他包才能解决,上次看的时候最新的 wkhtmltopdf 貌似自带了。
    yidinghe
        9
    yidinghe  
       Jan 4, 2019   2
    用 Chrome 的 headless 模式直接转换,无需 xserver
    Aprilming
        10
    Aprilming  
       Jan 4, 2019
    这玩意在生产环境中,还是比较坑比的,自己玩玩就算了,主要是在服务器上转 pdf 的速度比较慢,还经常报错,还有文件名中文的问题,反正之前用的时候,坑的一批,最后为了解决慢的问题,还重构了代码,ps:在自己电脑转的时候不算慢,但是到了服务器上真的慢。主要还是 X server 的问题
    devforma
        11
    devforma  
       Jan 4, 2019
    https://yq.aliyun.com/articles/601753
    可以用阿里云函数计算搭一个服务
    nogoodren
        12
    nogoodren  
       Jan 4, 2019
    试一试虚拟打印机
    l0o0
        13
    l0o0  
       Jan 4, 2019
    如果用 python 的话,推荐你试试这个 https://github.com/Kozea/WeasyPrint,我感觉比较不错,打印出来的效果比 wkhtmltopdf 好挺多的。而且开发还挺活跃,有问题直接提 issue
    xjqaxl
        14
    xjqaxl  
       Jan 4, 2019
    phantomjs
    Ewig
        15
    Ewig  
    OP
       Jan 4, 2019
    已经解决,原因是版本太低,在外国论坛找了一个高版本的已经解决,谢谢诸位!
    About     Help     Advertise     Blog     API     FAQ     Solana     5727 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 86ms UTC 01:41 PVG 09:41 LAX 18:41 JFK 21:41
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86