How to convert TXT to PDF in RHEL 6?

Hello friends,

I need to convert ASCII text to PDF on RHEL 6 so I did the below and could generate PDF but it has lot of junk/special characters.

yum install enscript ghostscript

enscript -p output.ps input.txt

ps2pdf output.ps output.pdf

So I download latest source of Ghostscript (ver 9.18) and I'm able to see ps2pdf and other commands that I got after installing from the source (after compiling/installing etc.). How can I generate PDF from these utilities (or how can I generate PS file from them so I can later run ps2pdf?)?

[root@lnxtst01 bin]#  file *
dvipdf:      POSIX shell script text executable
eps2eps:     POSIX shell script text executable
font2c:      POSIX shell script text executable
gpcl6:       ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
gs:          ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
gsbj:        POSIX shell script text executable
gsdj:        POSIX shell script text executable
gsdj500:     POSIX shell script text executable
gslj:        POSIX shell script text executable
gslp:        POSIX shell script text executable
gsnd:        POSIX shell script text executable
gxps:        ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
lprsetup.sh: POSIX shell script text executable
pdf2dsc:     POSIX shell script text executable
pdf2ps:      POSIX shell script text executable
pf2afm:      POSIX shell script text executable
pfbtopfa:    POSIX shell script text executable
pphs:        POSIX shell script text executable
printafm:    POSIX shell script text executable
ps2ascii:    POSIX shell script text executable
ps2epsi:     POSIX shell script text executable
ps2pdf:      POSIX shell script text executable
ps2pdf12:    POSIX shell script text executable
ps2pdf13:    POSIX shell script text executable
ps2pdf14:    POSIX shell script text executable
ps2pdfwr:    POSIX shell script text executable
ps2ps:       POSIX shell script text executable
ps2ps2:      POSIX shell script text executable
unix-lpr.sh: POSIX shell script text executable
wftopfa:     POSIX shell script text executable
[root@lnxtst01 bin]#

Please advise, many thanks!!

---------- Post updated at 12:31 PM ---------- Previous update was at 11:54 AM ----------

Further investigation shows that output PDF has many lines with special control characters like \033 (escape sequences) like below

\033&k2G\033(s12h10V

$ file input.txt
input.txt:       ASCII English text, with escape sequences

So is there any possibility to remove those escape sequences from source text file OR using enscript command itself (which I used to convert TXT to PS)

Did you try a2ps ?

If you don't have it, you can install using yum install a2ps

1 Like

Have you tried pcl2ps. Your source document is a PCL5 print file.

1 Like

Excellent! You are absolutely right. I used this source file as PCL and able to generate PDF without any special/junk characters using gpcl6 from ghostpcl 9.18 . But there's some small issue of getting more number of pages than source ( I tried 650 pages source file and it generated 810 pages of PDF). Few last lines of a page skipping to next page and pushing the next page further. Each page starts with a "Print Date" & "Page xxx" (in the first line). Can we use this pattern to adjust each page OR gpcl6 has any parameter that can define this? I tried few but no luck.

Could you please suggest any ideas on how to fix this?

Again, many thanks for your correct direction :b:

The page length is incorrect for the paper size. You need to set the top and bottom margins, and the printable lines per page so that the pdf file matches the original output.