如何在coldfusion中将TIF图像转换为PDF

时间:2013-11-11 14:53:56

标签: coldfusion coldfusion-9 cfdocument cfimage

我能得到的最接近的是使用此代码

<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> 

这让我非常接近我的TIF图像的完全重复,但由于某种原因,图像宽度减少了5个像素,我无法弄清楚原因。

更多细节: ad1.tif图像是1425x1125,最终生成的pdf文档是1725x2625。如您所见,我在cfdocument上使用5.75 x 8.75英寸。这在PDF文档中翻译为300DPI。当我在photoshop中加载PDF文档时,它确实说明文档是300DPI。

您可能会注意到ImageNew使用1725x2625而cfimage使用1740x2625。如果我将cfimage尺寸与imagenew相匹配(这非常有意义),那么你最终会在顶部,右侧和底部都有这个白色边框。图像仍然偏离宽度上的5个像素。所以我不得不让它摆脱那个白色的边界。如果我能弄明白为什么该图像关闭了5个像素。

1 个答案:

答案 0 :(得分:0)

显然您的原始问题已得到解答,但对于图像解析问题,您可以尝试将scale="100"添加到cfdocument标记中。这可能会阻止它缩小图像(这与降低分辨率相同)。我不确定它会起作用,因为我还没有尝试过。

作为旁注,我不明白为什么人们会在评论中而不是在答案中回答问题。