使用pdfkit for python生成目录

2024-06-01 01:59:31 发布

您现在位置:Python中文网/ 问答频道 /正文

问题摘要:我无法使目录生成器在pdfkit for Python中工作

我所尝试的:传递参数toc

我的当前代码:

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

pdfkit.from_file(
    book_html_filename, book_pdf_filename, 
    configuration=config, 
    toc=toc,
    options=options,cover=cover_html_filename,cover_first=True)

我对.xsl一点也不熟悉,因此我不知道该文件应该包含什么内容

我当前的.xsl文件:

我是说它是空的。我收到以下错误消息:

Exception has occurred: OSError
wkhtmltopdf reported an error:
Loading pages (1/6)
[>                                                           ] 0%
[===>                                                        ] 5%
[======>                                                     ] 10%
[==================>                                         ] 30%
[=================================>                          ] 55%
[=============================================>              ] 75%
[============================================================] 100%
Counting pages (2/6)                                               
[===================>                                        ] Object 1 of 3
[============================================================] Object 3 of 3
Error XTSE0010 in file:///C:/Program%20Files/wkhtmltopdf/bin/wkhtmltopdf.exe, at line 1, column 0: Parse error: Premature end of document.
Loading TOC (3/6)                                                           
[======>                                                     ] 10%
[============================================================] 100%
Error XTSE0010 in file:///C:/Program%20Files/wkhtmltopdf/bin/wkhtmltopdf.exe, at line 1, column 0: Parse error: Premature end of document.
[======>                                                     ] 10% 
[============================================================] 100%
Resolving links (4/6)                                              
[===================>                                        ] Object 1 of 3
[=======================================>                    ] Object 2 of 3
[============================================================] Object 3 of 3
Loading headers and footers (5/6)                                           
Printing pages (6/6)
[>                                                           ] Preparing
[========>                                                   ] Page 1 of 7
[================>                                           ] Page 2 of 7
[=========================>                                  ] Page 3 of 7
[==================================>                         ] Page 4 of 7
[==========================================>                 ] Page 5 of 7
[===================================================>        ] Page 6 of 7
[============================================================] Page 7 of 7
Done                                                                      
  File "C:\Users\User\Documents\GitHub\SeferMaker\py\create_pdf_with_pdfkit.py", line 40, in <module>
    pdfkit.from_file(

Tags: ofinobjectlinepageerrorcoverpages