Charset in Coldfusion PDF

Can someone please tell me how to fix this encoding to read what I have in this pdf. Obviously something is wrong, because this information works when the filename is .html and coldfusion is taken out and the meta encoding is utf-8. Someone can tell me how to fix this problem. I'm very new to coldfusion and I believe the problem lies in my lack of knowledge. Any help would be greatly appreciated!

My result: enter image description here

http://jsfiddle.net/yntz3n8w/1/

What I'm trying to accomplish: http://www.flhsmv.gov/dmv/forms/BTR/82040.pdf

    <cfsetting enablecfoutputonly="true">
    <cfcontent type="application/pdf">
    <cfheader name="Content-Disposition" value="attachment;filename=test.pdf">
    <cfdocument format="PDF" localurl="yes" 
        marginTop=".25" marginLeft=".25" marginRight=".25" marginBottom=".25" 
        pageType="custom" pageWidth="8.5" pageHeight="10.2">
    <cfoutput><?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>PDF Export Example</title>
    </head>
    <body>
    </body>
    </html>

</cfoutput>
</cfdocument>

      

+3


source to share


2 answers


Try this basic order. This is how I do it in one of my files and it works fine:



<cfdocument format="PDF" filename="name.pdf" overwrite="Yes">
   <html>
   ...
   </html>
</cfdocument>

<cfheader name="Content-Disposition" value="attachment;filename=name.pdf">
<cfcontent type="application/octet-stream" file="#expandPath('.')#\name.pdf" deletefile="Yes">

      

0


source


This worked for me. However, if you are hard-coded UTF-8 characters in the actual file .cfm

, try using <cfprocessingdirective pageencoding="utf-8">

at the top of the script. This tells the CF processor that the content is UTF-8 encoded, so the characters are processed correctly.

Update:

It looks like your end goal is to actually complete this pdf form. If that's the case, you probably don't have to clap with recreating the whole thing to HTML and converting it to PDF. Assuming the site allows it, just grab a copy of the pdf form and use cfpdfform

to fill it out.

Use <cfpdf action="read"..>

to get a list of the different fields on a form and upload them to the screen.



<cfpdfform action="read" source="c:/path/to/82040.pdf" result="data" />
<cfdump var="#data#" />

      

Once you know the names of the fields you need to fill in, just use cfpdfform

with the correct field name / value. For example, I took a quick look at this form and came up with this snippet that fills in two fields, the owner's name and the owner's email address:

<!--- for demo purposes, display on screen ---> 
<cfpdfform action="populate" source="c:/path/to/82040.pdf">
    <cfpdfformparam name="owner name" value="John Adams"> 
    <cfpdfformparam name="owner email" value="jadams@example.com"> 
</cfpdfform>

      

0


source







All Articles