Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
08-15-2014, 09:52 PM
|
#1
|
Member
Registered: Oct 2013
Posts: 37
Rep:
|
Software that converts .txt to .pdf: Options to intall.
Hello!
Guys, could you, please, tell me a simple command line program that converts .txt files to .pdf? Could be more than one format(.txt) do pdf, but mainly .txt to pdf. He needs to be freeware too. I tried this one, but i have to pay for it after 30 days!
http://www.linuxquestions.org/questi...ersion-290058/
I'm talking about text2pdf.
I'm using Sublime Text 2 and, i don't know, but i believe he doesn't have this option. I don't want to install LibreOffice just to do that. I just want to convert .txt to .pdf.
Thank you!
I'm using Debian Wheezy last version.
|
|
|
08-15-2014, 10:34 PM
|
#2
|
Senior Member
Registered: Dec 2005
Distribution: Slackware
Posts: 1,135
|
Ghostscript (which I imagine would be part of your install)
Code:
gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=<newfilename>.pdf <inputfilenameshere>
cheers,
|
|
|
08-16-2014, 01:18 AM
|
#3
|
Member
Registered: Oct 2013
Posts: 37
Original Poster
Rep:
|
I tried what you said, but look the output of my test.txt file. He has the same content of this topic, the same text.
Quote:
rob@robgeek:~$ gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=Test.pdf test.txt
Error: /undefined in Hello!
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1910 1 3 %oparray_pop 1909 1 3 %oparray_pop 1893 1 3 %oparray_pop 1787 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:1162/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Current file position is 7
GPL Ghostscript 9.05: Unrecoverable error, exit code 1
|
|
|
|
08-16-2014, 04:29 AM
|
#4
|
LQ Guru
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465
Rep:
|
|
|
|
08-16-2014, 08:35 AM
|
#5
|
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,461
|
You can use txt2html to convert it to html first, then wkhtmltopdf for the html to pdf. Both of those have lots of options you can use in a script. And I think you can just apt-get them.
Last edited by Guttorm; 08-16-2014 at 08:37 AM.
|
|
|
08-16-2014, 07:33 PM
|
#6
|
Member
Registered: Oct 2013
Posts: 37
Original Poster
Rep:
|
Quote:
Originally Posted by Guttorm
You can use txt2html to convert it to html first, then wkhtmltopdf for the html to pdf. Both of those have lots of options you can use in a script. And I think you can just apt-get them.
|
I tried what you said and i got a problem with special characters we use in my idiom, so i tried convert .txt to .ps and then convert .ps to .pdf with the following commands:
Quote:
rob@robgeek:~$ enscript -p questions.ps questions.txt
[ 1 page * 1 copy ] left in questions.ps
6 lines were wrapped
rob@robgeek:~$ ps2pdf questions.ps questions.pdf
|
It worked fine but the problem is in my idiom we use special characters, like ' ` ~ ^ in vogals, and when i convert .txt to .pdf the output is like the following exmaples.
Quote:
iônico -> ià ́nico
não -> não
cátions -> cátions
possível -> possÃ-vel
|
How can i solve this problem?
|
|
|
08-17-2014, 04:11 AM
|
#7
|
Senior Member
Registered: Dec 2005
Distribution: Slackware
Posts: 1,135
|
*edit* I'm basically an idiot and wrote my reply before reading what had already been attempted by OP, which is pretty well everything I suggest, so +1 redundant on my part.
Secondly, your issue with special characters sounds like an encoding issue: perhaps the original text file needs to be converted to utf-8.
Code:
$ iconv -f original_charset -t utf-8 originalfile > newfile
To determine the original charset:
Code:
$ file -bi myfile.txt
*******/edit
Apologies for not responding earlier; I'd *forgotten* that I had strayed outside of the slackware forums and haven't checked back here....
Also, my bad, as the ghostscript command I provided only works with certain filetypes, text *not* being one of them (though I believe html is.)
So you can try the gs command with your newly-created html file, or use enscript to convert your original file to ps, then use gs to convert to pdf.
Thusly:
Code:
$ enscript -o <outputfilename> <inputfilename>
Then issue the ghostcript command and hopefully it works.
cheers,
Last edited by mrclisdue; 08-17-2014 at 04:31 AM.
|
|
|
08-18-2014, 11:03 AM
|
#8
|
Member
Registered: Oct 2013
Posts: 37
Original Poster
Rep:
|
mrclisdue, no problem and thank you for trying to help me. Thank you all, guys.
So, mrclisdue, i entered with the commands that you suggested and look the output:
I pasted a text from br.reuters.com/news/ in my test.txt to test your commands.
Quote:
rob@robgeek:~$ txt2html --infile test.txt --outfile test.html
rob@robgeek:~$ gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=test.pdf test.html
Error: /syntaxerror in -file-
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1910 1 3 %oparray_pop 1909 1 3 %oparray_pop 1893 1 3 %oparray_pop 1787 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push
Dictionary stack:
--dict:1162/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Current file position is 1
GPL Ghostscript 9.05: Unrecoverable error, exit code 1
|
Here the images of my test.txt, test.html and test.pdf files.
test.txt: http://postimg.org/image/ut2xk7fo1/
test.html: http://postimg.org/image/fhptaobwd/
test.pdf: A blank document.
-----------------------------------------------------------------------------
Here the images of my test.txt, test.ps and test.pdf files.
Quote:
rob@robgeek:~$ enscript -o test.ps test.txt
[ 1 page * 1 copy ] left in test.ps
4 lines were wrapped
1 non-printable character
rob@robgeek:~$ gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=test.pdf test.ps
|
test.txt: The same from above.
test.ps: http://postimg.org/image/8dgrxlzlr/
test.pdf: http://postimg.org/image/xi6rx6wkv/
|
|
|
08-18-2014, 10:40 PM
|
#9
|
Senior Member
Registered: Dec 2005
Distribution: Slackware
Posts: 1,135
|
As per the post you replied to, I *believe* you may need to convert your original txt file to utf-8 before conversion to ps, using iconv, or is that not the issue?
cheers,
|
|
|
08-19-2014, 02:22 AM
|
#10
|
Member
Registered: Aug 2014
Location: Virginia, USA
Posts: 51
Rep:
|
If you are just trying to turn a txt file to pdf simply and there is not a specific reason to use a command line, print it to a pdf file. It's a built-in utility.
|
|
|
08-19-2014, 12:22 PM
|
#11
|
Member
Registered: Oct 2013
Posts: 37
Original Poster
Rep:
|
Quote:
Originally Posted by mrclisdue
As per the post you replied to, I *believe* you may need to convert your original txt file to utf-8 before conversion to ps, using iconv, or is that not the issue?
cheers,
|
But when i enter with the following command in terminal, look the output.
Quote:
rob@robgeek:~$ file -i test.txt
test.txt: text/plain; charset=utf-8
|
|
|
|
08-21-2014, 04:54 PM
|
#12
|
Senior Member
Registered: Dec 2005
Distribution: Slackware
Posts: 1,135
|
It turns out that enscript *doesn't* support UTF-8, as per this link:
http://www.linuxfromscratch.org/blfs.../enscript.html
As per the same link, the solution is to install paps. If it isn't in your repo, you can download the source and install.
Then:
Code:
$ paps <inputfilename> > outputfile.ps
Then run the gs command.
I just tried it and it works!
cheers,
|
|
|
08-22-2014, 12:58 PM
|
#13
|
Member
Registered: Oct 2013
Posts: 37
Original Poster
Rep:
|
Quote:
Originally Posted by mrclisdue
It turns out that enscript *doesn't* support UTF-8, as per this link:
http://www.linuxfromscratch.org/blfs.../enscript.html
As per the same link, the solution is to install paps. If it isn't in your repo, you can download the source and install.
Then:
Code:
$ paps <inputfilename> > outputfile.ps
Then run the gs command.
I just tried it and it works!
cheers,
|
With paps worked fine, thank you! I'll try to find an alternative app that converts .txt -> html that upports utf-8. Thus all "technics i tried will have been resolved.
|
|
|
All times are GMT -5. The time now is 06:25 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|