How do you convert a TIF image into PDF within coldfusion

1.2k Views Asked by At

The closest I have been able to get is using this code

<cfset Background = ImageNew("",1725,2625)>
<cfimage source="#APPLICATION.config.serverpath#/ad1.tif" name="ad1">
<cfset height1   = ImageGetHeight(ad1)> 
<cfset width1    = ImageGetWidth(ad1)>
<cfset resImage1 = ImageCopy(ad1,0,0, width1, height1)> 
<cfset ImagePaste(Background,resImage1,150,150)>

<cfdocument format="pdf" pagetype="custom" pagewidth="5.75" pageheight="8.75" fontembed="no" name="temp" margintop="0" marginbottom="0" marginleft="0" marginright="0">
<div style="position:absolute; top:0; left:0; right:0; bottom:0; z-index:0;width:100%;height:100%;">
<cfimage action="writeToBrowser" source="#Background#" style="width:1740px; height: 2650px;">
</cfdocument> 

This gets me very close to the exact duplicate of my TIF image, but for some reason the image is reduced by like 5 pixels on the width, and I cannot figure out why.

A bit more details: The ad1.tif image is 1425x1125, the final pdf document that gets produced is 1725x2625. As you can see I use 5.75 x 8.75 inches on the cfdocument. This translates in the PDF document being 300DPI. When I load up the PDF document in photoshop it does state the document is in 300DPI.

You might notice that the ImageNew uses 1725x2625 and the cfimage uses 1740x2625. If I matched the cfimage dimensions to the imagenew (which makes perfect sense), then you end up with having this white border on the top, right, and bottom. The image is still off by like 5 pixels on the width. So I am forced to make it a bit bigger to get rid of that white border. If I can just figure out why that image is 5 pixels off.

1

There are 1 best solutions below

0
Samuel Dealey On

Well obviously your original question has been answered, but for the image resolution issue, you might try adding scale="100" to your cfdocument tag. That might prevent it scaling the image down (which is the same thing as lowering resolution). I'm not sure it will work, since I haven't tried it.

As a side note, I don't understand why people keep answering questions in the comments instead of in the answers.