Professional Documents
Culture Documents
text processing - How to convert TXT to PDF? - Unix & Linux Stack Exchange
signup
Unix&LinuxStackExchangeisa
questionandanswersiteforusersof
Linux,FreeBSDandotherUn*xlike
operatingsystems.Jointhemitonly
takesaminute:
login
tour
Here'showitworks:
Anybodycanask
aquestion
Signup
help
Anybodycan
answer
Thebestanswersarevoted
upandrisetothetop
HowtoconvertTXTtoPDF?
Iwanttoconvert
.txt
filesto
.I'musingthis:
Butthisproducesone"error"ifthere'saverylonglineinthetextfile,itdoesn'tgetwrapped.
Inputtext
OutputPDF
Also,itwouldalsobegreatiftheoutputPDFcouldcontaintext,insteadofimagesoftext.
UPDATE:IhavemanymanymanyTXTfiles.Sodon'twanttodoitbyhand.Ineedanautomaticsolution,liketheoneimentionedabove.
/textprocessing
askedJul26'11at6:03
Caleb
39.7k
LanceBaynes
6
107
148
6,257
51
159
284
7 Answers
OnemethodistouseCUPSandthePDFpsuedoprinterto"print"thetexttoaPDFfile.
AnotheristouseenscripttoencodetopostscriptandthenconvertfrompostscripttoPDF
usingtheps2pdffilefromghostscriptpackage.
answeredJul26'11at6:53
Keith
5,121
15
21
pandoccandothis.It'smorefocusedonconvertingmarkeduptexttovariousformats,butit
shouldhavenoproblemswithsimpleplaintext.
http://unix.stackexchange.com/questions/17406/how-to-convert-txt-to-pdf
1/3
01/12/2016
text processing - How to convert TXT to PDF? - Unix & Linux Stack Exchange
evilsoup
3,075
10
23
2 Looksnice,butthemassiveamountofhaskelldependenciespandocwantsscaredmeaway:/lkraavJun28'13at
11:46
@Ikraavyeah,it'swayoverkillforthispurpose,butifyouhavemarkdownorHTML(oranyoftheothermarkupsit
canacceptasinput)pandocwouldbethewaytogo.PDFactuallyrequiresevenmoredependenciesinternally,
pandocusesLaTeXtoconverttoPDF,soyouneedtoinstallthatstufftoobutthequalityisverygood(Iuseitto
convertmarkdown'dtexttoPDFandEPUB,primarily).evilsoupJun28'13at11:52
pandoc(1.16.0.2)replacesmynewlineswithtabs.SparhawkJan26at2:34
LibreOffice/OpenOfficeaswellasmostotherwordprocessors(Abiword)candothisquite
easily.
Thereisalittleutilitycalled unoconv thatusestheLibreOfficecodebasetodofileformat
conversionsonthecommandline.Itcanreadandwriteanycombinationofformatsthat
LibreOfficecanandmakesitveryeasytodothingslike doc to pdf conversionsonthe
commandline.Simple txt to pdf wouldbeeasyforit.
answeredJul26'11at7:55
Caleb
39.7k
107
148
Justusethetext2pdf,whichisfreeandopensource.Atthelinkyoucandownloadthesource
ortheprecompiledbinaryforwindows,solaris,dos.
I'mabletouseitintoAIXOSwithoutproblem.Verysimpletocompile,justsavethetext2pdf.c
andMakefileintothesamedirectoryandtype make .(hereIsetthevariableCC=gcconAIX,
onlinuxthiswillnotbeanissue)
$ ./text2pdf
-h
Note that where one variable is implied by two options, the second option
takes precedence for that variable. (e.g. -A4 -y500)
In landscape mode, page width and height are simply swapped over before
formatting, no matter how or when they were defined.
text2pdf v1.1 (c) Phil Smith, 1996
$ ./text2pdf -f"Courier" -s6 -c216 -v6 -L -A4 ./rep3.txt >rep3.pdf
editedApr5'13at17:32
answeredApr5'13at14:02
ceinmart
213
2 isthereanutf8capableforkofthis?WolfgangFahlJun4'15at2:42
ThereisalsoaUTF8toPostScriptconvertercalled
paps
editedJul26'11at12:17
answeredJul26'11at11:23
Caleb
39.7k
tunit
6
107
148
51
http://unix.stackexchange.com/questions/17406/how-to-convert-txt-to-pdf
2/3
01/12/2016
text processing - How to convert TXT to PDF? - Unix & Linux Stack Exchange
2 Itworks,andwithTrueTypefonts,butitshouldbenotedthatitproducesadocumentwithbitmapsasaresult,
insteadofusingthefontsnatively.(Iguessthat'sbecauseofPostscript?)njsgJan29'13at22:08
Couldn'tcompileitonCygwin32onmyWindoze...errekaFeb18at23:03
YoucanprinttexttoaPDFfileusingVim,aslongasitwascompiledwiththe
feature.
Forthisyouusethe :hardcopy
example.txt andexecute
> {filename}
+postscript
command.Forexampleyoucanopen
-c
option,which
GonaloRibeiro
151
Useenscripttocreateda.psfile,andthenps2pdf(orps2pdfwr)toconvertto.pdf
Thefollowingscriptcreatesa.pdffilewith10ptleftandrightmargins,andusesacourierfont
thatis7.3ptswideand10ptshigh,soa132colprintoutfitsonan81/2X11page.Use
enscripttosetupyourpage,fonts,etc.
$ enscript -B --margins=10:10: -o outputfile.ps -f Courier@7.3/10 inputfile
$ ps2pdfwr outputfile.ps newfile.pdf
$ rm outputfile.ps
editedJun8'13at20:32
answeredJun8'13at18:52
slm
171k
DanWalker
43
320
489
31
4 Athingtonote:enscriptdoesnotsupportutf8.maxschlepzigAug16'14at13:51
http://unix.stackexchange.com/questions/17406/how-to-convert-txt-to-pdf
3/3