LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-16-2018, 03:42 AM   #1
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 18.04
Posts: 1,789

Rep: Reputation: 67
batch convert text files to pdf


I have some simple text files. I want to print them using Python and the module cups. This cups python module can't handle .odt or .docx.

Quote:
>>> conn.printFile('EPSON-L350-Series', '/home/pedro/getEmailtexts/stragglers/17BElate.odt', 'test', {})
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
conn.printFile('EPSON-L350-Series', '/home/pedro/getEmailtexts/stragglers/17BElate.odt', 'test', {})
cups.IPPError: (1034, 'Unsupported document-format "application/vnd.oasis.opendocument.text".')
If I print the text file, it prints right along the top edge of the page and almost on the right edge of the page.

This prints the pdf in Python:

Quote:
conn.printFile('EPSON-L350-Series', '/home/pedro/getEmailtexts/stragglers/17BElate.pdf', 'test', {})
If I print as pdf in Python, it looks ok. So I need to convert 300+ text files to pdf.

I have the python module text2pdf, but I can't find docs to show the usage. However, in bash text2pdf works.

Quote:
pedro@pedro-newssd:~/getEmailtexts/stragglers$ text2pdf -o 17BElate.pdf 17BElate.txt
So I just need to batch this command for bash and convert the whole directory contents.

Any tips please??
 
Old 12-16-2018, 03:59 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,400
Blog Entries: 9

Rep: Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655Reputation: 3655
Code:
for i in *.txt; do text2pdf -o "$i".pdf "$i"; done
 
1 members found this post helpful.
Old 12-16-2018, 06:43 AM   #3
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 18.04
Posts: 1,789

Original Poster
Rep: Reputation: 67
Thanks, works like a dream. In the pdf the text has the top cut off a bit, but it prints ok!

Thanks a lot!
 
  


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
Convert DOS text files to UNIX text files ta0kira Linux - Software 7 03-15-2011 12:42 PM
[SOLVED] Batch Convert Linux Text Format to RTF? Super TWiT Linux - Software 4 08-27-2010 02:37 PM
Batch images to pdf / pdf to txt geeeeky.girl Linux - Software 10 12-24-2009 02:40 AM
Software to batch convert CBR, CBZ files to PDF format JTAL604622 Linux - Software 1 06-11-2007 07:33 PM

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

All times are GMT -5. The time now is 10:59 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration