I found this post on another forum and had the same question. It does not
appear that he received an answer.
http://forums.asp.net/p/1167105/1944057.aspx#1944057
I am working on a webapplication in which i have to create pdf file using
itextsharp(must as customer want to usethis only). here i will have a
gridview which is not databound, not have any column at design timeon page
load only i will create a datatable based on some data and bind it to
gridview.
after this i need to do formatting of some specific rows in the girdview.
this formatting will use pre tag with some attributes like font-family,
size, style. so while displaying the gridview after page load some rows of
gridview will have specific formatting tags in it's cell's text.
on click of a button i need to create a pdf file using itextsharp. i am able
to create pdf only problem is all formatting tags are appearing in file,
they are not being replaced with thier html meaning.
can anybody help me to sort it out? please it's very much required at this
time...
below is the function to which i am passing a datatable dt, which is nothing
but data contained in grid stored into table... also a string headerText,
which will come on top of page and will show some note text.
private void CreateSavePdf(DataTable dt, string headerText)
{
// where to store the file
string pdfFileName = "D:\\Report.pdf";
Document document = new Document(PageSize.A4.Rotate(), 50, 50, 50, 50);
PdfWriter writer = PdfWriter.GetInstance(document, new
FileStream(pdfFileName, FileMode.Create));
document.Open();
Phrase headerPhrase = new Phrase(headerText, FontFactory.GetFont("Verdana",
24));
HeaderFooter header = new HeaderFooter(headerPhrase, false);
header.Border = Rectangle.NO_BORDER;
header.Alignment = Element.ALIGN_LEFT;
document.Header = header;
document.Add(headerPhrase);
HeaderFooter footer = new HeaderFooter(new Phrase("Page "), true);
footer.Border = Rectangle.NO_BORDER;
footer.Alignment = Element.ALIGN_CENTER;
document.Footer = footer;
int numColumns = dt.Columns.Count;
PdfPTable datatable = new PdfPTable(numColumns);
datatable.DefaultCell.Padding = 3;
datatable.WidthPercentage = 100; // percentage
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
datatable.DefaultCell.BorderWidth = 1;
datatable.DefaultCell.GrayFill = 0.7f;
foreach (DataColumn column in dt.Columns)
{
string columnName = column.ColumnName;
Phrase phrase = new Phrase(columnName, FontFactory.GetFont("Arial", 8,
Font.BOLD));
datatable.AddCell(phrase);
}
datatable.HeaderRows = 1;
foreach (DataRow row in dt.Rows)
{
foreach (DataColumn column in dt.Columns)
{
string columnName = column.ColumnName;
datatable.DefaultCell.BackgroundColor = Color.WHITE;
Phrase phrase = new Phrase(row[columnName].ToString(),
FontFactory.GetFont("Arial", 8));
datatable.AddCell(phrase);
}
}
document.Add(datatable);
document.Close();
}
Chris
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar