LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to print/save a bundle of .png files as a single .pdf file (https://www.linuxquestions.org/questions/linux-software-2/how-to-print-save-a-bundle-of-png-files-as-a-single-pdf-file-565482/)

satimis 06-29-2007 06:09 PM

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

maroonbaboon 06-30-2007 12:04 AM

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.

jschiwal 06-30-2007 02:27 AM

You could also use ImageMagick.

convert *.png book.mng
convert book.mng book.pdf

b0uncer 06-30-2007 02:37 AM

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.

satimis 07-01-2007 10:39 AM

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

maroonbaboon 07-01-2007 10:53 AM

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.

satimis 07-02-2007 08:12 PM

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

satimis 07-02-2007 11:32 PM

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

satimis 07-02-2007 11:35 PM

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

maroonbaboon 07-03-2007 12:44 AM

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.

satimis 07-03-2007 03:11 AM

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

maroonbaboon 07-03-2007 03:35 AM

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.

satimis 07-03-2007 04:02 AM

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

maroonbaboon 07-03-2007 05:10 AM

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

jschiwal 07-03-2007 05:13 AM

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.


All times are GMT -5. The time now is 09:42 PM.