Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在xhtml2pdf中添加目录_Python 3.x_Xhtml2pdf - Fatal编程技术网

Python 3.x 在xhtml2pdf中添加目录

Python 3.x 在xhtml2pdf中添加目录,python-3.x,xhtml2pdf,Python 3.x,Xhtml2pdf,下面的例子我还需要添加目录。在xhtml2pdf中 需要在html文件中插入以添加目录。但问题是在哪里添加它。xhtml2pdf文档仅说明添加到html文件。我不知道该加在哪里。我尝试在很多地方添加它,但都返回了一些错误。我也在网上搜索了一些例子,没有找到 from xhtml2pdf import pisa # import python module # Define your data sourceHtml = """ html> <head>

下面的例子我还需要添加目录。在xhtml2pdf中
需要在html文件中插入以添加目录。但问题是在哪里添加它。xhtml2pdf文档仅说明添加到html文件。我不知道该加在哪里。我尝试在很多地方添加它,但都返回了一些错误。我也在网上搜索了一些例子,没有找到

from xhtml2pdf import pisa             # import python module

# Define your data
sourceHtml = """
html>
<head>
<style>
    @page {
        size: a4 portrait;
        @frame header_frame {           /* Static Frame */
            -pdf-frame-content: header_content;
            left: 50pt; width: 512pt; top: 50pt; height: 40pt;
        }
        @frame content_frame {          /* Content Frame */
            left: 50pt; width: 512pt; top: 90pt; height: 632pt;
        }
        @frame footer_frame {           /* Another static Frame */
            -pdf-frame-content: footer_content;
            left: 50pt; width: 512pt; top: 772pt; height: 20pt;
        }
    }
</style>
</head>

<body>
    <!-- Content for Static Frame 'header_frame' -->
    <div id="header_content">Lyrics-R-Us</div>

    <!-- Content for Static Frame 'footer_frame' -->
    <div id="footer_content">(c) - page <pdf:pagenumber>
        of <pdf:pagecount>
    </div>

    <!-- HTML Content -->
    <h1>Title Page</h1>
     <h1>Chapter 1</h1>
</body>
</html>

"""
outputFilename = "test.pdf"

# Utility function
def convertHtmlToPdf(sourceHtml, outputFilename):
    # open output file for writing (truncated binary)
    resultFile = open(outputFilename, "w+b")

    # convert HTML to PDF
    pisaStatus = pisa.CreatePDF(
            sourceHtml,                # the HTML to convert
            dest=resultFile)           # file handle to recieve result

    # close output file
    resultFile.close()                 # close output file

    # return True on success and False on errors
    return pisaStatus.err

# Main program
if __name__ == "__main__":
    pisa.showLogging()
    convertHtmlToPdf(sourceHtml, outputFilename)

从xhtml2pdf导入pisa#导入python模块
#定义您的数据
sourceHtml=“”
html>
@页面{
尺寸:a4人像;
@帧头\帧{/*静态帧*/
-pdf框架内容:标题内容;
左:50磅;宽:512磅;顶:50磅;高:40磅;
}
@框架内容\框架{/*内容框架*/
左:50磅;宽:512吨;顶:90磅;高:632吨;
}
@框架页脚\u框架{/*另一个静态框架*/
-pdf框架内容:页脚内容;
左:50磅;宽:512吨;顶:772吨;高:20磅;
}
}
歌词-R-Us
(c) -页面
属于
标题页
第一章
"""
outputFilename=“test.pdf”
#效用函数
def CONVERTTHTMLTOPDF(源HTML,输出文件名):
#打开输出文件进行写入(截断的二进制文件)
结果文件=打开(outputFilename,“w+b”)
#将HTML转换为PDF
pisaStatus=pisa.CreatePDF(
sourceHtml,#要转换的HTML
dest=resultFile)#接收结果的文件句柄
#关闭输出文件
resultFile.close()#关闭输出文件
#成功时返回True,错误时返回False
返回pistatus.err
#主程序
如果名称=“\uuuuu main\uuuuuuuu”:
pisa.showLogging()
convertHtmlToPdf(源HTML,输出文件名)

把它放在你喜欢的任何地方,注意它在某种程度上是可以理解空白的,所以为了使它工作,请粘贴
div
,如下所示

    <div>
        <pdf:toc />
    </div>

把它放在你喜欢的任何地方,注意它在某种程度上是可以理解空白的,所以为了使它工作,请粘贴
div
,如下所示

    <div>
        <pdf:toc />
    </div>