diff --git a/src/DoddleReport.Sample.WinForms/DoddleReport.Sample.WinForms.csproj b/src/DoddleReport.Sample.WinForms/DoddleReport.Sample.WinForms.csproj
index 842d735..a2cddd4 100644
--- a/src/DoddleReport.Sample.WinForms/DoddleReport.Sample.WinForms.csproj
+++ b/src/DoddleReport.Sample.WinForms/DoddleReport.Sample.WinForms.csproj
@@ -85,6 +85,10 @@
{355CAFF3-F806-4194-BE54-2F7640463CED}
DoddleReport.AbcPdf
+
+ {347d0716-0297-4866-9fd5-5e019b51c408}
+ DoddleReport.iTextSharp
+
{0646C575-0EA6-4331-809C-10DC000929F3}
DoddleReport.OpenXml
@@ -94,6 +98,11 @@
DoddleReport
+
+
+ Always
+
+
+
@@ -68,9 +69,10 @@
-
+
+
@@ -85,9 +87,10 @@
-
+
+
@@ -109,9 +112,9 @@
2.0
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
\ No newline at end of file
diff --git a/src/DoddleReport.Sample.WinForms/Resources/Logomakr.png b/src/DoddleReport.Sample.WinForms/Resources/Logomakr.png
new file mode 100644
index 0000000..0c602d4
Binary files /dev/null and b/src/DoddleReport.Sample.WinForms/Resources/Logomakr.png differ
diff --git a/src/DoddleReport.iTextSharp/PdfReportWriter.cs b/src/DoddleReport.iTextSharp/PdfReportWriter.cs
index c12b95d..62610f3 100644
--- a/src/DoddleReport.iTextSharp/PdfReportWriter.cs
+++ b/src/DoddleReport.iTextSharp/PdfReportWriter.cs
@@ -6,6 +6,7 @@
using iTextSharp.text.pdf;
using Font = iTextSharp.text.Font;
using Rectangle = iTextSharp.text.Rectangle;
+using Image = iTextSharp.text.Image;
namespace DoddleReport.iTextSharp
{
@@ -108,10 +109,10 @@ protected virtual void RenderHeader(PdfPTable globalTable, ReportTextFieldCollec
RenderHintsCollection renderHints)
{
int rowCount = 0;
+
if (!string.IsNullOrEmpty(textFields.Title))
{
- ReportStyle reportStyle = renderHints[TitleStyle] as ReportStyle ?? GetDefaultTitleStyle();
- globalTable.AddCell(CreateTextCell(reportStyle, renderHints[FontFamily] as string, textFields.Title));
+ globalTable.AddCell(CreateTitleCell(textFields.Title, renderHints));
rowCount++;
}
@@ -140,6 +141,57 @@ protected virtual void RenderHeader(PdfPTable globalTable, ReportTextFieldCollec
globalTable.HeaderRows = rowCount;
}
+ ///
+ /// Creates a new Title cell
+ ///
+ /// Title text.
+ /// The render hints.
+ /// The newly created Title cell
+ private static PdfPCell CreateTitleCell(string titleText, RenderHintsCollection renderHints)
+ {
+ var reportTitleStyle = renderHints[TitleStyle] as ReportTitleStyle ?? GetDefaultTitleStyle();
+ var reportStyle = renderHints[TitleStyle] as ReportStyle ?? GetDefaultTitleStyle();
+
+ var table = new PdfPTable(2);
+ table.SetWidths(new[] { reportTitleStyle.ImageWidthPercentage, (100 - reportTitleStyle.ImageWidthPercentage)});
+
+ if (reportTitleStyle.Image != null)
+ {
+ table.AddCell(CreateImageCell(reportTitleStyle.Image));
+ }
+ else
+ {
+ table.AddCell(CreateEmptyCell());
+ }
+
+ table.AddCell(CreateTextCell(reportStyle, renderHints[FontFamily] as string, titleText));
+
+
+ var headerTableCell = new PdfPCell(table) {Border = 0};
+ return headerTableCell;
+ }
+
+ ///
+ /// Creates a new Image cell
+ ///
+ /// The image details
+ /// The newly created Image cell
+ private static PdfPCell CreateImageCell(ReportImage imageDetails)
+ {
+ var headerImage = Image.GetInstance(imageDetails.ImageData);
+ headerImage.ScaleToFit(imageDetails.Width, imageDetails.Height);
+ return new PdfPCell(headerImage) {Border = 0};
+ }
+
+ ///
+ /// Creates an Empty cell
+ ///
+ /// The empty cell
+ private static PdfPCell CreateEmptyCell()
+ {
+ return new PdfPCell() { Border = 0 };
+ }
+
///
/// Renders the footer.
///
@@ -161,14 +213,15 @@ protected virtual void RenderFooter(PdfPTable globalTable, ReportTextFieldCollec
/// Gets the default title style.
///
/// The default title style.
- private static ReportStyle GetDefaultTitleStyle()
+ private static ReportTitleStyle GetDefaultTitleStyle()
{
- return new ReportStyle
- {
- Bold = true,
- FontSize = 18,
- HorizontalAlignment = HorizontalAlignment.Center
- };
+ return new ReportTitleStyle
+ {
+ Bold = true,
+ FontSize = 18,
+ HorizontalAlignment = HorizontalAlignment.Center,
+ ImageWidthPercentage = 0
+ };
}
///
diff --git a/src/DoddleReport/DoddleReport.csproj b/src/DoddleReport/DoddleReport.csproj
index a4b111e..a920f8c 100644
--- a/src/DoddleReport/DoddleReport.csproj
+++ b/src/DoddleReport/DoddleReport.csproj
@@ -89,8 +89,10 @@
+
+
diff --git a/src/DoddleReport/ReportImage.cs b/src/DoddleReport/ReportImage.cs
new file mode 100644
index 0000000..9c5bfb0
--- /dev/null
+++ b/src/DoddleReport/ReportImage.cs
@@ -0,0 +1,9 @@
+namespace DoddleReport
+{
+ public class ReportImage
+ {
+ public byte[] ImageData { get; set; }
+ public int Width { get; set; }
+ public int Height { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/DoddleReport/ReportTitleStyle.cs b/src/DoddleReport/ReportTitleStyle.cs
new file mode 100644
index 0000000..06f71e7
--- /dev/null
+++ b/src/DoddleReport/ReportTitleStyle.cs
@@ -0,0 +1,8 @@
+namespace DoddleReport
+{
+ public class ReportTitleStyle : ReportStyle
+ {
+ public ReportImage Image { get; set; }
+ public int ImageWidthPercentage { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/DoddleReport/Writers/ExcelReportWriter.cs b/src/DoddleReport/Writers/ExcelReportWriter.cs
index 3dd2645..dcfc545 100644
--- a/src/DoddleReport/Writers/ExcelReportWriter.cs
+++ b/src/DoddleReport/Writers/ExcelReportWriter.cs
@@ -8,6 +8,7 @@ protected override void RenderHeader(ReportTextFieldCollection textFields, Rende
{
Html.AppendLine(ExcelHeaderHtml(textFields));
WrapHeadAndBody = true;
+ IgnoreTitleImage = true;
base.RenderHeader(textFields, hints);
diff --git a/src/DoddleReport/Writers/HtmlReportWriter.cs b/src/DoddleReport/Writers/HtmlReportWriter.cs
index 67387a5..6f1f89d 100644
--- a/src/DoddleReport/Writers/HtmlReportWriter.cs
+++ b/src/DoddleReport/Writers/HtmlReportWriter.cs
@@ -6,11 +6,19 @@ namespace DoddleReport.Writers
{
public class HtmlReportWriter : IReportWriter
{
+ public const string TitleStyle = "TitleStyle";
+ public const string SubTitleStyle = "SubTitleStyle";
+ public const string HeaderStyle = "HeaderStyle";
public const string HtmlStyle = "HtmlStyle";
public const string HtmlLogo = "HtmlLogo";
protected StringBuilder Html { get; private set; }
protected virtual bool WrapHeadAndBody { get; set; }
+ ///
+ /// Tells the writer to ignore the Image passed via TitleStyle render hints.
+ /// Used in ExcelReportWriter
+ ///
+ protected virtual bool IgnoreTitleImage { get; set; }
public HtmlReportWriter()
@@ -32,22 +40,48 @@ protected virtual string InternalStyling()
///
/// This CSS style will be applied to the top of every report. You may override this property to customize the default CSS that gets rendered on all HTML reports
///
- public static string DefaultStyle
+ public static string GetDefaultStyle()
{
- get
- {
- var style = @"
+
+ var style = @"
.htmlReport { font: 12px Verdana; }
.htmlReport h1 { font-size: 12pt; margin-bottom: 10px; }
- .htmlReport .title { margin-bottom: 1px; }
+ .htmlReport .titleImage { vertical-align:middle; }
+ .htmlReport .title { margin-bottom: 1px; vertical-align:middle; }
.htmlReport .subTitle { margin-bottom: 3px; margin-top: 1px; }
.htmlReport .header { padding-bottom: 8px; border-bottom: solid 1px #ccc; } \r\n";
+
+ style += ".htmlReport td { " + ReportStyle.HeaderRowStyle.ToCss() + "}\r\n";
+ style += ".htmlReport th { " + ReportStyle.DataRowStyle.ToCss() + "}\r\n";
+
+ return style;
+ }
- style += ".htmlReport td { " + ReportStyle.HeaderRowStyle.ToCss() + "}\r\n";
- style += ".htmlReport th { " + ReportStyle.DataRowStyle.ToCss() + "}\r\n";
+ ///
+ /// Generates the custom CSS styles passed in via the render hints
+ ///
+ public static string GetCustomStyle(RenderHintsCollection hints)
+ {
+
+ var style = string.Empty;
- return style;
+ var titleStyle = hints[TitleStyle] as ReportStyle;
+ if (titleStyle != null)
+ {
+ style += ".htmlReport .titleHint { " + titleStyle.ToCss() + "}\r\n";
}
+ var subTitleStyle = hints[SubTitleStyle] as ReportStyle;
+ if (subTitleStyle != null)
+ {
+ style += ".htmlReport .subTitleHint { " + subTitleStyle.ToCss() + "}\r\n";
+ }
+ var headerStyle = hints[HeaderStyle] as ReportStyle;
+ if (headerStyle != null)
+ {
+ style += ".htmlReport .headerHint { " + headerStyle.ToCss() + "}\r\n";
+ }
+
+ return style;
}
protected void AppendStyling(RenderHintsCollection hints)
@@ -56,9 +90,12 @@ protected void AppendStyling(RenderHintsCollection hints)
Html.AppendLine(@"