Page 1 of 1

Help trying to merge PDFs

Posted: 2015-11-21T16:50:02-07:00
by lwfx
Using Ubuntu 15.10

Basically what I normally have to do for printing out ebay slips without murdering trees, is print the address label take the paper out turn upside down then print on that same sheet, the packing slip. So I am looking to Imagemagick. All I could find is:

montage -geometry +0+0 -density 100x100 1.pdf 2.pdf out.pdf

But that just seems to make the page landscaped and the 2 pdts side by side. Basically I just need to keep 1.pdf intact. Rotate pdf.2 180deg and merge like an overlay to pdf.1 and spit out that image/PDF. Any ideas?

Re: Help trying to merge PDFs

Posted: 2015-11-21T17:50:50-07:00
by lwfx
Well, I kind of half assedly got what I want, but it's unusable. Found a script to merge 2 images.

Code: Select all

#!/bin/bash
if [ -z "$3" ]
then
    echo "usage: $0 background.png foreground.png output.png"
    exit 1
fi
bg_size=`identify -format '%wx%h' "$1"`
convert -size $bg_size -composite "$1" "$2" -geometry $bg_size+0+0 -depth 100 "$3"
but first have to make 1 transparent then rotate 1 180 degrees and convert back to pdf. it prints out with some weird white border and looks blurry as all hell though.

Re: Help trying to merge PDFs

Posted: 2015-11-21T17:55:59-07:00
by fmw42
What is your IM version and platform? Please always provide that when asking questions, since syntax is different for Windows and Unix. In Unix, try

Code: Select all

convert 1.pdf \( 2.pdf -rotate 180 \) -geometry +X+Y -compose over -composite result.pdf
In Windows, try

Code: Select all

convert 1.pdf ( 2.pdf -rotate 180 ) -geometry +X+Y -compose over -composite result.pdf
where +X+Y are the x and y offsets from the top left corner of 1.pdf to the top left corner of 2.pdf where you want 2.pdf to appear on 1.pdf

See
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/compose/#geometry
http://www.imagemagick.org/Usage/windows/

Re: Help trying to merge PDFs

Posted: 2015-11-21T18:30:52-07:00
by lwfx
Thanks for the reply. I am using Ubuntu 15.10. That overlay worked, thanks! Then now just one more issue. Each image only takes up half a page but leaves the rest of the page blank, which then acts as whitespace and overlaps what is underneath :(

This is what I mean http://i.imgur.com/HsQnEBs.png

Edit: Also, that upper Packing Slip area only takes up a little more than 1/3 of the page, so maybe cropping of some sort?

Re: Help trying to merge PDFs

Posted: 2015-11-21T18:39:40-07:00
by fmw42
Post your two input pdfs and explain or post an example of your desired output. Also what version of Imagemagick are you using. Do you have ghostscript installed (gslib). It should show as gs or gslib for current IM versions when you do

Code: Select all

convert -version

Re: Help trying to merge PDFs

Posted: 2015-11-21T18:53:06-07:00
by lwfx
it's version 6.8.9-9, it was explained some up top and pretty much exactly like you had it, except I guess I only want half of the page from the overlaying PDF. I got it to 'work' with PNG but not as elegant as your code and had to deal with transparency which screwed up parts of the image. Tried using crop, but not sure if it's the correct thing to use here. Have to edit out some information, but here are images, which are normally PDF.

http://i.imgur.com/vOG8TBq.png and http://i.imgur.com/qtnsWgo.png

Edit: Those large Gray borders shouldn't normally be there in the pdf and not accounted for.

Re: Help trying to merge PDFs

Posted: 2015-11-21T20:34:16-07:00
by fmw42
Here is what I did (Unix syntax):

Code: Select all

convert qtnsWgo.png -trim +repage -alpha off qtnsWgo_trim.png
convert vOG8TBq.png -trim +repage -alpha off vOG8TBq_trim.png
Then I measure where to crop the second image and where to place it on the first image. You can change values if you want.

Code: Select all

convert qtnsWgo_trim.png \( vOG8TBq_trim.png -crop 631x401+0+0 +repage \) \
-geometry +0+400 -compose over -composite composite.png
Try that and see what you get. It should work with the pdfs, but you may have to specify an appropriate density just before reading the pdfs in the command line using -density XX

Re: Help trying to merge PDFs

Posted: 2015-11-22T13:35:17-07:00
by lwfx
That gets me to a place to work with it and does set it in the correct position. Thanks!