GUI file converter app and its commands

Here is where you can post tips and tricks to share with other users of MX. Do not ask for help in this Forum.
Message
Author
TimothySimon
Posts: 93
Joined: Fri Sep 10, 2021 2:16 am

GUI file converter app and its commands

#1 Post by TimothySimon »

GUI file Converter App

viewtopic.php?p=653310#p653310

https://github.com/TimothySimon123/file-converter

Commands
TL; DR

Code: Select all

 find . -maxdepth 1 -iname '*.pdf' | xargs -I{} pdftoppm {} -jpeg {}
converts all files ending with .pdf (case-insensitive) in the current directory to JPGs (each page is a separate jpg , with the page number in the file name.

Code: Select all

sudo apt install poppler-utils
if you don't have it installed (MX Linux comes with this by default)


If you don't understand the above, here is the newbie-friendly version:
When you're within the folder containing all PDFs, Right click on the empty space, open terminal here, then type (or Right click -> Paste) this command , followed by an Enter :

Code: Select all

echo "Please wait. Converting......... Do NOT close this terminal" ;  find . -maxdepth 1 -iname '*.pdf' | xargs -I{} pdftoppm {} -jpeg {} ; echo "Finished conversion. Please close this Terminal"
The output files are named like this: MyFile.pdf-1.jpg (means Page 1 of MyFile.pdf)

To convert just the first page of each pdf (Ignores all other pages)

Code: Select all

echo "Please wait. Converting......... Do NOT close this terminal" ; find . -maxdepth 1 -iname '*.pdf' | xargs -I{} pdftoppm -singlefile {} -jpeg {} ; echo "Finished conversion. Please close this Terminal"
Long description

This is forked off from viewtopic.php?p=652929#p652929 .
My original reply was viewtopic.php?p=652987#p652987 .
Huckleberry Finn wrote: Thu Sep 16, 2021 12:15 pm This one is really handy , simple, requiring no extra software .. perfect indeed.

I'm also surprised how there's nothing easy to "batch" convert ..

So, maybe you put this in tips & tricks..
................
--- @ Huckleberry Finn

This command just applies this ( pdftoppm -jpeg ) for all PDF files in that folder (with find piping to pdftoppm via xargs)

More generally, we can use

Code: Select all

find <something_to_find> | xargs -I{} some_command {} 
to apply some_command (which may be a conversion or something else) to all the files found by find(1)
xargs will replace {} with the paths of matching files (supplied from find's stdout to xarg's stdin)
Even more generally, this is just using xargs -I{}

find -iname means that the match is case-insensitive (matches .PDF , .pdf , .Pdf , .PdF etc.,)
xargs -I{} means to replace all occurences of {} with the current line from stdin (and repeat the command for each line)

Ref: $ man xargs , $ man find

EDIT 1: I learnt from man xargs that -i is deprecated. Edited command to use -I{}

I added the echo's as a "newbie guard" to stop people from closing the terminal thinking the job is over (some people don't know when a command finishes its job), and this command may take a lot of time

Only a very minor drawback -- the output names are something like this: MyFile.pdf.jpg-1.jpg
EDIT: @Huckleberry Finn fixed that.
Amigo wrote: Thu Sep 16, 2021 2:08 pm https://askubuntu.com/questions/1162790 ... pm-in-ubun
find . -maxdepth 1 -type f -name '*.pdf' -exec pdftoppm -jpeg {} {} \;
Done, you will find the new converted jpg files in the same directory alongside the old pdf files.
EDIT 2: Learnt that there is a similar way on another forum.
EDIT 3: Incorporated good things from that (-maxdepth 1 -type f)
Huckleberry Finn wrote: Fri Sep 17, 2021 10:13 am So, @TimothySimon : My humble suggestion for next "dot release" :D is:

Replace the main command with @Amigo 's

(And) While you're at it: 2 Options:

"Convert All Pages"

"Convert just First Pages" (of each file)


One with

ls *.pdf | sed 's|\.pdf||' | xargs -I{} pdftoppm {}.pdf -jpeg {}

The other

ls *.pdf | sed 's|\.pdf||' | xargs -I{} pdftoppm -singlefile {}.pdf -jpeg {}
EDIT 4: Incorporated good things from commands given by @Amigo and @Huckleberry Finn
Last edited by TimothySimon on Sun Sep 19, 2021 12:57 am, edited 7 times in total.

SwampRabbit
Posts: 3602
Joined: Tue Jun 14, 2016 2:02 pm

Re: Batch convert PDF to JPG (or X file format to Y)

#2 Post by SwampRabbit »

Nice work, this would be really cool as a YAD script. I seem to recall that there might already be something like it (or close to it out there).
NEW USERS START HERE FAQS, MX Manual, and How to Break Your System - Don't use Ubuntu PPAs! Always post your Quick System Info (QSI) when asking for help.

TimothySimon
Posts: 93
Joined: Fri Sep 10, 2021 2:16 am

Re: Batch convert PDF to JPG (or X file format to Y)

