Hi,
I’ve been having a problem using the ReportingEngine where whitespace is being removed from my output document and think I have narrowed it down to the JsonDataSource.
I have provided some C# code below which should demonstrate the issue.
The code outputs 2 documents, one which uses the JsonDataSource and one which uses DataSourcesNames/DataSources. I pass the same values to both of them, but when the JsonDataSource is used it seems to strip out the whitespace completely.
Json Output
Other Output
var reportingEngine = new ReportingEngine();
var doc = new Document();
doc.EnsureMinimum();
var builder = new DocumentBuilder(doc);
builder.MoveToDocumentStart();
builder.Write("LINE BEFORE");
builder.InsertParagraph();
builder.Write("<<[LineWhitespace]>>");
builder.InsertParagraph();
builder.Write("<<[BlockWhitespace]>>");
builder.Write("LINE AFTER");
// JSON
var jsonDoc = doc.Clone();
var json = "{" +
" \"LineWhitespace\" : \" \"," +
" \"BlockWhitespace\" : \"\r\n\r\n\r\n\r\n\"" +
"}";
var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(json));
var jsonDataSource = new JsonDataSource(jsonStream, new JsonDataLoadOptions { SimpleValueParseMode = JsonSimpleValueParseMode.Strict });
jsonStream.Dispose();
reportingEngine.BuildReport(jsonDoc, jsonDataSource);
var jsonFileName = Path.GetTempPath() + "Json.docx";
jsonDoc.Save(jsonFileName);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(jsonFileName) { UseShellExecute = true });
// OTHER
var otherDoc = doc.Clone();
var otherDataSources = new object[] { " ", "\r\n\r\n\r\n\r\n" };
var otherDataSourceNames = new string[] { "LineWhitespace", "BlockWhitespace" };
reportingEngine.BuildReport(otherDoc, otherDataSources, otherDataSourceNames);
var otherFileName = Path.GetTempPath() + "Other.docx";
otherDoc.Save(otherFileName);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(otherFileName) { UseShellExecute = true });