place image on page as letterhead

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dbdata
Posts: 3
Joined: 2017-08-02T17:19:22-07:00
Authentication code: 1151

place image on page as letterhead

Post by dbdata »

I realize that in 16 years I probably have have never asked an original tech support question and most are questions asked and answered 100 times if I really knew how to work the search functions.

Two versions of the same need:

I will have a text file that I can arrange any way that I wish and I have a graphic that I can format as needed. What I want to do is merge the text file and the graphic such that the graphic appears on the page as letterhead ... followed by the text.

In a perfect word, imagine an invoice with the company logo in the top left corner, taking up 50% of the page width and then beside that on the right is the customer name, address, etc. and then below all of that is the remainder of the invoice text ... occupying all 100% of the single page --> a final, one page PDF. I'm guessing I'd have to first make a page image out of the text but then I'd need a method of "placing" the logo into the page image at some X-Y coordinate.

Secondary, much simpler, is an image that takes up 100% of the page width followed immediately by the text taking up 100% -- this one would be much like "convert image.png text.txt out.pdf" -- except that command always generates 2 pages when what I want is for the text to immediately follow the image on the same page.

I'm hoping that both of these have been asked and answered/solved 100 times already.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: place image on page as letterhead

Post by fmw42 »

Please always provide your IM version and platform when asking questions on this forum, since syntax may vary.

1) To place a logo at the top left corner of an existing image, you would do the following.

Code: Select all

convert backgroundimage logoimage -gravity northwest -compose over -composite resultimage
If you are creating it from scratch and have the address text file and body text file, then if you want a letter size page, which is 612x792 (see http://www.imagemagick.org/script/comma ... s.php#page), you can do

Code: Select all

convert -size 612x792 xc:white logoimage -gravity northwest -compose over -composite addressfile.txt -gravity northeast -compose over -composite bodytext.txt -gravity south -compose over -composite result.pdf
2) If you have a logo and some text, you can also just do

Code: Select all

convert -background white logoimage textimage -gravity northwest -append result.pdf
See
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/layers/#append
dbdata
Posts: 3
Joined: 2017-08-02T17:19:22-07:00
Authentication code: 1151

Re: place image on page as letterhead

Post by dbdata »

Thanks, Fred. It did just what I wanted (with one complaint I'll get to in a minute)
What the server does for this - I create a text file where the northwest corner is conspicuously blank and then use your first command line and it's great. I have the luxury of being able to program the text output and also edit the logo file so I can size it properly.

Here's what remains: Regardless of either variation below:

$convert source.txt logo.png gravity northwest -compose over -composite out.pdf
--or-
$enscript -p source.ps -f Times-Roman12 -B source.txt
$convert source.ps logo.png gravity northwest -compose over -composite out.pdf

The text on the page comes out poorly rasterized (like a bad fax copy, if that makes sense)
If I print the source.txt file it looks fine. If I print the source.ps file it looks really fine (nice & sharp, etc.)

My goal is a PDF output but the problem is exactly the same when I convert to a JPG file
[URL=http://s112.photobucket.com/user/dbme/m ... f.jpg.html]

Version: ImageMagick 6.7.2-7 2016-06-16 Q16 http://www.imagemagick.org
Centos 6.7
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: place image on page as letterhead

Post by fmw42 »

Can you upload your text and logo files to some place such as dropbox.com and put the URLs here?

You can try

Code: Select all

convert -density 300 source.ps logo.png -gravity northwest -compose over -composite out.pdf
or

Code: Select all

convert -density 288 source.ps logo.png -gravity northwest -compose over -composite -resize 25% out.pdf
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: place image on page as letterhead

Post by GeeMack »

dbdata wrote: 2017-08-03T11:22:11-07:00The text on the page comes out poorly rasterized (like a bad fax copy, if that makes sense)
Within the command suggestion by fmw42 you'll notice the "-density 300". When reading in PDF files or other vector and/or postscript material, put the "-density N" before the input file name. You can usually get a decent screen image and good print results if you make "N" the resolution you might expect from the output printing device. I often use an input setting of "-density 1200" to get really high definition text to start, then reduce the size as necessary within the IM command to meet the output requirements.
dbdata
Posts: 3
Joined: 2017-08-02T17:19:22-07:00
Authentication code: 1151

Re: place image on page as letterhead

Post by dbdata »

So far I've tried converting the text directly
convert -density 300 source.txt logo.png -gravity northwest -compose over -composite out.pdf

to a PS file first
enscript -p source.ps -f Courier10 -B source.txt
convert -density 300 source.ps logo.png -gravity northwest -compose over -composite out.pdf

to a PDF first
enscript -p source.ps -f Courier10 -B source.txt
ps2pdf source.ps source.pdf
convert -density 300 source.pdf logo.png -gravity northwest -compose over -composite out.pdf

and through it all, while I can see many changes and opportunities, the core problem remains a constant.

I'll send both you and fmw a pm
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: place image on page as letterhead

Post by snibgo »

dbdata wrote:Version: ImageMagick 6.7.2-7
This is very old. I suggest you upgrade to a newer versio of IM.

If your version of Ghostscript is also old (before about 9.19), you might also upgrade that.

You want a PDF as output. As you may realise, this PDF will contain a raster image only.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: place image on page as letterhead

Post by fmw42 »

try this assuming on Unix-like system. If on Windows remove all the \

Code: Select all

convert \( source.ps -background white -flatten -level 47x100% \) \( logo.png -trim +repage \) -gravity northwest -geometry +10+30 -compose over -composite test2.pdf
Your logo image had lots of transparent area, so I trimmed it first.
Post Reply