LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 08-15-2014, 09:52 PM   #1
robgeek
Member
 
Registered: Oct 2013
Posts: 37

Rep: Reputation: Disabled
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.
 
Old 08-15-2014, 10:34 PM   #2
mrclisdue
Senior Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 1,135

Rep: Reputation: 277Reputation: 277Reputation: 277
Ghostscript (which I imagine would be part of your install)

Code:
gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=<newfilename>.pdf <inputfilenameshere>
cheers,
 
Old 08-16-2014, 01:18 AM   #3
robgeek
Member
 
Registered: Oct 2013
Posts: 37

Original Poster
Rep: Reputation: Disabled
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
 
Old 08-16-2014, 04:29 AM   #4
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
Maybe you'll find something here: https://www.google.com/search?hl=en&...to+pdf%3Alinux
jdk
 
Old 08-16-2014, 08:35 AM   #5
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,461

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
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.
 
Old 08-16-2014, 07:33 PM   #6
robgeek
Member
 
Registered: Oct 2013
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Guttorm View Post
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?
 
Old 08-17-2014, 04:11 AM   #7
mrclisdue
Senior Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 1,135

Rep: Reputation: 277Reputation: 277Reputation: 277
*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.
 
Old 08-18-2014, 11:03 AM   #8
robgeek
Member
 
Registered: Oct 2013
Posts: 37

Original Poster
Rep: Reputation: Disabled
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/
 
Old 08-18-2014, 10:40 PM   #9
mrclisdue
Senior Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 1,135

Rep: Reputation: 277Reputation: 277Reputation: 277
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,
 
Old 08-19-2014, 02:22 AM   #10
fixer1234
Member
 
Registered: Aug 2014
Location: Virginia, USA
Posts: 51

Rep: Reputation: Disabled
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.
 
Old 08-19-2014, 12:22 PM   #11
robgeek
Member
 
Registered: Oct 2013
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by mrclisdue View Post
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
 
Old 08-21-2014, 04:54 PM   #12
mrclisdue
Senior Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 1,135

Rep: Reputation: 277Reputation: 277Reputation: 277
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,
 
Old 08-22-2014, 12:58 PM   #13
robgeek
Member
 
Registered: Oct 2013
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by mrclisdue View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me choose an app that converts images into PDF files GuiRitter General 5 03-30-2012 09:04 PM
Batch images to pdf / pdf to txt geeeeky.girl Linux - Software 10 12-24-2009 02:40 AM
LXer: OggConvert makes Ogg converts (and converts to Oggs) LXer Syndicated Linux News 0 12-22-2007 07:00 AM
Convert pdf to html or txt or remaster the pdf? jago25_98 Linux - Software 1 12-13-2005 02:11 AM
Convertible... Converts.... No Wait - I know! Conversion Utilites (TXT/PDF) Nimoy Linux - Software 4 08-30-2003 02:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration