LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-29-2007, 06:09 PM   #1
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,427

Rep: Reputation: 53
How to print/save a bundle of .png files as a single .pdf file


Hi folks,

Ubuntu Desktop 7.04
Gnome desktop


I have a bundle of .png files, about 30 files. I need to print all of them together as a single .pdf file. I have cup-pdf printer installed. Instead of printing each of them as .pdf file and then adding them together as a single .pdf file afterwards, is there a simple way to do the job??? TIA


B.R.
satimis
 
Old 06-30-2007, 12:04 AM   #2
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
One image per page? You could try this, using the netpbm package. First convert the files to Postscript bitmaps:

pngtopnm image.png | pnmtops > image.ps

pnmtops has options for scaling and so on that you might want to look into (see the man page). Once you are satisfied you can convert the lot using

for i in *.png ; do pngtopnm $i | pnmtops > ${i%.png}.ps ; done

(adding in any options you need). Finally ghostscript will combine everything into a single PDF:

gs -q -dNOPAUSE -dBATCH -sOutputFile=all.pdf -sDEVICE=pdfwrite *.ps

If you want other than alphabetical order you will have to specify the .ps individually as a an argument list.
 
Old 06-30-2007, 02:27 AM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
You could also use ImageMagick.

convert *.png book.mng
convert book.mng book.pdf
 
Old 06-30-2007, 02:37 AM   #4
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Or you just could launch OpenOffice Writer (or any app for that matter that can do pdf), add the images and save/export it as a pdf file. I'm not sure how the output quality depends on the program you do, but this is one way. Of course there are other programs that may do more precise output (Scribus?) but I'm not sure if they export pdf.
 
Old 07-01-2007, 10:39 AM   #5
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,427

Original Poster
Rep: Reputation: 53
Hi maroonbaboon,

Tks for your advice.

Quote:
One image per page?
Yes. There are 29 .png files.

Quote:
You could try this, using the netpbm package.
$ sudo apt-get install netpbm

Quote:
First convert the files to Postscript bitmaps:

pngtopnm image.png | pnmtops > image.ps
$ pngtopnm /path/to/file.png | pnmtops > image.ps

An image.ps file was created. But the document was rotated 90 deg anti-clockwise. I think it was because the page length being not sufficient. Any suggestion ??? TIA

Quote:
pnmtops has options for scaling and so on that you might want to look into (see the man page). Once you are satisfied you can convert the lot using

for i in *.png ; do pngtopnm $i | pnmtops > ${i%.png}.ps ; done

(adding in any options you need). Finally ghostscript will combine everything into a single PDF:

gs -q -dNOPAUSE -dBATCH -sOutputFile=all.pdf -sDEVICE=pdfwrite *.ps
Whether create a script as
Code:
for i in *.png ; do pngtopnm $i | pnmtops > ${i%.png}.ps ; done \
gs -q -dNOPAUSE -dBATCH -sOutputFile=all.pdf -sDEVICE=pdfwrite *.ps
??? Tks.

Quote:
If you want other than alphabetical order you will have to specify the .ps individually as a an argument list.
Can you please explain in more detail. TIA


B.R.
satimis
 
Old 07-01-2007, 10:53 AM   #6
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
To answer your questions:

The pnmtops command can be given an argument -turn or -noturn to determine if it gets rotated 90 degrees. The manual page gives many other options for the command, controlling width, height, scaling, aspect ratio and so on. Try them out on a single image until you have things the way you want.

For the following commands, just run each on its own on the command line. Check what you get after the first. If it's OK, run the second.

As for the order, if your images are called one.ps, two.ps and three.ps and you run the command with argument *.ps this always expands out in alphabetical order, so it is equivalent to

...command... one.ps three.ps two.ps

If that's not what you want you have to list the arguments explicitly in the order you need. If the files are image00.ps, image01.ps, image02.ps etc. you are probably OK with *.ps of course.

The other two solutions posted look reasonable also. I like netpbm because I can control each stage, but if ImageMagick works it may be simpler.
 
Old 07-02-2007, 08:12 PM   #7
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,427

Original Poster
Rep: Reputation: 53
Quote:
Originally Posted by jschiwal
You could also use ImageMagick.

convert *.png book.mng
convert book.mng book.pdf
Hi jschiwal,


Tks for your advice.

$ sudo apt-cache showpkg imagemagick
Code:
Package: imagemagick
Versions: 
7:6.2.4.5.dfsg1-0.14 (/var/lib/apt/lists/hk.archive.ubuntu.com_ubuntu_dists_feisty_main_binary-i386_Packages)
 Description Language: 
                 File: /var/lib/apt/lists/hk.archive.ubuntu.com_ubuntu_dists_feisty_main_binary-i386_Packages
                  MD5: 3a199f3f933e41176706fce9b43cccee

....
.......
.........

