LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 02:42 AM   #1
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Rep: Reputation: 73
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, 02:59 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

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

Original Poster
Rep: Reputation: 73
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



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

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

All times are GMT -5. The time now is 09:26 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
Open Source Consulting | Domain Registration