在 Linux 中将文本转换为 pdf 的轻量级解决方案

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20129029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:25:12  来源:igfitidea点击:

a light solution to convert text to pdf in Linux

linuxpdf

提问by Xin Guo

I am looking for a light solution in linux, to literallyconvert a *.txtfile into pdfformat. I hope the solution satisfies:

我正在 linux 中寻找一个简单的解决方案,从字面上*.txt文件转换为pdf格式。我希望解决方案满足:

  1. lightweight. I know renaming *.txtto *.odtand then use libreofficeis a pathway, but it will load the heavy libreoffice.
  2. I know pr|groff -Tpdfis a solution, yet it does not work literally: it throws away my line-breaks, an may accidentally eat some special marks as escaped labels, making potential bugs. But I still hope to use these old tools as much as possible, because they are stable and fast.
  1. 轻的。我知道重命名*.txt*.odt然后使用libreoffice是一种途径,但它会加载沉重的libreoffice.
  2. 我知道pr|groff -Tpdf是一个解决方案,但它实际上并不能正常工作:它会丢弃我的换行符,可能会不小心吃一些特殊标记作为转义标签,从而产生潜在的错误。但我还是希望尽可能多地使用这些旧工具,因为它们既稳定又快速。

Many thanks!

非常感谢!

采纳答案by jkshah

One way would be to use enscriptfollowed by ps2pdf

一种方法是使用enscript后跟ps2pdf

enscript -p file.ps file.txt
ps2pdf file.ps file.pdf