Provides: 
7:6.2.4.5.dfsg1-0.14 - 
Reverse Provides: 
graphicsmagick-imagemagick-compat 1.1.7-14
$ sudo apt-get install imagemagick

$ which convert
/usr/bin/convert


$ convert /path/to/dir/* book.mng
$ convert book.mng book.pdf
Done.

A .pdf file created.


Can I run a single command line to do the job;

$ convert /path/to/dir/* | convert - book.pdf
???


TIA


B.R.
satimis
 
Old 07-02-2007, 11:32 PM   #8
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,427

Original Poster
Rep: Reputation: 53
Hi maroonbaboon,

Quote:
The pnmtops command can be given an argument -turn or -noturn to determine if it gets rotated 90 degrees. The manual page gives many other options for the command, controlling width, height, scaling, aspect ratio and so on. Try them out on a single image until you have things the way you want.

For the following commands, just run each on its own on the command line. Check what you get after the first. If it's OK, run the second.
pnmtops -noturn image.ps

works for me. Tks.

Quote:
As for the order, if your images are called one.ps, two.ps and three.ps and you run the command with argument *.ps this always expands out in alphabetical order, so it is equivalent to

...command... one.ps three.ps two.ps

If that's not what you want you have to list the arguments explicitly in the order you need. If the files are image00.ps, image01.ps, image02.ps etc. you are probably OK with *.ps of course.
The files are named as;
file_name01.png
file_name02.png
file_name03.png
etc.

There are 29 files.


Performed following test without result;

1)
$ for i in IDC\ Enterprise\ Panel_20070618/*.png ; do pngtopnm $i | pnmtops > ${i%.png}.ps ; done
Code:
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
etc.

2)
t$ for i in IDC\ Enterprise\ Panel_20070618/* ; do pngtopnm $i | pnmtops > ${i%.png}.ps ; done
Code:
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
pngtopnm: IDC - No such file or directory
bash: ${i%.png}.ps: ambiguous redirect
etc.
Failed.

Quote:
The other two solutions posted look reasonable also. I like netpbm because I can control each stage, but if ImageMagick works it may be simpler.
Noted with tks. I'm interested to learn an alternative with command lines.


B.R.
satimis
 
Old 07-02-2007, 11:35 PM   #9
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,427

Original Poster
Rep: Reputation: 53
Hi b0uncer,

Quote:
Or you just could launch OpenOffice Writer (or any app for that matter that can do pdf), add the images and save/export it as a pdf file. I'm not sure how the output quality depends on the program you do, but this is one way. Of course there are other programs that may do more precise output (Scribus?) but I'm not sure if they export pdf.
Tks for your advice.

The quality of .pdf file created is not good, position shifted.

Scribus is not running on this box.


B.R.
satimis
 
Old 07-03-2007, 12:44 AM   #10
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
You problem is caused by the spaces in the directory name. There are rules for dealing with this in shell commands, but if you are also doing filename expansion (e.g. using * to match filenames) they are not so easy to understand. Better just rename the directory to get rid of the spaces.

If you really want to know the rules, check the manual page for bash, in the section headed QUOTING.
 
Old 07-03-2007, 03:11 AM   #11
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,427

Original Poster
Rep: Reputation: 53
Quote:
Originally Posted by maroonbaboon
You problem is caused by the spaces in the directory name. There are rules for dealing with this in shell commands, but if you are also doing filename expansion (e.g. using * to match filenames) they are not so easy to understand. Better just rename the directory to get rid of the spaces.
Renamed directory as: IDC_Enterprise_Panel_20070618

$ for i in IDC_Enterprise_Panel_20070618/* ; do pngtopnm $i | pnmtops > ${i%.png}.ps ; done
Code:
pnmtops: warning, image too large for page, rescaling to 0.471429
pnmtops: writing color PostScript...
pnmtops: warning, image too large for page, rescaling to 0.471429
pnmtot$ for i in IDC_Enterprise_Panel_20070618/* ; do pngtopnm $i | pnmtops -noturn > ${i%.png}.ps ; done
pnmtops: warning, image too large for page, rescaling to 0.364286
pnmtops: writing color PostScript...
pngtopnm: input file not a PNG file
pnmtops: EOF / read error reading magic number
pnmtops: warning, image too large for page, rescaling to 0.364286
pnmtops: writing color PostScript...
pngtopnm: input file not a PNG file
pnmtops: EOF / read error reading magic number
pnmtops: warning, image too large for page, rescaling to 0.364286
pnmtops: writing color PostScript...
pngtopnm: input file not a PNG file
pnmtops: EOF / read error reading magic number
ps: writing color PostScript...
pnmtops: warning, image too large for page, rescaling to 0.471429
pnmtops: writing color PostScript...
pnmtops: warning, image too large for page, rescaling to 0.471429
pnmtops: writing color PostScript...
pnmtops: warning, image too large for page, rescaling to 0.471429
....
etc.
$ for i in IDC_Enterprise_Panel_20070618/* ; do pngtopnm $i | pnmtops -noturn > ${i%.png}.ps ; done
Code:
pnmtops: warning, image too large for page, rescaling to 0.364286
pnmtops: writing color PostScript...
pngtopnm: input file not a PNG file
pnmtops: EOF / read error reading magic number
pnmtops: warning, image too large for page, rescaling to 0.364286
pnmtops: writing color PostScript...
pngtopnm: input file not a PNG file
pnmtops: EOF / read error reading magic number
pnmtops: warning, image too large for page, rescaling to 0.364286
pnmtops: writing color PostScript...
pngtopnm: input file not a PNG file
pnmtops: EOF / read error reading magic number
....
pngtopnm: input file not a PNG file
pnmtops: EOF / read error reading magic number
pnmtops: warning, image too large for page, rescaling to 0.364286
pnmtops: writing color PostScript...
pngtopnm: input file not a PNG file
pnmtops: EOF / read error reading magic number

Still fail. What does it mean "pnmtops: warning, image too large for page, rescaling to 0.364286"
???


Quote:
If you really want to know the rules, check the manual page for bash, in the section headed QUOTING.
Noted with tks.


B.R.
satimis
 
Old 07-03-2007, 03:35 AM   #12
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
Quote:
What does it mean "pnmtops: warning, image too large for page, rescaling to 0.364286"
I guess it means exactly that. If you don't like the output, try adding options to the pnmtops command to get the effect you want.

The conversion seems to be failing because some of the input files are not PNG files.
 
Old 07-03-2007, 04:02 AM   #13
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,427

Original Poster
Rep: Reputation: 53
Quote:
Originally Posted by maroonbaboon
I guess it means exactly that. If you don't like the output, try adding options to the pnmtops command to get the effect you want.

The conversion seems to be failing because some of the input files are not PNG files.
On that directory there are .ps and .ps.ps files created. All .ps files exeed 10MB in capacty and .ps.ps files are all empty. the .png files are screenshop only.

If creating them as .ps file one by one, I can make it w/o problem. Can you see what was the cause??? TIA


B.R.
satimis
 
Old 07-03-2007, 05:10 AM   #14
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
When you use

for i in IDC_Enterprise_Panel_20070618/*

you are trying to process all files, not just PNG ones. You need

for i in IDC_Enterprise_Panel_20070618/*.png
 
Old 07-03-2007, 05:13 AM   #15
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Quote:
Originally Posted by satimis
Hi jschiwal,


Tks for your advice.

$ sudo apt-cache showpkg imagemagick
Code:
Package: imagemagick
Versions: 
7:6.2.4.5.dfsg1-0.14 (/var/lib/apt/lists/hk.archive.ubuntu.com_ubuntu_dists_feisty_main_binary-i386_Packages)
 Description Language: 
                 File: /var/lib/apt/lists/hk.archive.ubuntu.com_ubuntu_dists_feisty_main_binary-i386_Packages
                  MD5: 3a199f3f933e41176706fce9b43cccee

....
.......
.........

Provides: 
7:6.2.4.5.dfsg1-0.14 - 
Reverse Provides: 
graphicsmagick-imagemagick-compat 1.1.7-14
$ sudo apt-get install imagemagick

$ which convert
/usr/bin/convert


$ convert /path/to/dir/* book.mng
$ convert book.mng book.pdf
Done.

A .pdf file created.


Can I run a single command line to do the job;

$ convert /path/to/dir/* | convert - book.pdf
???


TIA


B.R.
satimis
I wasn't able to create from png files to a pdf directly.
You could create a script to do it, and put it in your ~/bin/ directory.
This one can be called like: pics2pdf book.pdf *.png
Code:
#!/bin/bash
if [ ${#} -lt 2 ]; then cat <<-EOF
        Usage: ${0} pdf-filename imagefile1 [ imagefile2 ] ...


        EOF
        exit 1;
        fi

pdffile="${1}"
shift 1
imagefiles=(${*})
infiles="${*}"
convert $infiles tmp.mng
convert tmp.mng $pdffile
rm tmp.mng
It won't handle whitespaces in filenames.

Last edited by jschiwal; 07-03-2007 at 05:14 AM.
 
  


Reply

Tags
batch, convert, jpg, pdf, png


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
Cannot print PDF files. mooreted Mandriva 17 01-02-2012 03:11 AM
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 04:15 PM
Cannot Print PDF Files as400 Solaris / OpenSolaris 41 04-24-2006 02:23 AM
How To Merge multiple files into a single PDF ? kkempter Linux - Software 1 10-28-2005 01:02 PM
why I can't print PDF files wannaluvlinux Linux - Software 3 10-13-2004 02:52 AM


All times are GMT -5. The time now is 01:55 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration