Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #7004 > unrolled thread

Converting multiple PNG files to single PDF from BASH

Started byzipeppe@gmail.com
First post2013-01-14 00:45 -0800
Last post2013-01-16 14:37 +0000
Articles 14 — 9 participants

Back to article view | Back to comp.os.linux.misc


Contents

  Converting multiple PNG files to single PDF from BASH zipeppe@gmail.com - 2013-01-14 00:45 -0800
    Re: Converting multiple PNG files to single PDF from BASH Tim Watts <tw+usenet@dionic.net> - 2013-01-14 09:00 +0000
    Re: Converting multiple PNG files to single PDF from BASH dave.gma+news002@googlemail.com.invalid (Dave Gibson) - 2013-01-14 09:57 +0000
      Re: Converting multiple PNG files to single PDF from BASH zipeppe@gmail.com - 2013-01-14 02:11 -0800
      Re: Converting multiple PNG files to single PDF from BASH "Peter J. Holzer" <hjp-usenet2@hjp.at> - 2013-01-14 15:42 +0100
    Re: Converting multiple PNG files to single PDF from BASH zipeppe@gmail.com - 2013-01-14 02:08 -0800
      Re: Converting multiple PNG files to single PDF from BASH The Natural Philosopher <tnp@invalid.invalid> - 2013-01-14 10:11 +0000
        Re: Converting multiple PNG files to single PDF from BASH zipeppe@gmail.com - 2013-01-14 04:06 -0800
          Re: Converting multiple PNG files to single PDF from BASH Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2013-01-14 18:32 +0000
      Re: Converting multiple PNG files to single PDF from BASH unruh <unruh@invalid.ca> - 2013-01-14 17:34 +0000
    Re: Converting multiple PNG files to single PDF from BASH unruh <unruh@invalid.ca> - 2013-01-14 17:30 +0000
    Re: Converting multiple PNG files to single PDF from BASH Anonymous <anonymous@foto.nl1.torservers.net> - 2013-01-15 06:12 -0500
    Re: Converting multiple PNG files to single PDF from BASH Anonymous <anonymous@foto.nl1.torservers.net> - 2013-01-15 07:23 -0500
      Re: Converting multiple PNG files to single PDF from BASH J G Miller <miller@yoyo.ORG> - 2013-01-16 14:37 +0000

#7004 — Converting multiple PNG files to single PDF from BASH

Fromzipeppe@gmail.com
Date2013-01-14 00:45 -0800
SubjectConverting multiple PNG files to single PDF from BASH
Message-ID<ab6ef068-4cf6-4fb2-854f-866844d0d9a1@googlegroups.com>
Hi guys,
I am looking for a bash script using 'convert' to convert PNG file to single PDF.
The problem is mainly related to their names which are not numerically sorted:
fig1.png fig2.pnf fig3.png ... fig10.png... fig100.png... fig250.png

The following command creates a PDF file with useless *unsorted* pages:

convert *png book.pdf

It seems that there is no option for the 'convert' to force the piping into a single file..

The following script for the first 20 pages, on the other hand, creates only a single page as output, the last one:

for i in $(seq 20); do convert fig$i.png book.pdf; done

Any suggestion?

[toc] | [next] | [standalone]


#7005

FromTim Watts <tw+usenet@dionic.net>
Date2013-01-14 09:00 +0000
Message-ID<q2ucs9-t6v.ln1@squidward.local.dionic.net>
In reply to#7004
On Monday 14 January 2013 08:45 zipeppe@gmail.com wrote in 
comp.os.linux.misc:

> Hi guys,
> I am looking for a bash script using 'convert' to convert PNG file to
> single PDF. The problem is mainly related to their names which are not
> numerically sorted: fig1.png fig2.pnf fig3.png ... fig10.png...
> fig100.png... fig250.png
> 
> The following command creates a PDF file with useless *unsorted* pages:
> 
> convert *png book.pdf
> 
> It seems that there is no option for the 'convert' to force the piping
> into a single file..
> 
> The following script for the first 20 pages, on the other hand, creates
> only a single page as output, the last one:
> 
> for i in $(seq 20); do convert fig$i.png book.pdf; done
> 
> Any suggestion?

pdftk

I cannot give you a recipe, but that took will almost certainly have a way 
to fix your problem.

-- 
Tim Watts                 Personal Blog: http://www.dionic.net/tim/

"It would be better to live under robber barons than under omnipotent
moral busybodies."

[toc] | [prev] | [next] | [standalone]


#7006

Fromdave.gma+news002@googlemail.com.invalid (Dave Gibson)
Date2013-01-14 09:57 +0000
Message-ID<lc1ds9xp42.ln2@perseus.wenlock-data.co.uk>
In reply to#7004
zipeppe@gmail.com wrote:
> Hi guys,
> I am looking for a bash script using 'convert' to convert PNG file
> to single PDF.
> The problem is mainly related to their names which are not numerically
> sorted:
> fig1.png fig2.pnf fig3.png ... fig10.png... fig100.png... fig250.png
> 
> The following command creates a PDF file with useless *unsorted* pages:
> 
> convert *png book.pdf

The shell sorts generated filename lists.  Use multiple patterns:

  convert fig?.png fig??.png fig???.png book.pdf

[toc] | [prev] | [next] | [standalone]


#7008

Fromzipeppe@gmail.com
Date2013-01-14 02:11 -0800
Message-ID<fcba4d4d-b7dc-41a7-89a3-102570298bdb@googlegroups.com>
In reply to#7006
Il giorno lunedì 14 gennaio 2013 10:57:09 UTC+1, Dave Gibson ha scritto:
> zipeppe@gmail.com wrote:
> 
> > Hi guys,
> 
> > I am looking for a bash script using 'convert' to convert PNG file
> 
> > to single PDF.
> 
> > The problem is mainly related to their names which are not numerically
> 
> > sorted:
> 
> > fig1.png fig2.pnf fig3.png ... fig10.png... fig100.png... fig250.png
> 
> > 
> 
> > The following command creates a PDF file with useless *unsorted* pages:
> 
> > 
> 
> > convert *png book.pdf
> 
> 
> 
> The shell sorts generated filename lists.  Use multiple patterns:
> 
> 
> 
>   convert fig?.png fig??.png fig???.png book.pdf

YES, this worked!

Thank you ;-)

[toc] | [prev] | [next] | [standalone]


#7011

From"Peter J. Holzer" <hjp-usenet2@hjp.at>
Date2013-01-14 15:42 +0100
Message-ID<slrnkf86af.n4u.hjp-usenet2@hrunkner.hjp.at>
In reply to#7006
On 2013-01-14 09:57, Dave Gibson <dave.gma+news002@googlemail.com.invalid> wrote:
> zipeppe@gmail.com wrote:
>> Hi guys,
>> I am looking for a bash script using 'convert' to convert PNG file
>> to single PDF.
>> The problem is mainly related to their names which are not numerically
>> sorted:
>> fig1.png fig2.pnf fig3.png ... fig10.png... fig100.png... fig250.png
>> 
>> The following command creates a PDF file with useless *unsorted* pages:
>> 
>> convert *png book.pdf
>
> The shell sorts generated filename lists.  Use multiple patterns:
>
>   convert fig?.png fig??.png fig???.png book.pdf

Or use ls to sort them in numerical ("version") order:

convert $(ls -v fig*.png) book.pdf

or maybe you want to sort them by date:

convert $(ls -tr fig*.png) book.pdf

Or by size:

convert $(ls -S fig*.png) book.pdf

(just kidding)

	hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) | Sysadmin WSR       | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel

[toc] | [prev] | [next] | [standalone]


#7007

Fromzipeppe@gmail.com
Date2013-01-14 02:08 -0800
Message-ID<19788834-7298-44a9-b93b-e1f0bff7f8c8@googlegroups.com>
In reply to#7004
Il giorno lunedì 14 gennaio 2013 09:45:47 UTC+1, zip...@gmail.com ha scritto:
> Hi guys,
> 
> I am looking for a bash script using 'convert' to convert PNG file to single PDF.
> 
> The problem is mainly related to their names which are not numerically sorted:
> 
> fig1.png fig2.pnf fig3.png ... fig10.png... fig100.png... fig250.png
> 
> 
> 
> The following command creates a PDF file with useless *unsorted* pages:
> 
> 
> 
> convert *png book.pdf
> 
> 
> 
> It seems that there is no option for the 'convert' to force the piping into a single file..
> 
> 
> 
> The following script for the first 20 pages, on the other hand, creates only a single page as output, the last one:
> 
> 
> 
> for i in $(seq 20); do convert fig$i.png book.pdf; done
> 
> 
> 
> Any suggestion?

Thank you Tim,

I guess the problem is related to the 'enumeration' of such files, and pdftk has the same limitation of the convert command: once it has executed, the output does not follow the natural numeration fig1* fig2* .. fig10* but the following:

