输出格式
输出格式
Aspose.TeX FOSS for Python supports three output formats through interchangeable output device classes. Pass the appropriate device to TeXJob and call run() to obtain the typeset output. PdfDevice returns PDF bytes directly from run(). DviDevice returns DVI bytes from run(). SvgDevice does not return bytes from run() — instead, retrieve per-page SVG byte strings using SvgDevice.get_all_pages() after run() completes.
通过PdfDevice的PDF文件
from aspose_tex import TeXJob, TeXOptions, PdfDevice, StringInputSource
pdf_bytes = TeXJob(StringInputSource("Hello!"), PdfDevice(), options=TeXOptions()).run()
with open("output.pdf", "wb") as f:
f.write(pdf_bytes)通过DviDevice进行DVI
from aspose_tex import TeXJob, TeXOptions, DviDevice, StringInputSource
dvi_bytes = TeXJob(StringInputSource("Hello!"), DviDevice(), options=TeXOptions()).run()
with open("output.dvi", "wb") as f:
f.write(dvi_bytes)通过SvgDevice进行 SVG
from aspose_tex import TeXJob, TeXOptions, SvgDevice, StringInputSource
device = SvgDevice()
TeXJob(StringInputSource("Hello!"), device, options=TeXOptions()).run()
for i, svg in enumerate(device.get_all_pages()):
with open(f"page_{i}.svg", "wb") as f:
f.write(svg)选择输出格式
| 使用情况 | Device | Notes |
|---|---|---|
| 打印或分享 | PdfDevice | 可携带,最兼容的 |
| 网络/向量图形 | SvgDevice | 每页SVG通过 get_all_pages() |
| 传统的TEX管道 | DviDevice | 下游工具的DVI格式 |
API 参考概述
| Class | Description |
|---|---|
PdfDevice | 制作PDF输出字节 |
DviDevice | 生成DVI输出字节 |
SvgDevice | 每页生成SVG输出 |
SvgDevice.get_all_pages() | 返回SVG字节串列表 |