});
Engine.Handlebars
for the header merge operation
the string is
function getPageNumber (pageIndex) {
if (pageIndex == null) {
return ''
}
const pageNumber = pageIndex + 1
return pageNumber
}
function getTotalPages (pages) {
if (!pages) {
return ''
}
return pages.length
}
Hi... I am trying to access the $pdf object in my handlebars template so that I can write conditional logic for the PDF header based on the pageNumber..... but I am unable to manage to get the $pdf variable working... it probably seems to stay undefined... I tried different ways but I am not able to make it work... PLEASE SOMEONE KINDLY HELP ME..
more info: using jsreport-core https://github.com/jsreport/jsreport-core in nodejs
I'm back! I was able to reproduce this using the toc template. Using 2.10.0 you'll notice that the page numbers don't display on the toc. If you run this using 2.6.0 and 1.5.1 pdf-utils, they display fine.
string strDocx = _env.WebRootPath + "\\reports\\CV.docx";
FileInfo fileInfoMain = new FileInfo(strDocx);
if (fileInfoMain.Exists)
{
FileStream fileStream = fileInfoMain.Open(FileMode.Open, FileAccess.Read);
using StreamReader reader = new StreamReader(fileStream);
strDocx = await reader.ReadToEndAsync().ConfigureAwait(true);
await fileStream.DisposeAsync().ConfigureAwait(true);
}
strDocx = strDocx.Replace(Environment.NewLine, string.Empty, StringComparison.InvariantCulture);
Asset myAsset = new jsreport.Types.Asset();
myAsset.Content = strDocx;
jsreport.Types.Report report = await _jsReportMvcService.RenderAsync(new RenderRequest()
{
Template = new Template
{
Engine = Engine.Handlebars,
Recipe = Recipe.Docx,
Docx = new Docx {
TemplateAsset = myAsset
}
},
Data = null
})
.ConfigureAwait(true);
string strDocx = _env.WebRootPath + "\\reports\\CV.docx";
FileInfo fileInfoMain = new FileInfo(strDocx);
if (fileInfoMain.Exists)
{
FileStream fileStream = fileInfoMain.Open(FileMode.Open, FileAccess.Read);
using StreamReader reader = new StreamReader(fileStream);
strDocx = await reader.ReadToEndAsync().ConfigureAwait(true);
await fileStream.DisposeAsync().ConfigureAwait(true);
}
byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes(strDocx);
string strDocTemplate = Convert.ToBase64String(plainTextBytes);
jsreport.Types.Report report = await _jsReportMvcService.RenderAsync(new RenderRequest()
{
Template = new Template
{
Engine = Engine.Handlebars,
Recipe = Recipe.Docx,
Docx = new Docx
{
TemplateAsset = new Asset
{
Encoding = "base64",
Content = strDocTemplate
}
}
},
Data = new
{
message = "Hello world"
}
})
.ConfigureAwait(true);
rs.StartAsync().Wait();
services.AddJsReport(rs);