noah
noah

Reputation: 208

ColdFusion: Replacing String with a cfdocumentitem tag

I have following situation: I create a PDF with the cfdocument tag but the documents value is generated by some other cf functions. Now I need some pagebreaks at specific points but it logically won't work with the cfdocumentitem (pagebreak) tag because it is not nested in a cfdocument tag. I tried to mark the points where I need these pagebreaks with a specific string and replace them somehow with the cfdocumentitem tag.. but as expected it doesn't work..

<some function>
  <table>blablahtml</table>

  <cfif pdfreport>markedforpagebreak</cfif>

  <table>blablahtml</table>
  .
  .
  .
</some function>

<other function>
  <cfdocument>
    #replace(dashboardHTML,"markedforpagebreak","<cfdocumentitem type='pagebreak'/>","all")#
  </cfdocument>
</other function>

I also looked at evalAtPrint attribute but it doesn't work either.. so has anybody an idea to solve my problem? Thanks =)

Upvotes: 1

Views: 284

Answers (1)

TheLifeOfBri_
TheLifeOfBri_

Reputation: 66

I don't think you can do this with replace.

We use a special character to denote pagebreaks. Then treat the content as a list, with this character as a delimiter. Then loop through the 'list', and for each iteration of the loop, display the chunk of text, and then insert the cfdocumentitem tag e.g.

<cfdocument>
<cfset numPageBreaks = listlen(email_message_text,'¶') />
    <cfloop from="1" to="#numPageBreaks#" index="thisPageBreak">
        #listgetat(email_message_text,thisPageBreak,'¶')#
        <cfif thisPageBreak lt numPageBreaks>
         <cfdocumentitem type="pagebreak" />
        </cfif>
    </cfloop>
</cfdocument>

Upvotes: 3

Related Questions