I want to send the cppcheck report through email but I had never used the email ext plugin before, so I found this Sending Cppcheck result/report on email from Jenkins using email-ext plugin with a nice jelly template to do so, I have also followed the steps in the documentation, to send my own templates in a pipeline job, I have created my template with a .jelly extension and set it into my $JENKINS_HOME\email-templates although the email-templates folder did not exist, so I am not sure if it should be created beforehand just by installing the plugin or what I am missing. This is my stage
stage('Mail cppcheck report') {
steps{
script{
def mailRecipients = "email#email.net"
def jobName = currentBuild.fullDisplayName
mimeType: 'text/html'
emailext body: '''${JELLY_SCRIPT, template="custom"}''',
subject: "[Jenkins] ${jobName}",
to: "${mailRecipients}"
}
}
}
And this is the template I want to use but I keep getting the following error JellyException: Could not parse Jelly script : null even though the email is sent the email body is just the error mentioned above.
<j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
<j:if test="${cppcheckAction!=null}">
<j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
<j:if test="${cppcheckResult!=null}">
<TABLE width="100%">
<TR><TD class="bg1" colspan="2"><B>CPPCHECK RESULT</B></TD></TR>
<TR bgcolor="white"><TD class="test_failed" colspan="2"><B><li>Found: ${cppcheckResult.report.getNumberTotal()}</li></B></TD></TR>
</TABLE>
<BR/>
</j:if>
</j:if>
I have also tried with some other templates and I get no error but I receive an empty email instead, like with this one.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<html>
<j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
<j:if test="${cppcheckAction!=null}">
<j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
<j:if test="${cppcheckResult!=null}">
<h2>Summary</h2>
<style type="text/css">
#cppcheckStatistics { width: auto; }
#cppcheckStatistics .number { text-align: right; }
</style>
<table class="pane sortable" id="cppcheckStatistics">
<thead>
<tr>
<td class="pane-header">Severity</td>
<td class="pane-header">Count</td>
<td class="pane-header">Delta</td>
</tr>
</thead>
<tbody>
<tr>
<td class="pane">Error</td>
<td class="pane number">${cppcheckResult.statistics.getNumberErrorSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberErrorSeverity()}</td>
</tr>
<tr>
<td class="pane">Warning</td>
<td class="pane number">${cppcheckResult.statistics.getNumberWarningSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberWarningSeverity()}</td>
</tr>
<tr>
<td class="pane">Style</td>
<td class="pane number">${cppcheckResult.statistics.getNumberStyleSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberStyleSeverity()}</td>
</tr>
<tr>
<td class="pane">Performance</td>
<td class="pane number">${cppcheckResult.statistics.getNumberPerformanceSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberPerformanceSeverity()}</td>
</tr>
<tr>
<td class="pane">Portability</td>
<td class="pane number">${cppcheckResult.statistics.getNumberPortabilitySeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberPortabilitySeverity()}</td>
</tr>
<tr>
<td class="pane">Information</td>
<td class="pane number">${cppcheckResult.statistics.getNumberInformationSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberInformationSeverity()}</td>
</tr>
<tr>
<td class="pane">No category</td>
<td class="pane number">${cppcheckResult.statistics.getNumberNoCategorySeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberNoCategorySeverity()}</td>
</tr>
</tbody>
<tfoot>
<tr class="sortbottom">
<td class="pane-header">Total</td>
<td class="pane-header number"><B>${cppcheckResult.report.getNumberTotal()}</B></td>
<td class="pane-header number"><B>${cppcheckResult.getDiff().getNumberTotal()}</B></td>
</tr>
</tfoot>
</table>
</j:if>
</j:if>
</html>
</j:jelly>
However if I use the default template emailext body: '''${JELLY_SCRIPT, template="html"}''' it works fine
Related
I am converting a table to pdf, if I put the pdf into portrait then the PDF gets generated with no issues.
However the table is quite wide so I need to switch it to landscape, as soon as I do I receive the following error:
TypeError: cell is undefined[Learn More] jspdf.plugin.autotable.js:690:17
Sadly I can't share the table as it is confidential work (hence the local pdf creation) but here is the script I am using.
$('#btnExportPDF').on('click', function(e){
e.preventDefault();
let source = document.getElementById('iframeReport').contentWindow.document.getElementById('tblReport');
$('#divHiddenTable').html(source.outerHTML);
console.log(source);
let doc = new jsPDF({format: 'a4', unit: 'pt', orientation: 'l'});//change l to p and it works
console.log('PDF Obj');
doc.autoTable({html: '#tblReport'});
console.log('PDF autoTable');
doc.save("RegionalDirectorsWriteOffReviewExport.pdf");
console.log('PDF save');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.0.9/jspdf.plugin.autotable.js"></script>
After some more investigation, it appears that if I remove the OFFICE 3 section from the table below it works, but with it in it doesn't.
<table class="table table-striped" id="tblReport">
<thead>
<tr>
<th>Client
Code</th>
<th>Client
Partner</th>
<th>Client
Name</th>
<th> </th>
<th align="center">Billed</th>
<th align="center">WIP
W/O</th>
<th align="center">Profit/
Loss</th>
<th>Recovery</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr class="OfficeHeader">
<th colspan="9">City 1</th>
</tr>
<tr>
<td>123456</td>
<td>NAME</td>
<td>COMPANY </td>
<td>WHOAMI</td>
<td class="text-right">2,069.58</td>
<td class="text-right">4,609.66</td>
<td class="text-right">-2,540.08</td>
<td class="text-right">44.89</td>
<td></td>
</tr>
<tr>
<td>45384</td>
<td>NAME</td>
<td>COMPANY 2</td>
<td>WHOAMI</td>
<td class="text-right">195.00</td>
<td class="text-right">4,559.74</td>
<td class="text-right">-4,364.74</td>
<td class="text-right">4.27</td>
<td></td>
</tr>
<tr>
<td>852136</td>
<td>NAME</td>
<td>COMPANY 3</td>
<td> </td>
<td class="text-right">600.00</td>
<td class="text-right">3,109.00</td>
<td class="text-right">-2,509.00</td>
<td class="text-right">19.29</td>
<td></td>
</tr>
<tr>
<td>111</td>
<td>NAME</td>
<td>COMPANY 4</td>
<td>WHOAMI</td>
<td class="text-right">0.00</td>
<td class="text-right">1,677.50</td>
<td class="text-right">-1,677.50</td>
<td class="text-right">0.00</td>
<td></td>
</tr>
<tr>
<td>123654</td>
<td>NAME</td>
<td>COMPANY</td>
<td>WHOAMI</td>
<td class="text-right">0.00</td>
<td class="text-right">1,169.75</td>
<td class="text-right">-1,169.75</td>
<td class="text-right">0.00</td>
<td></td>
</tr>
<tr class="OfficeFooter">
<td colspan="4" class="text-right">Office Totals</td>
<td class="text-right"><div class="double-border">2,864.58</div></td>
<td class="text-right"><div class="double-border">15,125.65</div></td>
<td class="text-right"><div class="double-border">-12,261.07</div></td>
<td colspan="2"><div class="pagebreak"> </div></td>
</tr>
<tr class="OfficeHeader">
<th colspan="9">City 2</th>
</tr>
<tr>
<td>A-569</td>
<td>NAME</td>
<td>COMPANY </td>
<td>WHOIZYOU</td>
<td class="text-right">2,175.00</td>
<td class="text-right">4,361.72</td>
<td class="text-right">-2,186.72</td>
<td class="text-right">49.86</td>
<td>Overrun against a thing that we don't know so can't put here</td>
</tr>
<tr>
<td>D/6666</td>
<td>NAME</td>
<td>COMPANY</td>
<td>WHOIZTHIS</td>
<td class="text-right">1,300.00</td>
<td class="text-right">2,371.01</td>
<td class="text-right">-1,071.01</td>
<td class="text-right">54.82</td>
<td>Taken on from previous prtner and manager</td>
</tr>
<tr class="OfficeFooter">
<td colspan="4" class="text-right">Office Totals</td>
<td class="text-right"><div class="double-border">3,475.00</div></td>
<td class="text-right"><div class="double-border">6,732.73</div></td>
<td class="text-right"><div class="double-border">-3,257.73</div></td>
<td colspan="2"><div class="pagebreak"> </div></td>
</tr>
<tr class="OfficeHeader">
<th colspan="9">OFFICE 3</th>
</tr>
<tr>
<td>GFDGDFGF</td>
<td>NAME</td>
<td>COMPANY </td>
<td>WHO</td>
<td class="text-right">2,910.00</td>
<td class="text-right">8,385.21</td>
<td class="text-right">-5,475.21</td>
<td class="text-right">34.70</td>
<td></td>
</tr>
<tr>
<td>KJHKJHKJ</td>
<td>NAME</td>
<td>COMPANY Limited </td>
<td>WHO</td>
<td class="text-right">2,310.00</td>
<td class="text-right">4,733.76</td>
<td class="text-right">-2,423.76</td>
<td class="text-right">48.79</td>
<td></td>
</tr>
<tr>
<td>OIOUIO</td>
<td>NAM,E</td>
<td>COMPANY</td>
<td>WHOZ</td>
<td class="text-right">0.00</td>
<td class="text-right">2,110.25</td>
<td class="text-right">-2,110.25</td>
<td class="text-right">0.00</td>
<td></td>
</tr>
<tr class="OfficeFooter">
<td colspan="4" class="text-right">Office Totals</td>
<td class="text-right"><div class="double-border">5,220.00</div></td>
<td class="text-right"><div class="double-border">15,229.22</div></td>
<td class="text-right"><div class="double-border">-10,009.22</div></td>
<td colspan="2"><div class="pagebreak"> </div></td>
</tr>
</tbody>
<tfoot>
<tr style="height: 2px !important; overflow: hidden !important;">
<td colspan="4"><div style="line-height: 2px !important; height: 2px !important; font-size: 2px !important; overflow: hidden; !important;"> </div></td>
<td colspan="3"><div style="line-height: 2px !important; height: 2px !important; font-size: 2px !important; background-color: #e7ebee; overflow: hidden !important;"> </div></td>
<td colspan="2"><div style="line-height: 2px !important; height: 2px !important; font-size: 2px !important; overflow: hidden; !important;"> </div></td>
</tr>
<tr>
<td colspan="4" class="text-right">AVG</td>
<td class="text-right">1,319.98</td>
<td class="text-right">3,526.59</td>
<td class="text-right">-2,206.61</td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="4" class="text-right">Totals</td>
<td class="text-right"><div class="double-border">27,719.58</div></td>
<td class="text-right"><div class="double-border">74,058.42</div></td>
<td class="text-right"><div class="double-border">-46,338.84</div></td>
<td colspan="2"> </td>
</tr>
</tfoot>
</table>
example JSFiddle https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.css
Here is the jelly script i am using:
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<STYLE>BODY, TABLE, TD, TH, P { font-family:Verdana,Helvetica,sans serif; font-size:11px; color:black; } h1 { color:black; } h2 { color:black; } h3 {
color:black; } TD.bg1 { color:white; background-color:#0000C0; font-size:120% } TD.bg2 { color:white;
background-color:#4040FF; font-size:110% } TD.bg3 { color:white; background-color:#8080FF; } TD.test_passed { color:blue; } TD.test_failed { color:red
; } TD.console { font-family:Courier New; }</STYLE>
<BODY>
<j:set var="spc" value=" " />
<!-- GENERAL INFO -->
<TABLE>
<TR>
<TD align="right">
<j:choose>
<j:when test="${build.result=='SUCCESS'}">
<IMG SRC="${rooturl}static/e59dfe28/images/32x32/blue.gif" />
</j:when>
<j:when test="${build.result=='FAILURE'}">
<IMG SRC="${rooturl}static/e59dfe28/images/32x32/red.gif" />
</j:when>
<j:otherwise>
<IMG SRC="${rooturl}static/e59dfe28/images/32x32/yellow.gif" />
</j:otherwise>
</j:choose>
</TD>
<TD valign="center">
<B style="font-size: 200%;">BUILD ${build.result}</B>
</TD>
</TR>
<TR>
<TD>Build URL</TD>
<TD>
${rooturl}${build.url}
</TD>
</TR>
<TR>
<TD>Project:</TD>
<TD>${project.name}</TD>
</TR>
<TR>
<TD>Date of build:</TD>
<TD>${it.timestampString}</TD>
</TR>
<TR>
<TD>Build duration:</TD>
<TD>${build.durationString}</TD>
</TR>
<TR>
<!-- BRANCH -->
<TD>Subversion Repo:</TD>
<TD>${build.scm}</TD>
</TR>
<tr>
<td>Build Cause:</td>
<td>
<j:forEach var="cause" items="${build.causes}">${cause.shortDescription} </j:forEach>
</td>
</tr>
</TABLE>
<BR />
<!-- CHANGE SET -->
<j:set var="changeSet" value="${build.changeSet}" />
<j:if test="${changeSet!=null}">
<j:set var="hadChanges" value="false" />
<TABLE width="100%">
<TR>
<TD class="bg1" colspan="2">
<B>CHANGES</B>
</TD>
</TR>
<j:forEach var="cs" items="${changeSet}" varStatus="loop">
<j:set var="hadChanges" value="true" />
<j:set var="aUser" value="${cs.hudsonUser}" />
<TR>
<TD colspan="2" class="bg2">${spc}Revision
<B>${cs.commitId?:cs.revision?:cs.changeNumber}</B>by
<B>${aUser!=null?aUser.displayName:cs.author.displayName}:</B>
<B>(${cs.msgAnnotated})</B></TD>
</TR>
<j:forEach var="p" items="${cs.affectedFiles}">
<TR>
<TD width="10%">${spc}${p.editType.name}</TD>
<TD>${p.path}</TD>
</TR>
</j:forEach>
</j:forEach>
<j:if test="${!hadChanges}">
<TR>
<TD colspan="2">No Changes</TD>
</TR>
</j:if>
</TABLE>
<BR />
</j:if>
<!-- ARTIFACTS -->
<j:set var="artifacts" value="${build.artifacts}" />
<j:if test="${artifacts!=null and artifacts.size()>0}">
<TABLE width="100%">
<TR>
<TD class="bg1">
<B>BUILD ATRIFACTS</B>
</TD>
</TR>
<TR>
<TD>
<j:forEach var="f" items="${artifacts}">
<li>
${f}
</li>
</j:forEach>
</TD>
</TR>
</TABLE>
<BR />
</j:if>
<!-- MAVEN ARTIFACTS -->
<j:set var="mbuilds" value="${build.moduleBuilds}" />
<j:if test="${mbuilds!=null}">
<TABLE width="100%">
<TR>
<TD class="bg1">
<B>BUILD ATRIFACTS</B>
</TD>
</TR>
<j:forEach var="m" items="${mbuilds}">
<TR>
<TD class="bg2">
<B>${m.key.displayName}</B>
</TD>
</TR>
<j:forEach var="mvnbld" items="${m.value}">
<j:set var="artifacts" value="${mvnbld.artifacts}" />
<j:if test="${artifacts!=null and artifacts.size()>0}">
<TR>
<TD>
<j:forEach var="f" items="${artifacts}">
<li>
${f}
</li>
</j:forEach>
</TD>
</TR>
</j:if>
</j:forEach>
</j:forEach>
</TABLE>
<BR />
</j:if>
<!-- JUnit TEMPLATE -->
<j:set var="junitResultList" value="${it.JUnitTestResult}" />
<j:if test="${junitResultList.isEmpty()!=true}">
<TABLE width="100%">
<TR>
<TD class="bg1" colspan="2">
<B>${project.name} Functional Tests</B>
</TD>
</TR>
<j:forEach var="junitResult" items="${it.JUnitTestResult}">
<j:forEach var="packageResult" items="${junitResult.getChildren()}">
<TR>
<TD class="bg2" colspan="2">Name: ${packageResult.getName()} Failed: ${packageResult.getFailCount()} test(s), Passed: ${packageResult.getP
assCount()} test(s), Skipped: ${packageResult.getSkipCount()} test(s), Total:
${packageResult.getPassCount()+packageResult.getFailCount()+packageResult.getSkipCount()} test(s)</TD>
</TR>
<j:forEach var="failed_test" items="${packageResult.getFailedTests()}">
<TR bgcolor="white">
<TD class="test_failed" colspan="2">
<B>
<li>Failed: ${failed_test.getFullName()}
<br />
<pre>
${failed_test.errorDetails}
</pre></li>
</B>
</TD>
</TR>
<TR bgcolor="white">
<TD class="test_failed" colspan="2">
<B>
<li>StackTrace: ${failed_test.getFullName()}
<br />
<pre>
${failed_test.errorStackTrace}
</pre></li>
</B>
</TD>
</TR>
</j:forEach>
</j:forEach>
</j:forEach>
</TABLE>
<BR />
</j:if>
<!-- COBERTURA TEMPLATE -->
<j:set var="coberturaAction" value="${it.coberturaAction}" />
<j:if test="${coberturaAction!=null}">
<j:set var="coberturaResult" value="${coberturaAction.result}" />
<j:if test="${coberturaResult!=null}">
<table width="100%">
<TD class="bg1" colspan="2">
<B>Cobertura Report</B>
</TD>
</table>
<table width="100%">
<TD class="bg2" colspan="2">
<B>Project Coverage Summary</B>
</TD>
</table>
<table border="1px" class="pane">
<tr>
<td>Name</td>
<j:forEach var="metric" items="${coberturaResult.metrics}">
<td>${metric.name}</td>
</j:forEach>
</tr>
<tr>
<td>${coberturaResult.name}</td>
<j:forEach var="metric" items="${coberturaResult.metrics}">
<td data="${coberturaResult.getCoverage(metric).percentageFloat}">${coberturaResult.getCoverage(metric).percentage}% (${coberturaResult.ge
tCoverage(metric)})</td>
</j:forEach>
</tr>
</table>
<j:if test="${coberturaResult.sourceCodeLevel}">
<h2>Source</h2>
<j:choose>
<j:when test="${coberturaResult.sourceFileAvailable}">
<div style="overflow-x:scroll;">
<table class="source">
<thead>
<tr>
<th colspan="3">${coberturaResult.relativeSourcePath}</th>
</tr>
</thead>${coberturaResult.sourceFileContent}</table>
</div>
</j:when>
<j:otherwise>
<p>
<i>Source code is unavailable</i>
</p>
</j:otherwise>
</j:choose>
</j:if>
<j:forEach var="element" items="${coberturaResult.childElements}">
<j:set var="childMetrics" value="${coberturaResult.getChildMetrics(element)}" />
<table width="100%">
<TD class="bg2" colspan="2">Coverage Breakdown by ${element.displayName}</TD>
</table>
<table border="1px" class="pane sortable">
<tr>
<td>Name</td>
<j:forEach var="metric" items="${childMetrics}">
<td>${metric.name}</td>
</j:forEach>
</tr>
<j:forEach var="c" items="${coberturaResult.children}">
<j:set var="child" value="${coberturaResult.getChild(c)}" />
<tr>
<td>${child.xmlTransform(child.name)}</td>
<j:forEach var="metric" items="${childMetrics}">
<j:set var="childResult" value="${child.getCoverage(metric)}" />
<j:choose>
<j:when test="${childResult!=null}">
<td data="${childResult.percentageFloat}">${childResult.percentage}% (${childResult})</td>
</j:when>
<j:otherwise>
<td data="101">N/A</td>
</j:otherwise>
</j:choose>
</j:forEach>
</tr>
</j:forEach>
</table>
</j:forEach>
</j:if>
<BR />
</j:if>
<!-- HEALTH TEMPLATE -->
<div class="content">
<j:set var="healthIconSize" value="16x16" />
<j:set var="healthReports" value="${project.buildHealthReports}" />
<j:if test="${healthReports!=null}">
<h1>Health Report</h1>
<table>
<tr>
<th>W</th>
<th>Description</th>
<th>Score</th>
</tr>
<j:forEach var="healthReport" items="${healthReports}">
<tr>
<td>
<img src="${rooturl}${healthReport.getIconUrl(healthIconSize)}" />
</td>
<td>${healthReport.description}</td>
<td>${healthReport.score}</td>
</tr>
</j:forEach>
</table>
<br />
</j:if>
</div>
<!-- CONSOLE OUTPUT -->
<j:getStatic var="resultFailure" field="FAILURE" className="hudson.model.Result" />
<j:if test="${build.result==resultFailure}">
<TABLE width="100%" cellpadding="0" cellspacing="0">
<TR>
<TD class="bg1">
<B>CONSOLE OUTPUT</B>
</TD>
</TR>
<j:forEach var="line" items="${build.getLog(100)}">
<TR>
<TD class="console">${line}</TD>
</TR>
</j:forEach>
</TABLE>
<BR />
</j:if>
</BODY>
</j:jelly>
<!-- BRANCH -->
<TD>Subversion Repo:</TD>
<TD>${build.scm}</TD>
</TR>
does not work, and i am not sure which argument to use with build object to get subversion url.
outside jelly script, i can get the Subversion URL, using:
Subversion URL: ${ENV, var="SVN_URL"}
This might work -
<j:set var="buildenv" value="${build.getEnvironment(listener)}"/>
<j:set var="myvar" value="${buildenv.get('SVN_URL')}"/>
Reference: Jelly script for ext-email plugin jenkins
<TD>${build.envVars.SVN_URL}</TD>
I'm receiving an error when trying to select a node with css value of "WhoIsOnDutyTableLevel1:header:2" using nokogiri. I'm assuming nokogiri just can't handle two colons. What are my options? I can't change the structure of the html.
Here's the html:
<html lang="en"><head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<link rel="stylesheet" type="text/css" href="stylesheets/forms.css">
<style type="text/css" media="screen" title="AlarmPoint">
#import "stylesheets/AlarmPoint.css";
</style>
</head>
<body><table id="WhoIsOnDutyTableLevel1" class="duty-report-level1">
<caption></caption>
<thead>
<tr>
<th id="WhoIsOnDutyTableLevel1:header:1" class="duty-report-lt-header">Who's on duty for:
January 06, 2012 00:00 -0800</th>
</tr>
</thead>
<tfoot></tfoot>
<tbody>
<tr>
<td headers="WhoIsOnDutyTableLevel1:header:1">
<table id="WhoIsOnDutyTableLevel2" class="duty-report-level2">
<caption></caption>
<thead>
<tr>
<th id="WhoIsOnDutyTableLevel1:header:1">Group Name</th><th id="WhoIsOnDutyTableLevel1:header:2">Group Time Zone</th><th id="WhoIsOnDutyTableLevel1:header:3">Default Devices</th><th id="WhoIsOnDutyTableLevel1:header:4">Supervisors</th>
</tr>
</thead>
<tfoot></tfoot>
<tbody>
<tr>
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="Support" href="/alarmpoint/GroupDetails.do;jsessionid=7pj06dj6krfs?_data=TJZuNquzHUiPj8lqyud7XvypLHHjUnT5bHn7hwtTf9Ei0C2PJ8QYcKIy8OkorCWT8HDTAzkon1ls%0D%0AefuHC1N%2F0SLQLY8nxBhwesdd7Zeg6NzvCfuzRqLg5g%3D%3D" name="Support" class="details">Support</a></td><td headers="WhoIsOnDutyTableLevel1:header:2" class="centered-text">US/Pacific</td><td headers="WhoIsOnDutyTableLevel1:header:3" class="centered-text"><img border="0" src="/static/images/icon_boolean_false.png" alt="No"></td><td headers="WhoIsOnDutyTableLevel1:header:4">
<values>
</values><a id="mgr1" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z4qZ%2FFdHH4hUAixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="mgr1" class="details">Manager 1</a>
</td>
</tr>
<tr>
<td headers="WhoIsOnDutyTableLevel1:header:1" colspan="4" class="no-padding">
<table id="WhoIsOnDutyTableLevel3" class="duty-report-level3">
<caption></caption>
<thead>
<tr>
<th id="WhoIsOnDutyTableLevel1:header:1" class="th-left">Blah_Blah1</th><th id="WhoIsOnDutyTableLevel1:header:2" class="">08:00 - 17:00 TU WE TH FR </th>
</tr>
</thead>
<tfoot></tfoot>
<tbody>
<tr>
<td headers="WhoIsOnDutyTableLevel1:header:1" colspan="2" class="no-padding">
<table id="WhoIsOnDutyTableLevel4" class="duty-report-level4">
<caption></caption>
<thead>
<tr>
<th id="WhoIsOnDutyTableLevel1:header:1">Recipient</th><th id="WhoIsOnDutyTableLevel1:header:2">Category</th><th id="WhoIsOnDutyTableLevel1:header:3">Escalation</th>
</tr>
</thead>
<tfoot></tfoot>
<tbody>
<tr id="205414">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user0" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z6oL%2BaI47zI4gixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="user0" class="details">User 0</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">PERSON</td><td headers="WhoIsOnDutyTableLevel1:header:3">0</td>
</tr>
<tr id="207569">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user1" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z4qZ%2FFdHH4hUAixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="user1" class="details">User 1</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">PERSON</td><td headers="WhoIsOnDutyTableLevel1:header:3">10</td>
</tr>
<tr id="209107">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user2" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z6uKpyoDh%2Fz%2FQixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="uer2" class="details">User 2</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">PERSON</td><td headers="WhoIsOnDutyTableLevel1:header:3">25</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td headers="WhoIsOnDutyTableLevel1:header:1" colspan="4" class="no-padding">
<table id="WhoIsOnDutyTableLevel3" class="duty-report-level3">
<caption></caption>
<thead>
<tr>
<th id="WhoIsOnDutyTableLevel1:header:1" class="th-left">Blah_Blah</th><th id="WhoIsOnDutyTableLevel1:header:2" class="">17:00 Lasting 15:00 WE TH FR </th>
</tr>
</thead>
<tfoot></tfoot>
<tbody>
<tr>
<td headers="WhoIsOnDutyTableLevel1:header:1" colspan="2" class="no-padding">
<table id="WhoIsOnDutyTableLevel4" class="duty-report-level4">
<caption></caption>
<thead>
<tr>
<th id="WhoIsOnDutyTableLevel1:header:1">Recipient</th><th id="WhoIsOnDutyTableLevel1:header:2">Category</th><th id="WhoIsOnDutyTableLevel1:header:3">Escalation</th>
</tr>
</thead>
<tfoot></tfoot>
<tbody>
<tr id="210855">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user0" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z72pjQodq7P5gixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="user0" class="details">User 0</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">PERSON</td><td headers="WhoIsOnDutyTableLevel1:header:3">5</td>
</tr>
<tr id="210529">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user1" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z6r1%2Fmnw2SZ2AixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="user1" class="details">User 1</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">PERSON</td><td headers="WhoIsOnDutyTableLevel1:header:3">10</td>
</tr>
<tr id="210337">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user2" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z6Rwqu8vCtzBAixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="user2" class="details">User 2</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">PERSON</td><td headers="WhoIsOnDutyTableLevel1:header:3">15</td>
</tr>
<tr id="204675">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user3" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z5oj5jdRJbzggixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="user3" class="details">User 3</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">PERSON</td><td headers="WhoIsOnDutyTableLevel1:header:3">20</td>
</tr>
<tr id="205555">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user4" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z4G8e7%2FY9SHyQixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="user4" class="details">User 4</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">PERSON</td><td headers="WhoIsOnDutyTableLevel1:header:3">25</td>
</tr>
<tr id="205004">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user5" href="/alarmpoint/UserDevices.do;jsessionid=7pj06dj6krfs?_data=KpBkJeR08z5XHkcVAMfXqgixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D" name="user5" class="details">User 5</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">PERSON</td><td headers="WhoIsOnDutyTableLevel1:header:3">30</td>
</tr>
<tr id="204718">
<td headers="WhoIsOnDutyTableLevel1:header:1"><a id="user6" href="/alarmpoint/GroupDetails.do;jsessionid=7pj06dj6krfs?_data=TJZuNquzHUiUNEK29yovHscXndexl2jCbHn7hwtTf9Ei0C2PJ8QYcKIy8OkorCWT8HDTAzkon1ls%0D%0AefuHC1N%2F0SLQLY8nxBhwesdd7Zeg6NzvCfuzRqLg5g%3D%3D" name="user6" class="details">User 6</a></td><td headers="WhoIsOnDutyTableLevel1:header:2">GROUP</td><td headers="WhoIsOnDutyTableLevel1:header:3">35</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body></html>
I'm running this in my rails console:
>> onDuty_userList = doc.at_xpath('//*[#id="WhoIsOnDutyTableLevel4"]/tbody/tr')
=> #<Nokogiri::XML::Element:0x1b83804 name="tr" attributes=[#<Nokogiri::XML::Attr:0x1b83764 name="id" value="208894">] children=[#<Nokogiri::XML::Element:0x1b83174 name="td" attributes=[#<Nokogiri::XML::Attr:0x1b83110 name="headers" value="WhoIsOnDutyTableLevel1:header:1">] children=[#<Nokogiri::XML::Element:0x1b82b70 name="a" attributes=[#<Nokogiri::XML::Attr:0x1b82aa8 name="href" value="/alarmpoint/UserDevices.do;jsessionid=3pz7t91kle3?_data=KpBkJeR08z6mdgIY4sPrzAixAYz%2BqH6ZPkanPQ24VqQFpjRFPQiWigQHttJBTMFaCLEBjP6ofpk%2B%0D%0ARqc9DbhWpI1nHAqm8ex%2BxOmu7xYUNxRSU0XUo1xoRw%3D%3D">, #<Nokogiri::XML::Attr:0x1b82a94 name="name" value="xxx">, #<Nokogiri::XML::Attr:0x1b82a80 name="id" value="xxx">, #<Nokogiri::XML::Attr:0x1b82a6c name="class" value="details">] children=[#<Nokogiri::XML::Text:0x1b7b438 "\r\n xxx, xxx (xxx)\r\n ">]>]>, #<Nokogiri::XML::Element:0x1b7b104 name="td" attributes=[#<Nokogiri::XML::Attr:0x1b7b0a0 name="headers" value="WhoIsOnDutyTableLevel1:header:2">] children=[#<Nokogiri::XML::Text:0x1b7aba0 "PERSON">]>, #<Nokogiri::XML::Element:0x1b7a984 name="td" attributes=[#<Nokogiri::XML::Attr:0x1b7a90c name="headers" value="WhoIsOnDutyTableLevel1:header:3">] children=[#<Nokogiri::XML::Text:0x1b7a420 "0">]>, #<Nokogiri::XML::Text:0x1b7a1f0 "\r\n">]>
When I try to select with css value:
>> onDuty_userList.css('WhoIsOnDutyTableLevel1:header:2')
Nokogiri::CSS::SyntaxError: unexpected '2' after ':'
from /home/dan/.rvm/gems/ruby-1.9.2-p290#apraper/gems/nokogiri-1.5.0/lib/nokogiri/css/parser_extras.rb:87:in `on_error'
from /home/dan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/racc/parser.rb:99:in `_racc_do_parse_c'
from /home/dan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/racc/parser.rb:99:in `do_parse'
from /home/dan/.rvm/gems/ruby-1.9.2-p290#apraper/gems/nokogiri-1.5.0/lib/nokogiri/css/parser_extras.rb:62:in `parse'
from /home/dan/.rvm/gems/ruby-1.9.2-p290#apraper/gems/nokogiri-1.5.0/lib/nokogiri/css/parser_extras.rb:79:in `xpath_for'
from /home/dan/.rvm/gems/ruby-1.9.2-p290#apraper/gems/nokogiri-1.5.0/lib/nokogiri/css.rb:23:in `xpath_for'
from /home/dan/.rvm/gems/ruby-1.9.2-p290#apraper/gems/nokogiri-1.5.0/lib/nokogiri/xml/node.rb:211:in `block in css'
from /home/dan/.rvm/gems/ruby-1.9.2-p290#apraper/gems/nokogiri-1.5.0/lib/nokogiri/xml/node.rb:210:in `map'
from /home/dan/.rvm/gems/ruby-1.9.2-p290#apraper/gems/nokogiri-1.5.0/lib/nokogiri/xml/node.rb:210:in `css'
from (irb):129
from /home/dan/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
You need to preface the id with a #.
This should work:
doc.css('#WhoIsOnDutyTableLevel1:header:2')
i have a table in my application.html.erb.like this:
<body>
<table width='100%' border='3'>
<tr><td height="100"> </td></tr>
<tr>
<td width="10%"></td>
<td width="80%"></td>
<td width="10%"></td>
</tr>
</table>
<%= yield %>
</body>
i want to put contents of other page in <td width="80%"></td> but i dont know how can i do that?
thank you for your helps
<body>
<table width='100%' border='3'>
<tr><td height="100"> </td></tr>
<tr>
<td width="10%"></td>
<td width="80%"><%= render "other_page" %></td>
<td width="10%"></td>
</tr>
</table>
<%= yield %>
</body>
This will render _other_page.html.erb.
Read more about it here:
http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials
Simply move the yield statement:
<body>
<table width='100%' border='3'>
<tr>
<td height="100"></td>
</tr>
<tr>
<td width="10%"></td>
<td width="80%"><%= yield %></td>
<td width="10%"></td>
</tr>
</table>
</body>
I created a pdf using TCPDF and I filled it with some php variables and the current date using heredoc syntax
Everything is fine when the pdf is generated and viewed in the browser, but on the saved pdf file the php variable values are not shown, only the date...
I declare my variables at the top like so:
$name = $_POST['name'];
$score = $_POST['percentage'];
$ku_number = $_POST['ku-number'];
$date = Date('d - m - Y');
Only $date is shown on the saved pdf.
Any suggestion?
Thank you
Edit: code to pass the variables to TCPDF
// Print a text
$html = <<<EOF
<!-- EXAMPLE OF CSS STYLE -->
<style>
table{
text-align:center;
color:#000;
}
</style>
<table id="name" cellpadding="0">
<tr>
<td width="10" height="80"> </td>
<td width="620"> </td>
<td width="10"> </td>
</tr>
<tr>
<td> </td>
<td width="620">$name</td>
<td> </td>
</tr>
<tr>
<td width="10"> </td>
<td> </td>
<td width="10"> </td>
</tr>
</table>
<table id="score" cellpadding="0" >
<tr>
<td width="10" height="180"> </td>
<td width="620"> </td>
<td width="10"> </td>
</tr>
<tr>
<td> </td>
<td width="620">$score</td>
<td> </td>
</tr>
<tr>
<td width="10" height="207"> </td>
<td> </td>
<td width="10"> </td>
</tr>
</table>
<table id="ku-number" cellpadding="0" >
<tr height="2">
<td width="50" height="2"></td>
<td width="620" height="2"></td>
<td width="10" height="2"></td>
</tr>
<tr>
<td> </td>
<td width="620" height="20"></td>
<td> </td>
</tr>
<tr>
<td width="50"> </td>
<td>$ku_number</td>
<td > </td>
</tr>
</table>
<table id="date" cellpadding="0" >
<tr height="2">
<td width="50" height="2"></td>
<td width="620" height="2"></td>
<td width="10" height="2"></td>
</tr>
<tr>
<td> </td>
<td width="420" height="20">$date</td>
<td> </td>
</tr>
<tr>
<td width="50"> </td>
<td></td>
<td > </td>
</tr>
</table>
EOF;
$pdf->writeHTML($html, true, false, true, false, '');
//Close and output PDF document
$pdf->Output('certificate.pdf', 'I');
I had the same problem. I found a solution by experimenting things myself mentioned as follows:
Please use concatenation to break $html string into parts. This will surely solve the problem. e.g. I used something like this:
$html = 'HTML CONTENT BREAKS HERE' . $variable_name . 'HTML CONTENT CONTINUES HERE' ;
Normally, most developers will use PHP variable within $html value,
$html = 'HTML CONTENT echo php variable HTML CONTENT' ;
I hope this will work.
Using $_SESSION to store the variables before outputting the PDF solved the problem
Credits go to Yuri Stuken
For more refined results:
Outputting the final PDF:
When you’ve finished creating all required cells, images, links, text etc. you have to call the Output() method to actually get your hands on your dynamically created PDF. This can take no parameters in which case the PDF is sent to the browser, more commonly though, developers specify the filename and the destination of the generated PDF. The destination can be one of four values, these are:
I: send the file inline to the browser.
D: send to the browser and force a file download with the name given by name.
F: save to a local file with the name given by name.
S: return the document as a string.
You can see my code sets the destination value as F:
$pdf->Output(”./pdfs/example.pdf”, “F”);
referenced from:this
Have a bAlaNCeD Life !