Dynamically display page number in cfdocument - pdf-generation

I'm able to create a PDF no problem but need the page number of the PDF to begin on a certain page -- not 1. Normally I would use the cfdocument scope to show the page number but because I don't want the page number to start on 1 I can't get the code to work. Not sure how best to do this while incrementing each page. Here's the code that works fine:
<cfset theStartPageNumber = 10 />
<cfdocument format="PDF>
<cfoutput query="getPerson">
<cfdocumentsection>
<cfdocumentitem type="header">
<table>
<tr>
<td>My Header</td>
</tr>
</table>
</cfdocumentitem>
#getPerson.FirstName# #getPerson.LastName#
<cfdocumentitem type="footer" evalAtPrint="true" pageNumber="#theStartPageNumber#">
<table>
<tr>
<td align="center"><cfoutput>#attributes.pageNumber#</cfoutput></td>
</tr>
</table>
</cfdocumentitem>
</cfdocumentsection>
<cfset thePageNumber ++ />
</cfoutput>
</cfdocument>
But when I introduce a page break the numbering doesn't increment each page. Here's code that doesn't increment each page number.
<cfset theStartPageNumber = 10 />
<cfdocument format="PDF>
<cfoutput query="getPerson">
<cfdocumentsection>
<cfdocumentitem type="header">
<table>
<tr>
<td>My Header</td>
</tr>
</table>
</cfdocumentitem>
#getPerson.FirstName# #getPerson.LastName#
<cfdocumentitem type="pagebreak" />
#getPerson.Address#
<cfdocumentitem type="pagebreak" />
<cfdocumentitem type="footer" evalAtPrint="true" pageNumber="#theStartPageNumber#">
<table>
<tr>
<td align="center"><cfoutput>#attributes.pageNumber#</cfoutput></td>
</tr>
</table>
</cfdocumentitem>
</cfdocumentsection>
<cfset thePageNumber ++ />
</cfoutput>
</cfdocument>
Using the code that doesn't work the page number will stay "10" for two pages then increment to "11".
Any help is appreciated!

<cfset theStartPageNumber = 10 />
<cfdocument format="PDF>
<cfoutput query="getPerson">
<cfdocumentsection>
<cfdocumentitem type="header">
<table>
<tr>
<td>My Header</td>
</tr>
</table>
</cfdocumentitem>
#getPerson.FirstName# #getPerson.LastName#
<p style='page-break-after:always;'> </p>
#getPerson.Address#
<p style='page-break-after:always;'> </p>
<cfdocumentitem type="footer" evalAtPrint="true" pageNumber="#theStartPageNumber#">
<table>
<tr>
<td align="center"><cfoutput>#attributes.pageNumber#</cfoutput></td>
</tr>
</table>
</cfdocumentitem>
</cfdocumentsection>
<cfset thePageNumber ++ />
</cfoutput>
</cfdocument>
Also: With my footer and numbers I do something like this:
<cfdocumentitem type="footer" evalatprint="true">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align="center">
<cfoutput>
#cfdocument.currentpagenumber# of
#cfdocument.totalpagecount# |
#dateformat(now(),"mm-dd-yyyy")#
</cfoutput>
</td></tr>
</table>
</cfdocumentitem>
My full working example:
<cfdocument localUrl="yes"
format="PDF"
mimetype="text/html"
marginbottom=".0925"
margintop="0"
marginright=".1"
marginleft=".1">
<cfoutput>
test
<p style='page-break-after:always;'> </p>
test
<p style='page-break-after:always;'> </p>
test
<p style='page-break-after:always;'> </p>
</cfoutput>
<cfdocumentitem type="footer" evalatprint="true">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align="center">
<cfoutput>
#cfdocument.currentpagenumber# of
#cfdocument.totalpagecount# |
#dateformat(now(),"mm-dd-yyyy")#
</cfoutput>
</td></tr>
</table>
</cfdocumentitem>
</cfdocument>

This actually ended up working. Basically adding the start page form variable to the cfdocument.currentpagenumber variable.
<cfdocumentitem type="footer" evalAtPrint="true" no="#thePageNumber#">
<span style="border-top:1px solid black;display:block;"> </span>
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin-bottom:50px;">
<tr>
<td align="left"><font face="Tahoma" color="black"><strong>High Desert Corridor</strong><br/>Street address<br/>City, ST 55555</font></td>
<td align="center"><cfoutput>#evaluate(attributes.no + cfdocument.currentpagenumber - 1)#</cfoutput></td>
<td align="right"><font face="Tahoma" color="black">Phone: 555.555.5555<br/>Fax: 555.555.5555<br/>Email: info#domain.com</font></td>
</tr>
</table>
</cfdocumentitem>

Related

Ignore some TR nodes

I have a HTML like
<body>
<tr class="sysinfoTableCategoryHeader">
<td colspan="4">Operating System</td>
</tr>
<tr class="sysinfoTablePropertyEven">
<td />
<td />
<td><span class="sysinfoTablePropertyKey">Operating System Name</span></td>
<td><span class="sysinfoTablePropertyValue">Linux</span></td>
</tr>
<tr class="sysinfoTablePropertyOdd">
<td />
<td />
<td><span class="sysinfoTablePropertyKey">Kernel Version</span></td>
<td><span class="sysinfoTablePropertyValue">4.8.0-1-amd64</span></td>
</tr>
<tr class="sysinfoTableCategoryHeader">
<td colspan="4">Motherboard</td>
</tr>
<tr class="sysinfoTablePropertyEven">
<td />
<td />
<td><span class="sysinfoTablePropertyKey">Manufacturer</span></td>
<td><span class="sysinfoTablePropertyValue">Acer</span></td>
</tr>
<tr class="sysinfoTablePropertyOdd">
<td />
<td />
<td><span class="sysinfoTablePropertyKey">Product</span></td>
<td><span class="sysinfoTablePropertyValue">Aspire E5-531</span></td>
</tr>
</body>
So I'm able to pick entire body from this html file which is actually awesome. But there is one problem . Lets say from that body i want to ignore the node with class name="sysinfoTableCategoryHeader" Operating system.
Is this doable at all ?
My output should be like this
<body>
<tr class="sysinfoTableCategoryHeader">
<td colspan="4">Motherboard</td>
</tr>
<tr class="sysinfoTablePropertyEven">
<td />
<td />
<td><span class="sysinfoTablePropertyKey">Manufacturer</span></td>
<td><span class="sysinfoTablePropertyValue">Acer</span></td>
</tr>
<tr class="sysinfoTablePropertyOdd">
<td />
<td />
<td><span class="sysinfoTablePropertyKey">Product</span></td>
<td><span class="sysinfoTablePropertyValue">Aspire E5-531</span></td>
</tr>
</body>
How can i acoomplish it with HTMLAGILITYPACK ??
I'm english a little.
exp code:
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(your html code);
HtmlNodeCollection htmlNodes = htmlDoc.DocumentNode.SelectNodes("//body/tr[#class!='sysinfoTableCategoryHeader']");
the htmlNodes is you needs.
Or use RemoveAllIDforNode();
HtmlNodeCollection htmlNodes = htmlDoc.DocumentNode.SelectNodes("//body/tr[#class='sysinfoTableCategoryHeader']");
foreach (HtmlNode node in htmlNodes) {
htmlDoc.DocumentNode.RemoveAllIDforNode(node);
}
you need find xpath //tr[#class!='sysinfoTableCategoryHeader']
the xpath have operator.

Issue with EDM Template making

My code:
<td bgcolor="#0096d6">
<table cellspacing="0" cellpadding="0" border="0" width="393" align="center">
<tr>
<td>
<img src="images/x.gif" width="30" height="1" style="display:block;"/>
</td>
<td>
<font style="font-family:'HP Simplified';font-size:28px;color:#ffffff;font-weight:bold;">New Platforms to Elevate ProTrain to the next level in February</font>
</td>
<!--space problem-->
<td>
<img src="images/x.gif" width="30" height="1" style="display:block;"/>
</td>
</tr>
</table>
</td>
How can anybody help to solve this? Here 1 px space is coming after the end of the text <td> in outlook 2016 only.

How to create a two column email newsletter

I am trying to create a two column email flyer but I'm having trouble with the coding as Outlook hates CSS.
I'm using tables to keep it as simple as possible but I want two separate tables on the left and the right so I can add data into it as I wish.
I tried using float left and right on the two tables but Outlook ignores this style.
I know the two grey tables at the bottom are each in their own separate "holder" tables but this is so I can duplicate the grey "data" tables for when I add new articles.
<table class="all" width="auto" height="auto" border="0" cellspacing="0"><tr><td height="504">
<table width="750" height="140" border="0" cellspacing="0">
<tr>
<td width="200" valign="bottom" bgcolor="#E6E6E6"> </td>
<td width="345" align="center" valign="bottom" bgcolor="#E6E6E6"> </td>
<td width="152" align="center" valign="bottom" bgcolor="#E6E6E6"> </td>
<td width="45" align="center" valign="bottom" bgcolor="#E6E6E6"> </td>
</tr>
<tr>
<td width="200" valign="bottom" bgcolor="#E6E6E6"> </td>
<td align="center" valign="bottom" bgcolor="#E6E6E6"><font color="#111111" face="Arial Narrow" size="+2">DECEMBER NEWSLETTER</font></td>
<td width="152" align="center" valign="bottom" bgcolor="#E6E6E6"><font size="2"><strong>#4 - <span class="orange">04.12.13</span></strong></font></td>
<td width="45" align="center" valign="bottom" bgcolor="#E6E6E6"> </td>
</tr>
</table>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="75" height="50" bgcolor="#E6E6E6" scope="row"> </td>
<td width="600" rowspan="2" scope="row"><img src="http://placehold.it/600x200"/></td>
<td width="75" bgcolor="#E6E6E6" scope="row"> </td>
</tr>
<tr>
<td width="75" height="81" scope="row"> </td>
<td scope="row"> </td>
</tr>
</table>
<table class="holder" width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" scope="row">
<table class="inlinetableleft" width="360">
<tr>
<td width="371" align="left">
<!------------LEFT COLUMN------------------>
<table width="360" border="0" cellspacing="0" cellpadding="0">
<tr>
<th height="103" colspan="4" align="left" valign="middle" bgcolor="#CCCCCC" scope="row"> </th>
</tr>
</table>
<!--------------LEFT COLUMN END------------->
</td>
</tr>
</table>
<table class="inlinetableright" width="360">
<tr>
<td align="left">
<!------------RIGHT COLUMN------------------>
<table width="360" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="106" align="left" bgcolor="#CCCCCC" scope="row"> </td>
</tr>
</table>
<!-----------RIGHT COLUMN END-------------->
</td></tr>
</table>
</td>
</tr>
</table>
Here is a fiddle of my newsletter so far, it's the bottom two grey tables that I want to be side by side.
Fiddle
For HTML emails, nested tables are your friend :)
JSFiddle
Note: the border around the table is just to show you where the tables are.
<table border="0" width="600" cellpadding="0" cellspacing="0" align="center">
<tr>
<td colspan="2">
header content here
</td>
</tr>
<tr>
<td width="300">
<table border="0" width="300" cellpadding="1" cellspacing="0" align="left">
<tr>
<td>Left Content</td>
</tr>
</table>
</td>
<td width="300">
<table border="0" width="300" cellpadding="1" cellspacing="0" align="left">
<tr>
<td>Right content</td>
</tr>
</table>
</td>
</tr>
</table>

Escaping characters with ajax and ColdFusion

Hello I've got an issue with an encode failing. Can anyone spot where I'm going wrong?
<form>
<table cellspacing="0" cellpadding="0" border="0" style="background-color:#ededed;padding:50px;">
<tr>
<td align="left"><b>Screen? (eg. Index)</b></td>
</tr>
<tr>
<td align="left"><input type="text" name="strFeedbackScreen" value="" style="width:300px;"></td>
</tr>
<tr>
<td style="height:10px"></td>
</tr>
<tr>
<td align="left"><b>Comments:</b></td>
</tr>
<tr>
<td align="left"><textarea name="strFeedbackComments" style="width:400px;height:150px;"></textarea></td>
</tr>
<tr>
<td style="height:10px"></td>
</tr>
<tr>
<td align="left"><b>Thank you for your feedback.</b></td>
</tr>
<tr>
<td style="height:10px"></td>
</tr>
<cfoutput>
<tr>
<td align="left"><input type="button" value="Send" class="button"
onMouseover="this.className = 'buttonover';"
onMousedown="this.className = 'buttonover';"
onMouseOut="this.className = 'button';"
onclick="sendfeedback('strFeedbackScreen='+escape(this.form.strFeedbackScreen.value)+',strFeedbackComments='+escape(this.form.strFeedbackComments.value),'send_feedback_action_ajax')">
</td>
</tr>
</cfoutput>
</table>
</form>
is the form
<cfoutput>
<cfmail to="feedback#example.com" from="feedback#example.com" subject="Feedback left" type="html">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>**** This email has been sent to all concerned ****</td>
</tr>
<tr>
<td style="height:10px;"> </td>
</tr>
<cfif application.ds eq "App1">
<tr>
<td>This feedback has been left on App 1.</td>
</tr>
<cfelseif application.ds eq "App2">
<tr>
<td>This feedback has been left on App 2.</td>
</tr>
<cfelseif application.ds eq "App3">
<tr>
<td>This feedback has been left on App 3.</td>
</tr>
</cfif>
<tr>
<td style="height:10px;"> </td>
</tr>
<tr>
<td><b>From:</b></td>
</tr>
<tr>
<td>#session.stafffirstname# #session.staffsurname# - #session.staffemail#</td>
</tr>
<tr>
<td style="height:10px;"> </td>
</tr>
<tr>
<td><b>Screen:</b></td>
</tr>
<tr>
<td>#strFeedbackScreen#</td>
</tr>
<tr>
<td style="height:10px;"> </td>
</tr>
<tr>
<td><b>Comments:</b></td>
</tr>
<tr>
<td>#strFeedbackComments#</td>
</tr>
</table>
</cfmail>
</cfoutput>
is the action.cfm
and the javascript is
function sendfeedback(fields,action) {
turnLayeron('ajaxloading');
nocache = Math.random();
http.open('get', '/ajax.cfm?action='+action+'&fields='+fields+'&nocache='+nocache);
http.onreadystatechange = function() {
if(http.readyState == 4){
closepopout();
turnLayeroff('ajaxloading');
}
};
http.send(null);
}
I've been trying to get uriencode working, but it encodes my string before it gets emailed.
Change your JavaScript to following:
function sendfeedback(fields,action) {
http.open("POST", '/ajax.cfm?action='+action+'&nocache='+nocache, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if(http.readyState == 4){
closepopout();
turnLayeroff('ajaxloading');
}
};
http.send(fields);
}
Also change your function call to:
onclick="sendfeedback('strFeedbackScreen='+escape(this.form.strFeedbackScreen.value)+'&strFeedbackComments='+escape(this.form.strFeedbackComments.value),'send_feedback_action_ajax')"

Grid generated with JQuery template need to reset using Ajax not working

Sometime working and sometime not.
I am trying to generate Grid with the help of JQuery Template via Ajax once record is added or deleted. In js file
$('.gridRow').remove();
is not working properly. Someone tell me how to reset grid to fill it again. Below is the code.
JS File
var ReloadGrid = (function(){
$.getJSON("/HeaderMenu/GetHeaderGrid", function(data) {
$('.gridRow').remove();
(data.length <= 0) ? $("#gridBtn").hide() : $("#gridBtn").show();
for (var i=0; i<data.length; i++) { data[i].num = i+1; }
$('#gridTemplate').tmpl(data).appendTo('table.gridTable > tbody');
});
});
on MVC3 cxhtml page
<script id="gridTemplate" type="text/x-jquery-tmpl">
<tr class="gridRow">
<td class="cellTd ">
<input type="checkbox" id="deleteCb" />
<input type="hidden" id="Id_ + ${num}" class="idField" value="${Id}" />
</td>
<td class="cellTd">
<input id="index" name="index" class="numberField" type="text" value="${IndexOrder}" />
</td>
<td class="cellTd">${DisplayName}</td>
<td class="cellTd ">${UrlName}</td>
<td class="cellTd ">
<input type="checkbox" id="activeCb" {{if Active}} checked{{/if}} />
</td>
</tr>
</script>
<div class="gridDiv">
<table class="gridTable" cellspacing="0" cellpadding="0">
<tbody>
<tr class="gridTitleRow">
<td class="iconLink width36">Delete</td>
<td class="iconLink width60">Sort Order</td>
<td class="iconLink widthAuto">Display Name</td>
<td class="iconLink widthAuto">Url Name</td>
<td class="iconLink widthAuto">Active</td>
</tr>
</tbody>
</table>
</div>
I usually empty the wrapper instead of the row.
$('table.gridTable > tbody').empty();
But for that to work you'd have to change your table to use thead
<table class="gridTable" cellspacing="0" cellpadding="0">
<thead>
<tr class="gridTitleRow">
<th class="iconLink width36">Delete</th>
<th class="iconLink width60">Sort Order</th>
<th class="iconLink widthAuto">Display Name</th>
<th class="iconLink widthAuto">Url Name</th>
<th class="iconLink widthAuto">Active</th>
</tr>
<thead>
<tbody>
</tbody>
</table>

Resources