LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-12-2018, 01:30 PM   #1
Keruskerfuerst
Senior Member
 
Registered: Oct 2005
Location: Horgau, Germany
Distribution: Manjaro KDE, Win 10
Posts: 2,199

Rep: Reputation: 164Reputation: 164
Libreoffice: convert a dir with 3247 *.odt files in 1171 folders to *.pdf


Is it possible to convert a directory with 3247 files in 1171 folders to *.pdf ?
 
Old 08-12-2018, 01:57 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,750

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
Probably. Please put "convert odt to pdf" into your favorite search engine and see if any of the many links is helpful.

This one looked useful...

Last edited by scasey; 08-12-2018 at 02:04 PM.
 
Old 08-12-2018, 01:59 PM   #3
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Rep: Reputation: 190Reputation: 190
Something like
Code:
for file in *.odt
do
  mv "$file" "${file%.odt}.pdf"
done
should do it. But take that with a grain of salt I'm no expert

Last edited by TheEzekielProject; 08-12-2018 at 02:22 PM.
 
Old 08-12-2018, 02:06 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,750

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
Quote:
Originally Posted by TheEzekielProject View Post
Something like
Code:
for file in *.odt
do
  mv "$file" "${file%.odt}.pdf"
done
should do it. But take that with a grain of salt I'm no expert
I'm pretty sure that moving a file and changing its name is NOT going to convert its type.
 
Old 08-12-2018, 02:19 PM   #5
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by scasey View Post
I'm pretty sure that moving a file and changing its name is NOT going to convert its type.
I tested this on some files and it seems to have worked as expected. However, it does not work recursively through directories.


EDIT: Scratch that. While my file manager showed it as pdf, running
Code:
file testfile
still showed it as an OpenDocument Text file

Last edited by TheEzekielProject; 08-12-2018 at 02:31 PM.
 
Old 08-12-2018, 02:40 PM   #6
Keruskerfuerst
Senior Member
 
Registered: Oct 2005
Location: Horgau, Germany
Distribution: Manjaro KDE, Win 10
Posts: 2,199

Original Poster
Rep: Reputation: 164Reputation: 164
I installed unoconv,
but how do I get through the directory tree and get the file names?
 
Old 08-12-2018, 06:57 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,750

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
Quote:
Originally Posted by Keruskerfuerst View Post
I installed unoconv,
but how do I get through the directory tree and get the file names?
You'll probably need to write a script.

cd to top directory
get list of directory names
for each directory
cd to directory
find files
execute unoconv on each file

...or something along those lines
 
Old 08-12-2018, 07:29 PM   #8
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
It is very simple. This is the command line command:
Code:
libreoffice --headless --convert-to pdf *.odt
I use LO 4.3.3. OO or LO has the habit to change their GUI interface and CLI in the most surprising ways, not upward compatible and badly documented. But at least now you know what to search for.

To traverse a directory tree, do something like:
Code:
find /path/to/start/ -name "*.odt" -exec libreoffice --headless --convert-to pdf "{}" \;
I recommend to test this on a test tree first. The quotes around {} are probably needed to protect file names containing spaces.

jlinkels

Last edited by jlinkels; 08-12-2018 at 07:32 PM.
 
3 members found this post helpful.
Old 08-13-2018, 07:54 AM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,153

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Cute jlinkels, never needed this (so far), but ya never know ...
 
Old 08-13-2018, 08:21 AM   #10
Keruskerfuerst
Senior Member
 
Registered: Oct 2005
Location: Horgau, Germany
Distribution: Manjaro KDE, Win 10
Posts: 2,199

Original Poster
Rep: Reputation: 164Reputation: 164
Thanks for the script!

This script works for far, but
The output path must be in the path, where the files have been found.

Sorry, but I have not studied informatics (I am using Linux for 20 years now and have also used Gentoo).
 
Old 08-13-2018, 10:26 AM   #11
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Create a file odt2pdf.sh in your current directory with this contents:
Code:
#! /bin/bash
libreoffice --headless --convert-to pdf --outdir $(dirname "$1") "$1"
exit
Save the file and:
Code:
chmod +x odt2pdf.sh
Then run the command in the same directory where you created odt2pdf.sh:
Code:
find /tmp -name "*.odt"  -exec ./odt2pdf.sh "{}"  \;
Some person smarter than me might be able to enter this command right in the -exec part of the find command. But find is quite picky when it comes to the syntax of the -exec command. So I could not and did not have the time. It works with this separate bash file.

Code:
find /tmp -name "*.odt"  -exec /path/to/odt2pdf.sh "{}"  \;
should work as well. Please test.

jlinkels

Last edited by jlinkels; 08-13-2018 at 10:28 AM.
 
1 members found this post helpful.
Old 08-13-2018, 11:26 AM   #12
Keruskerfuerst
Senior Member
 
Registered: Oct 2005
Location: Horgau, Germany
Distribution: Manjaro KDE, Win 10
Posts: 2,199

Original Poster
Rep: Reputation: 164Reputation: 164
Thanks!

The script works as expected.
 
Old 08-18-2018, 12:20 PM   #13
Keruskerfuerst
Senior Member
 
Registered: Oct 2005
Location: Horgau, Germany
Distribution: Manjaro KDE, Win 10
Posts: 2,199

Original Poster
Rep: Reputation: 164Reputation: 164
Now I only need to delete the remaining *.odt files with the following small script:

Code:
#! /bin/bash
find /path/to/dir/ -name "*.odt" -exec rm -rv {} \;
exit
 
Old 08-18-2018, 01:03 PM   #14
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 483

Rep: Reputation: 153Reputation: 153
Quote:
Something like
Code:

for file in *.odt
do
mv "$file" "${file%.odt}.pdf"
done

should do it. But take that with a grain of salt I'm no expert
This was without a doubt the worst thing I have seen in this forum for a while. Changing an extension does not change a word processing file to an Adobe pdf. You need LibreOffice to export the pdf.

Quote:
I tested this on some files and it seems to have worked as expected. However, it does not work recursively through directories.
You mean it changes the file extension as expected.

Quote:
EDIT: Scratch that. While my file manager showed it as pdf, running
Code:

file testfile

still showed it as an OpenDocument Text file
No kidding. So changing the extension of a file does not change its contents. Shocking. Why do you post on this forum ?
 
Old 08-18-2018, 01:18 PM   #15
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Quote:
Originally Posted by Keruskerfuerst View Post
Now I only need to delete the remaining *.odt files with the following small script:

Code:
#! /bin/bash
find /path/to/dir/ -name "*.odt" -exec rm -rv {} \;
exit
The -r is not needed for the rm at all. See "man rm".

In fact if you also check the manual page for find you might decide that the -delete option is more appropriate than trying for an -exec option. See "man find" and browse down to -delete
 
  


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
Strange (scary) problem with LibreOffice locking up all .odt files Gregg Bell Linux - Newbie 6 12-26-2016 02:33 PM
How to convert files from HTML to .odt gordont8 Linux - Software 7 09-28-2014 04:25 PM
[SOLVED] Libreoffice - how can I convert many odt files to doc or pdf automatically? charlemagne-is-my-son Linux - Software 3 12-10-2012 11:32 AM
Firefox not opening ODT files in Libreoffice comcastuser Linux - Software 19 04-30-2011 06:18 AM
Convert ODT to PDF CartmanYO Linux - Software 10 12-13-2009 08:56 PM

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

All times are GMT -5. The time now is 05:54 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