-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from xingchenyang/master
add attribute newPage to create a new page for a row or a table inside body tag
- Loading branch information
Showing
13 changed files
with
282 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="fr.cedricmartel.SampleItextSharp.NewPages.Default" MasterPageFile="../Master.Master" %> | ||
|
||
<asp:Content ContentPlaceHolderID="PageContent" runat="server"> | ||
<h2> | ||
New pages | ||
<asp:Button runat="server" Text="Génération PDF" OnClick="GenerationPdf" CssClass="btn btn-primary btn-sm btn-lg" /> | ||
</h2> | ||
<p class="well"> | ||
<asp:Label runat="server" ID="Resulat" ></asp:Label> | ||
</p> | ||
</asp:Content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Hashtable>(), | ||
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: <a href='../Output/" + fileName + "'>" + fileName + "</a><br/><br/><iframe src='../Output/" + fileName + "' width='1024' height='600' />"; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<pagedef pagesize="A4" margin_left="10" margin_right="10" margin_top="10" margin_bottom="10" pageorientation="portrait"> | ||
|
||
<header> | ||
<row> | ||
<font fontstyle="BoldItalic" fontsize="11"> | ||
<image src="{logoUrl}" align="center" height="80" width="100" > | ||
<var name="{logoUrl}" /> | ||
</image> | ||
<textbox text="" width="5%"/> | ||
<textblock width="70%" height="50" align="left" text="{titreDocument}" > | ||
<var name="{titreDocument}" /> | ||
</textblock> | ||
</font> | ||
</row> | ||
|
||
<!--séparateur--> | ||
<row> | ||
<font fontsize="16"> | ||
<textbox width="100%" /> | ||
</font> | ||
</row> | ||
</header> | ||
|
||
<body> | ||
<row> | ||
<textblock width="100%" align="left" text="Text before a new page" /> | ||
</row> | ||
<row> | ||
<textblock width="100%" align="left" text="Another text before a new page" /> | ||
</row> | ||
|
||
<row newPage="true"> | ||
<textblock width="100%" align="left" text="Text with the attribute newPage" /> | ||
</row> | ||
|
||
<table newPage="true" tablewidth="100%" cellperrow="6" cellwidth="1,2,2,1,1,1" width="100%" var="{NewPageTable}"> | ||
<tablehead> | ||
<tablerow> | ||
<tablecell border="Top, Bottom" backgroundcolor="#9BCFF9"> | ||
<textbox text="Date"></textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom" backgroundcolor="#9BCFF9"> | ||
<textbox text="Centre"></textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom" backgroundcolor="#9BCFF9"> | ||
<textbox text="Frais"></textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom" backgroundcolor="#9BCFF9"> | ||
<textbox text="Nombre"></textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom" backgroundcolor="#9BCFF9"> | ||
<textbox text="Base"></textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom" backgroundcolor="#9BCFF9"> | ||
<textbox text="Montant" align="right"></textbox> | ||
</tablecell> | ||
</tablerow> | ||
</tablehead> | ||
|
||
<tableloop> | ||
<tablerow> | ||
<tablecell border="Top, Bottom"> | ||
<textbox text="{Date}"> | ||
<var name="{Date}" formatter="datetime" formatterparameters="formatstring=dd/MM/yyyy" /> | ||
</textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom"> | ||
<textbox text="{Centre}"> | ||
<var name="{Centre}" /> | ||
</textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom"> | ||
<textbox text="{Frais}"> | ||
<var name="{Frais}" /> | ||
</textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom"> | ||
<textbox text="{Nombre}"> | ||
<var name="{Nombre}" /> | ||
</textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom"> | ||
<textbox text="{Base}"> | ||
<var name="{Base}" /> | ||
</textbox> | ||
</tablecell> | ||
<tablecell border="Top, Bottom"> | ||
<textbox text="{Montant}" align="right"> | ||
<var name= "{Montant}" formatter="number" formatterparameters="formatstring=0.00€" /> | ||
</textbox> | ||
</tablecell> | ||
</tablerow> | ||
</tableloop> | ||
</table> | ||
|
||
<row> | ||
<textblock width="100%" align="left" text="text after the last table" /> | ||
</row> | ||
</body> | ||
|
||
|
||
<footer y="50" absolute="yes"> | ||
|
||
<!--separating bar with padding--> | ||
<row> | ||
<textbox text=""/> | ||
</row> | ||
<row> | ||
<line x1="-1" x2="-1" width="100%" linethickness="0.1" /> | ||
</row> | ||
<row> | ||
<textbox text=""/> | ||
</row> | ||
|
||
<!--footer text--> | ||
<row> | ||
<font fontsize="8" fonttype="Helvetica"> | ||
|
||
<textblock width="50%" align="left" text="{titreDocument}" > | ||
<var name="{titreDocument}" /> | ||
</textblock> | ||
|
||
<pagenumber width="50%" text="Page {__PAGE__} of {__TOTALPAGE__}" align="right"> | ||
<var name="{__PAGE__}" optional="yes" /> | ||
<var name="{__TOTALPAGE__}" optional="yes"/> | ||
</pagenumber> | ||
</font> | ||
</row> | ||
</footer> | ||
|
||
</pagedef> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters