Skip to main content
 首页 » 编程设计

Python xhtml2pdf 横向生成PDF

2025年05月04日15Leo_wl

我正在使用 python xhtml2pdf 模块和 pisa 类来创建 PDF。现在 PDF 是竖版 A4 格式,如何将其更改为横向布局?

import xhtml2pdf.pisa as pisa 
result = StringIO() 
pdf = pisa.CreatePDF( 
        StringIO("This is my PDF"), 
        result) 

请您参考如下方法:

使用以下 CSS:

@page { 
    size: letter landscape; 
    margin: 2cm; 
}