fig10.png
fig11.png
fig12.png
fig13.png
fig14.png
...
fig19.png
fig1.png
fig20.png
...


[toc] | [prev] | [next] | [standalone]


#7009

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-01-14 10:11 +0000
Message-ID<kd0lku$cqd$1@news.albasani.net>
In reply to#7007
On 14/01/13 10:08, zipeppe@gmail.com wrote:
> Il giorno lunedì 14 gennaio 2013 09:45:47 UTC+1, zip...@gmail.com ha scritto:
>> Hi guys,
>>
>> I am looking for a bash script using 'convert' to convert PNG file to single PDF.
>>
>> The problem is mainly related to their names which are not numerically sorted:
>>
>> fig1.png fig2.pnf fig3.png ... fig10.png... fig100.png... fig250.png
>>
>>
>>
>> The following command creates a PDF file with useless *unsorted* pages:
>>
>>
>>
>> convert *png book.pdf
>>
>>
>>
>> It seems that there is no option for the 'convert' to force the piping into a single file..
>>
>>
>>
>> The following script for the first 20 pages, on the other hand, creates only a single page as output, the last one:
>>
>>
>>
>> for i in $(seq 20); do convert fig$i.png book.pdf; done
>>
>>
>>
>> Any suggestion?
>
> Thank you Tim,
>
> I guess the problem is related to the 'enumeration' of such files, and pdftk has the same limitation of the convert command: once it has executed, the output does not follow the natural numeration fig1* fig2* .. fig10* but the following:
>
> fig10.png
> fig11.png
> fig12.png
> fig13.png
> fig14.png
> ...
> fig19.png
> fig1.png
> fig20.png
> ...
>
>
>
well thats a bit of awk or shell or summat to sort them ..



-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#7010

Fromzipeppe@gmail.com
Date2013-01-14 04:06 -0800
Message-ID<5ea363e0-2960-4298-a321-832f8393862f@googlegroups.com>
In reply to#7009
> 
> well thats a bit of awk or shell or summat to sort them ..


Help me to learn how please...

[toc] | [prev] | [next] | [standalone]


#7014

FromLoki Harfagr <l0k1@thedarkdesign.free.fr.INVALID>
Date2013-01-14 18:32 +0000
Message-ID<pan.2013.01.14.18.32.29@thedarkdesign.free.fr.INVALID>
In reply to#7010
Mon, 14 Jan 2013 04:06:26 -0800, zipeppe did cat :

>> 
>> well thats a bit of awk or shell or summat to sort them ..
> 
> 
> Help me to learn how please...

ah well, let's try it for a start, here's a PoC of a possible way:
----------
$ ls | awk '
{
  ix=sprintf("%020d",0+$NF)
  nym[ix $0]=$0
}
END{
  for(i in nym) print i,nym[i]
}
' FS='[a-zA-Z]*' | sort -n | cut -d" " -f2- | tr '\n' ' ' && echo ""
----------

since you're interested in learning "summat" aka "kinashellstof"
it might be an interesting POV to use 4 and a half tool off the box
in that example ;-)
(you may do it strictly in awk but with that starter it may add
up some problems (like adding asort[i] (¹)) if you're a genuine rookie(b)
and were not just being tongue in tail or cheek against 'zipeppe' ;-)

 Note that this PoC goes a different path than the 'ls -v' solution (*)
(which I'd think would be the best one in the case exposed but as you
asked for some information about how...) just for the sake of it and
in the case it'd be of some use (at least the idea not the code fershure)



¹ hence needing not much further obfuscation if (b) true ;D)

(*) any doubt about that point, make/goto some disposable dir and play with:
$ for ll in {7..13} ; do touch "ff$ll" "fff$ll" "fg$ll" ; done

PMS:
 xposting to `cla` since the PoC is quite based on awk but FU2 kept in place

[toc] | [prev] | [next] | [standalone]


#7013

Fromunruh <unruh@invalid.ca>
Date2013-01-14 17:34 +0000
Message-ID<rkXIs.97759$2v.31626@newsfe05.iad>
In reply to#7007
On 2013-01-14, zipeppe@gmail.com <zipeppe@gmail.com> wrote:
> Il giorno luned? 14 gennaio 2013 09:45:47 UTC+1, zip...@gmail.com ha scritto:
>
> Thank you Tim,
>
> I guess the problem is related to the 'enumeration' of such files, and pdftk has the same limitation of the convert command: once it has executed, the output does not follow the natural numeration fig1* fig2* .. fig10* but the following:
>
> fig10.png
> fig11.png
> fig12.png
> fig13.png
> fig14.png
> ...
> fig19.png
> fig1.png
> fig20.png
> ...
>

That has nothing to do with pdftk or convert. The * expansion is done by
the shell, long before the commands see the arguments. And the ordering
IS lexicagraphical. . occurs in the sort order AFTER all numbers, not
before. So it is sorted after the numbers. 1. comes after 19

>
>

[toc] | [prev] | [next] | [standalone]


#7012

Fromunruh <unruh@invalid.ca>
Date2013-01-14 17:30 +0000
Message-ID<0hXIs.51953$On7.15662@newsfe16.iad>
In reply to#7004
On 2013-01-14, zipeppe@gmail.com <zipeppe@gmail.com> wrote:
> Hi guys,
> I am looking for a bash script using 'convert' to convert PNG file to single PDF.
> The problem is mainly related to their names which are not numerically sorted:
> fig1.png fig2.pnf fig3.png ... fig10.png... fig100.png... fig250.png
>
> The following command creates a PDF file with useless *unsorted* pages:
>
> convert *png book.pdf

No, that is sorted. It is lexigraphically sorted. It is in fact very
hard to sort numbers as you have given them 
You could do
convert fig[0-9].png fig[0-9][0-9].png fig[0-9][0-9][0-9].png book.pdf


>
> It seems that there is no option for the 'convert' to force the piping into a single file..
>
> The following script for the first 20 pages, on the other hand, creates only a single page as output, the last one:
>
> for i in $(seq 20); do convert fig$i.png book.pdf; done

of course. Each time you run it, it replaces book.pdf with a new one. 

>
> Any suggestion?
>
>

[toc] | [prev] | [next] | [standalone]


#7021

FromAnonymous <anonymous@foto.nl1.torservers.net>
Date2013-01-15 06:12 -0500
Message-ID<23acb2f084a1f52d7cd9af51028b086b@foto.nl1.torservers.net>
In reply to#7004
zipe...@gmail.com <zipe...@gmail.com> [z]:
z> The problem is mainly related to their names which are not numerically 
z> sorted:
z> fig1.png fig2.png fig3.png ... fig10.png... fig100.png... fig250.png

Use rename twice:

$ $ rename -V
rename from util-linux 2.22.1
$ rename fig fig0 fig?.png
$ rename fig fig0 fig??.png

$ ls -1
fig001.png
fig002.png
fig003.png
..
fig010.png
..
fig100.png
..
fig250.png

[toc] | [prev] | [next] | [standalone]


#7022

FromAnonymous <anonymous@foto.nl1.torservers.net>
Date2013-01-15 07:23 -0500
Message-ID<13246e55f19ba3ce27bd670a95326420@foto.nl1.torservers.net>
In reply to#7004
Or use awk to build a file renaming script:

$ ls *.png |
awk -v digits=3 -v Q="'" '
{
prefix="";number="";suffix="";
prefix=substr($0,1,match($0,"[0-9]")-1);		# part before digits
number=substr($0,length(prefix)+1);
number=substr(number,1,match(number,"[^0-9]|$")-1);	# digits part
suffix=substr($0,length(prefix)+length(number)+1); 	# part after digits
if (number!="") {
	printf "mv " Q "%s" Q "\t" Q "%s%0" digits "s%s" Q "\n",
		$0, prefix, number, suffix;
} else { print "#"$0; }
}
'
mv 'fig1.png'   'fig001.png'
mv 'fig10.png'  'fig010.png'
mv 'fig100.png' 'fig100.png'
mv 'fig2.png'   'fig002.png'
mv 'fig250.png' 'fig250.png'
mv 'fig3.png'   'fig003.png'

[toc] | [prev] | [next] | [standalone]


#7035

FromJ G Miller <miller@yoyo.ORG>
Date2013-01-16 14:37 +0000
Message-ID<kd6e06$625$2@dont-email.me>
In reply to#7022
On Tuesday, January 15th, 2013, at 07:23:06h -0500, Anonymous suggested:

> Or use awk to build a file renaming script:

Or install mmv.  ;)

Available as a package on most major distributions.

QUOTE

  mmv is a program to move/copy/append/link multiple files
  according to a set of wildcard patterns. This multiple
  action is performed safely, i.e. without any unexpected
  deletion of files due to collisions of target names with
  existing filenames or with other target names.


UNQUOTE

[toc] | [prev] | [standalone]


Back to top | Article view | comp.os.linux.misc


csiph-web