#3 Post by TimothySimon »

SwampRabbit wrote: Thu Sep 16, 2021 1:52 pm Nice work, this would be really cool as a YAD script. I seem to recall that there might already be something like it (or close to it out there).
Or still better, I dream of a FOSS Qt/C++ GUI app to convert between various formats.
(just for Linux :cool: )

If you want, I'm ready to help with my limited Qt/C++ knowledge.
(It'll also be a good exercise for me -- I'm studying these as part of my coursework)

SwampRabbit
Posts: 3602
Joined: Tue Jun 14, 2016 2:02 pm

Re: Batch convert PDF to JPG (or X file format to Y)

#4 Post by SwampRabbit »

TimothySimon wrote: Thu Sep 16, 2021 2:06 pm If you want, I'm ready to help with my limited Qt/C++ knowledge.
(It'll also be a good exercise for me -- I'm studying these as part of my coursework)
That makes two of us, well the “limited”, not the course work. :p

Install QtCreator if you haven’t already, that’s at least a start.

Edited for typo
Last edited by SwampRabbit on Thu Sep 16, 2021 2:20 pm, edited 1 time in total.
NEW USERS START HERE FAQS, MX Manual, and How to Break Your System - Don't use Ubuntu PPAs! Always post your Quick System Info (QSI) when asking for help.

TimothySimon
Posts: 93
Joined: Fri Sep 10, 2021 2:16 am

Re: Batch convert PDF to JPG (or X file format to Y)

#5 Post by TimothySimon »

SwampRabbit wrote: Thu Sep 16, 2021 2:13 pm
TimothySimon wrote: Thu Sep 16, 2021 2:06 pm If you want, I'm ready to help with my limited Qt/C++ knowledge.
(It'll also be a good exercise for me -- I'm studying these as part of my coursework)
That makes two of us, we’ll the “limited”, not the course work. :p

Install QtCreator if you haven’t already, that’s at least a start.
qtcreator is already installed.
viewtopic.php?f=108&t=66370
viewtopic.php?f=77&t=66324

So here we go ......... (?)

NOTE: I don't know the ways of programing as a team (git etc.,) . I would like to study that too.

Please PM me if you need to.

BTW: It is about 12 midnight in my part of the world (+0530)

SwampRabbit
Posts: 3602
Joined: Tue Jun 14, 2016 2:02 pm

Re: Batch convert PDF to JPG (or X file format to Y)

#6 Post by SwampRabbit »

Don’t worry about time, there is no rush for anything. ;)

I PM’d you and can help with what I know and have time for.
NEW USERS START HERE FAQS, MX Manual, and How to Break Your System - Don't use Ubuntu PPAs! Always post your Quick System Info (QSI) when asking for help.

TimothySimon
Posts: 93
Joined: Fri Sep 10, 2021 2:16 am

Re: Batch convert PDF to JPG (or X file format to Y)

#7 Post by TimothySimon »

SwampRabbit wrote: Thu Sep 16, 2021 2:29 pm Don’t worry about time, there is no rush for anything. ;)

I PM’d you and can help with what I know and have time for.
Here is my simple YAD GUI to convert PDF to JPG:
https://github.com/TimothySimon123/pdf2jpg
Lets call this pdf2jpg version 0.1 alpha

Just download pdf2jpg.sh and pdf2jpg-helper.sh int the same directory.
Launch pdf2jpg.sh to use it.

Features:
- Drag and drop
- Easy bulk conversion
- Progress meter

Please give your valuable suggestions and comments.

User avatar
Jerry3904
Administrator
Posts: 23619
Joined: Wed Jul 19, 2006 6:13 am

Re: Batch convert PDF to JPG (or X file format to Y)

#8 Post by Jerry3904 »

It works, thanks for posting. I will be able to give good feedback tomorrow, but I'm on the road all day today.

One general observation: I find that the directions could use some editing. For instance, "drag and drop here" seems to mean "click here to select files for conversion." I at least was unable to drag and drop in the usual sense.
Production: MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: MX-25 Fluxbox, ThinkPad X1 Carbon gen 9 with i7
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

Huckleberry Finn

Re: Batch convert PDF to JPG (or X file format to Y)

#9 Post by Huckleberry Finn »

Just.. drag works but it shows the window empty.. In my case I dragged & dropped, then clicked ok (as if it showed dropped files) :)

Huckleberry Finn

Re: Batch convert PDF to JPG (or X file format to Y)

#10 Post by Huckleberry Finn »

So, @TimothySimon : My humble suggestion for next "dot release" :D is:

Replace the main command with @Amigo 's

(And) While you're at it: 2 Options:

"Convert All Pages"

"Convert just First Pages" (of each file)


One with

ls *.pdf | sed 's|\.pdf||' | xargs -I{} pdftoppm {}.pdf -jpeg {}

The other

ls *.pdf | sed 's|\.pdf||' | xargs -I{} pdftoppm -singlefile {}.pdf -jpeg {}

Post Reply

Return to “Tips & Tricks by users (not for help)”