输出格式

输出格式

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)

选择输出格式

使用情况DeviceNotes
打印或分享PdfDevice可携带,最兼容的
网络/向量图形SvgDevice每页SVG通过 get_all_pages()
传统的TEX管道DviDevice下游工具的DVI格式

API 参考概述

ClassDescription
PdfDevice制作PDF输出字节
DviDevice生成DVI输出字节
SvgDevice每页生成SVG输出
SvgDevice.get_all_pages()返回SVG字节串列表

See Also

 中文