Skip to content

Commit

Permalink
pdf creation, fluent/chained, support for empty reports
Browse files Browse the repository at this point in the history
Add PDF export test, update report generation methods

Added a new test method `NoDataSetPdfDiskExport` in `ManualFluentChainedReportDefinitionTest.cs` to verify PDF export functionality without a dataset. Introduced `SmallTestData` method for creating sample reports. Modified `GenerateTestData` to use `WithReportTable` instead of `WithReportItems`.

Updated `Body` class to include `WithReportText` for adding textboxes and changed `WithReportItems` to `WithReportTable`. Enhanced `ReportItemsBody` class to support multiple textboxes and custom report items. Added `BackgroundColor` property to `Style` class for setting background colors of report elements.
  • Loading branch information
majorsilence committed Feb 9, 2025
1 parent f237090 commit 0c202e7
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 10 deletions.
114 changes: 113 additions & 1 deletion RdlCreator.Tests/ManualFluentChainedReportDefinitionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ public async Task PdfDiskExport()
Assert.That(text, Is.EqualTo("Test Data Set Report CategoryID CategoryName Description Beverages Soft drinks, coffees, teas, beers, and ales Condiments Sweet and savory sauces, relishes, spreads, and seasonings Confections Desserts, candies, and sweet breads Dairy Products Cheeses Grains/Cereals Breads, crackers, pasta, and cereal Meat/Poultry Prepared meats Produce Dried fruit and bean curd Seafood Seaweed and fish 1 of 1"));
}

[Test]
public async Task NoDataSetPdfDiskExport()
{
var create = new RdlCreator.Create();
var report = SmallTestData();
var fyiReport = await create.GenerateRdl(report);
using var ms = new Majorsilence.Reporting.Rdl.MemoryStreamGen();
await fyiReport.RunGetData(null);
await fyiReport.RunRender(ms, Majorsilence.Reporting.Rdl.OutputPresentationType.PDF);
var pdfStream = ms.GetStream();
pdfStream.Position = 0;

using var fileStream = new FileStream("NoDataSetExport.pdf", FileMode.Create, FileAccess.Write);
pdfStream.CopyTo(fileStream);
await fileStream.DisposeAsync();

using var pdfDocument = PdfDocument.Open("NoDataSetExport.pdf");
var text = string.Join(" ", pdfDocument.GetPages().SelectMany(page => page.GetWords()).Select(word => word.Text));

Assert.That(text, Is.Not.Null);
Assert.That(text, Is.EqualTo("Test Header Text Area 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 1 of 1"));
}


private RdlCreator.Report GenerateTestData()
{
Expand Down Expand Up @@ -157,7 +180,7 @@ private RdlCreator.Report GenerateTestData()
report
.WithBody()
.WithHeight("36pt")
.WithReportItems()
.WithReportTable()
.WithTableName("Table1")
.WithDataSetName("Data")
.WithNoRows("Query returned no rows!")
Expand Down Expand Up @@ -302,5 +325,94 @@ private RdlCreator.Report GenerateTestData()

return report;
}

private RdlCreator.Report SmallTestData()
{

var report = new Report
{
Description = "Sample report",
Author = "John Doe",
PageHeight = "11in",
PageWidth = "8.5in",
Width = "7.5in",
TopMargin = ".25in",
LeftMargin = ".25in",
RightMargin = ".25in",
BottomMargin = ".25in"
}
.WithPageHeader(
new PageHeader
{
Height = ".5in",
ReportItems = new ReportItemsHeader
{
Textbox = new Textbox
{
Name = "Header",
Top = ".1in",
Left = ".1in",
Width = "6in",
Height = ".25in",
Value = new Value { Text = "Test Header" },
Style = new Style { FontSize = "15pt", FontWeight = "Bold" }
}
},
PrintOnFirstPage = "true",
PrintOnLastPage = "true"
})
.WithPageFooter(new PageFooter
{
Height = "14pt",
ReportItems = new ReportItemsFooter
{
Textbox = new Textbox
{
Name = "Footer",
Top = "1pt",
Left = "10pt",
Height = "12pt",
Width = "3in",
Value = new Value { Text = "=Globals!PageNumber + ' of ' + Globals!TotalPages" },
Style = new Style { FontSize = "10pt", FontWeight = "Normal" }
}
},
PrintOnFirstPage = "true",
PrintOnLastPage = "true"
});

// Add a body to the report

report
.WithBody()
.WithHeight("36pt")
.WithReportText(new Textbox
{
Name = "Textbox1",
Top = ".1in",
Left = ".1in",
Width = "6in",
Height = ".25in",
Value = new Value { Text = "Text Area 1" },
Style = new Style { FontSize = "12pt", FontWeight = "Bold" }
})
.WithReportText(new Textbox
{
Name = "Textbox2",
Top = "1in",
Left = "1in",
Width = "6in",
Height = "4in",
Value = new Value { Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." },
Style = new Style
{
FontSize = "12pt",
BackgroundColor = "gray"
}
});

return report;
}

}
}
26 changes: 23 additions & 3 deletions RdlCreator/Body.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,41 @@ namespace Majorsilence.Reporting.RdlCreator

public class Body
{
[XmlElement(ElementName = "ReportItems")]
[XmlElement("ReportItems", typeof(ReportItemsBody))]
public ReportItemsBody ReportItems { get; set; }

[XmlElement(ElementName = "Height")]
public string Height { get; set; }

public Table WithReportItems()
public Table WithReportTable()
{
this.ReportItems = new ReportItemsBody()
{
Table = new Table()
Table = new Table(),
Text = new List<Textbox>()
};
return ReportItems.Table;
}

public Body WithReportText(Textbox textbox)
{
if (this.ReportItems == null)
{
this.ReportItems = new ReportItemsBody()
{
Text = new List<Textbox>()
};

this.ReportItems.Text.Add(textbox);
}
else
{
this.ReportItems.Text.Add(textbox);
}

return this;
}

public Body WithHeight(string height)
{
this.Height = height;
Expand Down
15 changes: 9 additions & 6 deletions RdlCreator/ReportItemsBody.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Xml.Serialization;


namespace Majorsilence.Reporting.RdlCreator
{
public class ReportItemsBody
{

[XmlElement(ElementName = "Table")]
public Table Table { get; set; }

public ReportItemsBody WithTable(Table table)
{
this.Table = table;
return this;
}
[XmlElement("Textbox", typeof(Textbox))]
public List<Textbox> Text { get; set; }

[XmlElement("CustomReportItem", typeof(CustomReportItems))]
public List<CustomReportItems> CustomReportItems { get; set; }

}
}
3 changes: 3 additions & 0 deletions RdlCreator/Style.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ public class Style
[XmlElement(ElementName = "BorderWidth")]
public BorderWidth BorderWidth { get; set; }

[XmlElement(ElementName = "BackgroundColor")]
public string BackgroundColor { get; set; }

}
}

0 comments on commit 0c202e7

Please sign in to comment.