diff --git a/Moon.PDFTemplateItextSharp/Generators/BodyGenerator.cs b/Moon.PDFTemplateItextSharp/Generators/BodyGenerator.cs
index f17ec99..69460fd 100644
--- a/Moon.PDFTemplateItextSharp/Generators/BodyGenerator.cs
+++ b/Moon.PDFTemplateItextSharp/Generators/BodyGenerator.cs
@@ -55,6 +55,13 @@ public void DrawBody(Hashtable data, IPDFDraw drawer)
{
Y = Helper.GetFloatAttributeValue("y", bodyNode.Attributes, -1)
};
+ // add new page if the attribute "newPage" == "true"
+ var newPageAttribute = itemNode.Attributes?["newPage"];
+ if (newPageAttribute != null && newPageAttribute.Value == "true")
+ {
+ pdfTemplate.NextPage();
+ pdfTemplate.DrawHeader();
+ }
rowGroup.AddRow(pdfTemplate._buildRow(itemNode, font));
pdfTemplate.DrawRowGroup(rowGroup, data, DocumentGroup.Body);
}
@@ -66,6 +73,13 @@ public void DrawBody(Hashtable data, IPDFDraw drawer)
var keyAttribute = itemNode.Attributes["var"];
if (keyAttribute == null || !data.ContainsKey(keyAttribute.Value))
continue;
+ // add new page if the attribute "newPage" == "true"
+ var newPageAttribute = itemNode.Attributes?["newPage"];
+ if (newPageAttribute != null && newPageAttribute.Value == "true")
+ {
+ pdfTemplate.NextPage();
+ pdfTemplate.DrawHeader();
+ }
var tableParameters = data[keyAttribute.Value];
if (!(tableParameters is TableData))
throw new Exception("table parameter must be of type TableData");
diff --git a/README.md b/README.md
index f499084..97360e8 100644
--- a/README.md
+++ b/README.md
@@ -12,11 +12,11 @@ This project is using iTextSharp to generate the PDF.
http://sourceforge.net/projects/itextsharp
-Working copy for following patches :
+Working copy for following patches :
- OK - add a sample asp.net app
- OK - support for multiple tables inside body tag
- OK - table won't show if associated data is null
- OK - add condition on body items to hide item if associated data is null
- - OK - add support for dynamic background color inside table cells
+ - OK - add support for dynamic background color inside table cells
+ - OK - add attribute newPage to create a new page for a row or a table inside body tag
-
diff --git a/SampleItextSharp/ConditionalDisplay/Default.aspx.cs b/SampleItextSharp/ConditionalDisplay/Default.aspx.cs
index 310fe7b..fd92435 100644
--- a/SampleItextSharp/ConditionalDisplay/Default.aspx.cs
+++ b/SampleItextSharp/ConditionalDisplay/Default.aspx.cs
@@ -57,7 +57,7 @@ protected void GenerationPdf(object sender, EventArgs e)
// save file locally
string fileDirectory = Server.MapPath("../Output/");
- string fileName = "SimpleTest-" + String.Format("{0:yyyyMMdd-HHmmss}", DateTime.Now) + ".pdf";
+ string fileName = "ConditionalDisplay-" + String.Format("{0:yyyyMMdd-HHmmss}", DateTime.Now) + ".pdf";
using (var filePdf = new FileStream(fileDirectory + fileName, FileMode.Create))
{
using (MemoryStream stream = pdfTemplate.Close())
diff --git a/SampleItextSharp/Master.Master b/SampleItextSharp/Master.Master
index d36f4a3..f8e722d 100644
--- a/SampleItextSharp/Master.Master
+++ b/SampleItextSharp/Master.Master
@@ -37,6 +37,7 @@
diff --git a/SampleItextSharp/Master.Master.designer.cs b/SampleItextSharp/Master.Master.designer.cs
index 99f301a..927fe6a 100644
--- a/SampleItextSharp/Master.Master.designer.cs
+++ b/SampleItextSharp/Master.Master.designer.cs
@@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
-//
-// Ce code a été généré par un outil.
+//
+// This code was generated by a tool.
//
-// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
-// le code est régénéré.
-//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
//------------------------------------------------------------------------------
namespace fr.cedricmartel.SampleItextSharp {
@@ -13,20 +13,20 @@ namespace fr.cedricmartel.SampleItextSharp {
public partial class Master {
///
- /// Contrôle HeadContent.
+ /// HeadContent control.
///
///
- /// Champ généré automatiquement.
- /// Pour modifier, déplacez la déclaration de champ du fichier de concepteur dans le fichier code-behind.
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
///
protected global::System.Web.UI.WebControls.ContentPlaceHolder HeadContent;
///
- /// Contrôle PageContent.
+ /// PageContent control.
///
///
- /// Champ généré automatiquement.
- /// Pour modifier, déplacez la déclaration de champ du fichier de concepteur dans le fichier code-behind.
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
///
protected global::System.Web.UI.WebControls.ContentPlaceHolder PageContent;
}
diff --git a/SampleItextSharp/MultipleTables/Default.aspx.cs b/SampleItextSharp/MultipleTables/Default.aspx.cs
index 7262042..c102ee8 100644
--- a/SampleItextSharp/MultipleTables/Default.aspx.cs
+++ b/SampleItextSharp/MultipleTables/Default.aspx.cs
@@ -55,7 +55,7 @@ protected void GenerationPdf(object sender, EventArgs e)
// save file locally
string fileDirectory = Server.MapPath("../Output/");
- string fileName = "SimpleTest-" + String.Format("{0:yyyyMMdd-HHmmss}", DateTime.Now) + ".pdf";
+ string fileName = "MultipleTables-" + String.Format("{0:yyyyMMdd-HHmmss}", DateTime.Now) + ".pdf";
using (var filePdf = new FileStream(fileDirectory + fileName, FileMode.Create))
{
using (MemoryStream stream = pdfTemplate.Close())
diff --git a/SampleItextSharp/NewPages/Default.aspx b/SampleItextSharp/NewPages/Default.aspx
new file mode 100644
index 0000000..f724e35
--- /dev/null
+++ b/SampleItextSharp/NewPages/Default.aspx
@@ -0,0 +1,11 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="fr.cedricmartel.SampleItextSharp.NewPages.Default" MasterPageFile="../Master.Master" %>
+
+
+
+ New pages
+
+
+
+
+
+
diff --git a/SampleItextSharp/NewPages/Default.aspx.cs b/SampleItextSharp/NewPages/Default.aspx.cs
new file mode 100644
index 0000000..eb012c0
--- /dev/null
+++ b/SampleItextSharp/NewPages/Default.aspx.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Web.UI;
+using Moon.PDFTemplateItextSharp.Model;
+
+namespace fr.cedricmartel.SampleItextSharp.NewPages
+{
+ public partial class Default : Page
+ {
+ private readonly Hashtable headerData = new Hashtable();
+ private readonly Hashtable bodyData = new Hashtable();
+ private readonly Hashtable footerData = new Hashtable();
+
+ protected void GenerationPdf(object sender, EventArgs e)
+ {
+ // templates load
+ var template = Server.MapPath("test.xml");
+ var pdfTemplate = new Moon.PDFTemplateItextSharp.PDFTemplateItextSharp(template);
+ // TODO fonts externes
+
+ // parameters load
+ headerData.Add("{titreDocument}", "SERVICE DEPARTEMENTAL D'INCENDIE \nET DE SECOURS DES DEUX-SEVRES");
+ headerData.Add("{logoUrl}", Server.MapPath("LogoPdf.jpg"));
+ footerData.Add("{titreDocument}", "Titre du document");
+
+ // data load
+ var newPageTable = new TableData
+ {
+ HeadData = new Hashtable(),
+ LoopData = new List(),
+ FootData = new Hashtable()
+ };
+ DateTime debut = new DateTime(2016, 1, 1);
+ for (int i = 0; i < 100; i++)
+ {
+ var donnees1 = new Hashtable
+ {
+ {"{Date}", debut.AddDays(i)},
+ {"{Centre}", "Centre 1"},
+ {"{Frais}", 5},
+ {"{Nombre}", "200,00"},
+ {"{Base}", "5,00"},
+ {"{Montant}", i}
+ };
+ newPageTable.LoopData.Add(donnees1);
+ }
+ newPageTable.FootData.Add("{Total}", 250.5);
+ bodyData.Add("{NewPageTable}", newPageTable);
+
+ // pdf generation
+ pdfTemplate.Draw(headerData, bodyData, footerData);
+
+ // save file locally
+ string fileDirectory = Server.MapPath("../Output/");
+ string fileName = "NewPages-" + String.Format("{0:yyyyMMdd-HHmmss}", DateTime.Now) + ".pdf";
+ using (var filePdf = new FileStream(fileDirectory + fileName, FileMode.Create))
+ {
+ using (MemoryStream stream = pdfTemplate.Close())
+ {
+ byte[] content = stream.ToArray();
+ filePdf.Write(content, 0, content.Length);
+ }
+ }
+
+ Resulat.Text = "Generated PDF: " + fileName + "
";
+ }
+ }
+}
\ No newline at end of file
diff --git a/SampleItextSharp/NewPages/Default.aspx.designer.cs b/SampleItextSharp/NewPages/Default.aspx.designer.cs
new file mode 100644
index 0000000..de1a6e7
--- /dev/null
+++ b/SampleItextSharp/NewPages/Default.aspx.designer.cs
@@ -0,0 +1,24 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace fr.cedricmartel.SampleItextSharp.NewPages {
+
+
+ public partial class Default {
+
+ ///
+ /// Resulat control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label Resulat;
+ }
+}
diff --git a/SampleItextSharp/NewPages/LogoPdf.jpg b/SampleItextSharp/NewPages/LogoPdf.jpg
new file mode 100644
index 0000000..00518a9
Binary files /dev/null and b/SampleItextSharp/NewPages/LogoPdf.jpg differ
diff --git a/SampleItextSharp/NewPages/test.xml b/SampleItextSharp/NewPages/test.xml
new file mode 100644
index 0000000..4bf57a1
--- /dev/null
+++ b/SampleItextSharp/NewPages/test.xml
@@ -0,0 +1,132 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+