简体   繁体   English

在 linux shell 中将.txt 转换为.pdf

[英]convert .txt to .pdf in linux shell

I am trying to convert.txt file to.pdf file in linux shell.我正在尝试将 linux shell 中的 .txt 文件转换为 .pdf 文件。 Problem is that, i dont have any converter install on Linux.问题是,我没有在 Linux 上安装任何转换器。 i only have ps2pdf converted on linux machine, other package/tool, i can not install so i have to manage with this.我只有在 linux 机器上转换的 ps2pdf,其他包/工具,我无法安装,所以我必须用这个来管理。 So i am trying to find way to convert.txt to.pdf.所以我试图找到将.txt 转换为.pdf 的方法。 I had read some blog which told to execute below script.我读过一些博客告诉执行下面的脚本。

vim file.txt -c "hardcopy > file.ps | q"; ps2pdf file.ps

While executing above command it provide file.pdf output but when opening this pdf using Adobe reader i see bad character (?) on each line, also see below message on shell after executing above script. While executing above command it provide file.pdf output but when opening this pdf using Adobe reader i see bad character (?) on each line, also see below message on shell after executing above script. Pls find attached bad character in attached file请在附件中找到附加的坏字符

[anukalps@CTSBUI ~]$ vim file.txt -c "hardcopy > file.ps | q"; ps2pdf file.ps ^[[2;2R[anukalps@CTSBUI ~]$ 2R

how to fix this?如何解决这个问题?

在此处输入图像描述

When you have a bunch of text documents to maintain, there are advantages in converting them into PDF format.当您有一堆文本文档要维护时,将它们转换为 PDF 格式是有好处的。 For example, PDF is good for printing because PDF documents have pre-defined layout.例如,PDF 适合打印,因为 PDF 文档具有预定义的布局。 Besides, with PDF format, there is less risk hat the documents are accidentally modified.此外,使用 PDF 格式,文档被意外修改的风险较小。

To convert a text file to PDF format, you can follow two-step procedures.要将文本文件转换为 PDF 格式,您可以执行两步过程。

Prerequisites先决条件

First, you need to install two prerequisite packages.首先,您需要安装两个必备软件包。

For Debian, Ubuntu or Linux Mint:对于 Debian、Ubuntu 或 Linux 薄荷:

$ sudo apt-get install enscript ghostscript

For Fedora, CentOS or RHEL:对于 Fedora,CentOS 或 RHEL:

$ sudo yum install enscript ghostscript

For Arch Linux:对于拱 Linux:

$ sudo pacman -S enscript ghostscript

Convert a Text File to PDF Format将文本文件转换为 PDF 格式

Once all prerequisites are installed, follow these two steps to generate a PDF file from a text file.安装所有先决条件后,请按照以下两个步骤从文本文件生成 PDF 文件。

First, convert a text file to Postscript format by using enscript command-line tool.首先,使用 enscript 命令行工具将文本文件转换为 Postscript 格式。

$ enscript -p output.ps input.txt

Finally convert the generated postscript file to a PDF file.最后将生成的 postscript 文件转换为 PDF 文件。

$ ps2pdf output.ps output.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM