Convert JPG to PDF using ColdFusion

2.3k Views Asked by At

Here's my current attempt to convert JPG to PDF using ColdFusion. I used cfdocument because it seemed easy to use:

<cfdocument format="PDF" name="jpgtopdf" mimetype="image/jpeg" srcfile="#myfile#"  pageheight="11" pagewidth="8.5">
</cfdocument>

Unfortunately this reduces the resolution to 72 DPI, destroying the details in the JPG. I would like to preserve the original JPG resolution. What is the best way to convert JPG to PDF?

--

EDIT: When I put <img> inside <cfdocument> it just produces a blank document. I believe this happens because, for security, #myfile# is outside the webroot. Fortunately, this led me to this answer: stackoverflow.com/questions/4813587/dynamic-pdf-cfdocument-cfcontent-image-email-attachement which indeed allows the conversion to be done with higher resolution. Here is my new code which seems to produce 300 DPI:

<cfdocument format="PDF" name="jpgtopdf" pageheight="11" pagewidth="8.5">
  <cfimage action="writetobrowser" source="#myfile#">
</cfdocument>
1

There are 1 best solutions below

1
On

Try this:

<cfdocument format="PDF">
    <img src="path to the image" width="1024px">
</cfdocument>

On CF11 it gives nice result.