Skip to main content
Known Participant
March 26, 2020
Answered

Beginner at PDF

  • March 26, 2020
  • 1 reply
  • 1998 views

Ok, I am trying to make a PDF file ... 

At the end of a <cfsavecontent> within a function within a ajax .cfc template ... 

I added <cffile
action = "write"
file = "c:\inetpub\wwwroot\webstuff\coldfusion\images\pdffile.html"
output = "#invoice#"
>

That worked fine. 

Then I added ... 

<cfhtmltopdf>
source = "c:\inetpub\wwwroot\webstuff\coldfusion\images\pdffile.html"
destination = "c:\inetpub\wwwroot\webstuff\coldfusion\images\pdffile.pdf"

</cfhtmltopdf>

The moment I run it I get a parse JSON error.  It's hosing on the cfhtmltopdf tag. 

I know I do not yet have a other parameters ... but what am I doing wrong to cause the JSON error?

 

    This topic has been closed for replies.
    Correct answer Charlie Arehart

    At

    https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-g-h/cfhtmltopdf.html

    it clearly shows the destination as being within 

    <cfhtmltopdf>

    encryption = "AES_128|RC4_40|RC4_128|RC4_128M|None"
    source = "URL|pathname absolute or relative to web root"
    destination = "filename"
    language="language name"
    marginBottom = "number"
    marginLeft = "number"
    marginRight = "number"
    marginTop = "number"
    name = "output variable name"
    orientation = "portrait|landscape"
    overwrite = "yes|no"
    ownerPassword = "password"
    pageHeight = "page height in inches(default)"
    pageType = "page type"
    pageWidth = "page width in inches(default)"
    permissions = "permission list"
    saveAsName = "PDF filename"
    unit = "in|cm"
    userPassword = "password"

    HTML and CFML code

    </cfhtmltopdf>

     

    I tried without writing the file but got a JSON error too. 

    How else would you do it?

     


    The doc is mistaken. You've been a cfml coder for years (I've just noticed your account name). Do you not recognize the mistake, even from what I said?

     

    Let me be explicit for you. Please first change this:

    <cfhtmltopdf>
    source = "c:\inetpub\wwwroot\webstuff\coldfusion\images\pdffile.html"
    destination = "c:\inetpub\wwwroot\webstuff\coldfusion\images\pdffile.pdf"

    </cfhtmltopdf>

     

    To this:

     

    <cfhtmltopdf
    source = "c:\inetpub\wwwroot\webstuff\coldfusion\images\pdffile.html"
    destination = "c:\inetpub\wwwroot\webstuff\coldfusion\images\pdffile.pdf">

    </cfhtmltopdf>

     

    You may even be able to leave off the closing tag. I'm short of time to run a test for you. 

     

    You could also leave off the source attribute and put your #invoice# var between the pair of cfhtmltopdf tags. 

     

    Finally, you have not addressed my suggestion that you look at the intermediate html file, to see how it looks. First look in a editor, then in a browser. Anything amiss about it?

     

    The cf tag will of course be trying to create a pdf from that html, so if the browse has any errors, so will cf. But even if it renders well, look at the source in that html. There may be something your human eyes recognize as an error that the browser may not, but it seems cf has a problem with.

     

     

    1 reply

    Charlie Arehart
    Community Expert
    Community Expert
    March 27, 2020

    Can you confirm it's not about the closing bracket right after cfhtmltopdf? 

    /Charlie (troubleshooter, carehart. org)
    Known Participant
    March 27, 2020

    Sorry, not understanding your question. 

    There is a closing bracket.  >

    Just as if one were to use, say. <cfmail> lgskgs </cfmail>

    Obviously I cannot put this stuff inside the <cfsavecontent> as the variable #invoice# would not be avilable to be used. 

    I also understand what throws a parseJSON error.  

    Either a valid showstopper error OR random junk characters in your function but outside the <cfsavecontent>

    Which is WHERE my PDF stuff (<cfhtmltopdf>) is.  But where else can you put it?

    Could it have anything to do with not having set something up in the CFADMIN panel?

    And I spent a good few minutes reading the quite unhelpful docs at 

    https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-g-h/cfhtmltopdf.html

    and looked for a youtube video.  Nada. 

     

    Charlie Arehart
    Community Expert
    Community Expert
    March 27, 2020

    You wrote <cfhtmltopdf>, with the closing bracket after the f, rather than after the value of the destination attribute. Was that just a copy/paste mistake here?

     

    Assuming so, have you opened the intermediate html page? In an editor? Is it all and only html?

     

    The error refers to json. I don't see how there's be any json involved in a cfhtmltoldf. Are you doing anything with json in this?

     

    Finally, do you really NEED to write out the intermediate html file?  Cf doesn't require it, but you may have reason to prefer it. 

    /Charlie (troubleshooter, carehart. org)