This project is read-only.
Table tag, Font, Example

The xml layout have 4 main section
1. header
2. loop
3. body
4. footer

These is what you will need to repeatedly generate your SO or Invoice.
It start from the header section, substitute your data into the xml template section and draw to the pdf.
When the loop section are having a lot of data, then it will need to draw on the next page,
the header will repeat on every page if the loop data is more than 1 page.
The body section will draw after the loop section.
The footer section, if you do not specified a "y" attribute, it will draw after the body section.
If a "y" position is provided, it will start to draw at the y position.

PDF coordinate x and y
A4 = 595, 842
/* x,y
* top page
* 0,842 595,842
* 0,0 595,0
* bottom page
when you specified y="300" in the footer section
It will start draw the footer section at the 300 position. If the current page y is less than 300 (already draw by body or loop), it will add a new page and the footer section will draw at the new page y=300 position. Of cause the header will repeated.

What is the available space for my footer section:
footer height(space) = y - Margin_bottom

row height = the biggest height or fontsize in that particular row.
footer height will occupied by row = sum up all the rows height.
Please make sure you have enough space for all you footer rows when you specified footer "y".

Inside of every section, will begin by the <row> tag.
A row is a line in your pdf document. You define what are fit into 1 row of your page.
PDFTemplate is drawing row by row to the pdf. From the top to the bottom.

Limitation of row:
If the text in a row of it's width cannot fit, text will be truncated.
You will need to use <table> if you need to span your text. Table tag

What can I draw to PDF
  • <textbox> text
  • <textblock> text block
  • <line> line
  • <image> image

How to use

Add Reference to your project
  • itextsharp.dll
  • Moon.PDFDraw.dll
  • Moon.PDFDrawItextSharp.dll
  • Moon.PDFTemplate.dll
  • Moon.PDFTemplateItextSharp.dll

Create your xml layout
please refer the PDFTemplate.xml for the tag and attribute.
Table tag, Font

Using PDFTemplateItextSharp
Moon.PDFTemplateItextSharp.PDFTemplateItextSharp pdfTmpl =
new Moon.PDFTemplateItextSharp.PDFTemplateItextSharp("a.xml");
Prepare data to substitute
Hashtable headerData = new Hashtable();
headerData.Add("{company_name}", "Company ABC");
headerData.Add("{date}", "10/31/2011");

<textbox width="15%" text="Date: {date}"><var name="{date}" /></textbox>
with this data
headerData.Add("{date}", "10/31/2011");
the output on the pdf is
Date: 10/31/2011
List<Hashtable> loopData = new List<Hashtable>();
for (int i = 0; i < 100; i++)
Hashtable data = new Hashtable();
data.Add("{no}", i);
data.Add("{another}", " another: " + i);
data.Add("{name}", "NAME " + i);

Hashtable footerData = new Hashtable();
Hashtable bodyData = new Hashtable();
bodyData.Add("{remark}", "This is the remark Line! This is the remark Line! This is the remark Line! This is the remark Line!");

process the data and draw it to pdf
without table tag
pdfTmpl.Draw(headerData, loopData, bodyData, footerData);
with table tag
pdfTmpl.Draw(headerData, null, bodyData, footerData, tableheadData, tableloopData, tablefootData);

You can repeatedly call Draw(), it will draw the data on the next page on the same pdf document.

Save your pdf to file
System.IO.FileStream file = new System.IO.FileStream("a.pdf", System.IO.FileMode.Create);
System.IO.MemoryStream mStream = pdfTmpl.Close();
byte[] bytes = mStream.ToArray();
file.Write(bytes, 0, bytes.Length);

System.IO.MemoryStream stream = pdfTmpl.Close();

Page.Response.ContentType = "application/pdf";
Page.Response.AppendHeader("Content-Disposition", "attachment; filename=SalesOrder.pdf");

Last edited Jul 21, 2013 at 6:26 PM by cmwong, version 16


jaimelopez Jun 16, 2013 at 11:48 AM 
Pending release 1.1 documentation.