Click here to Skip to main content
15,917,176 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionDatagrid Template Pin
.NET- India 6-Oct-07 2:11
.NET- India 6-Oct-07 2:11 
AnswerRe: Datagrid Template Pin
scicorp6-Oct-07 2:18
scicorp6-Oct-07 2:18 
GeneralRe: Datagrid Template Pin
.NET- India 6-Oct-07 2:48
.NET- India 6-Oct-07 2:48 
QuestionUnable to start debugging on the web server Pin
Milind Panchal6-Oct-07 1:25
Milind Panchal6-Oct-07 1:25 
AnswerRe: Unable to start debugging on the web server Pin
Abhijit Jana6-Oct-07 1:42
professionalAbhijit Jana6-Oct-07 1:42 
AnswerRe: Unable to start debugging on the web server Pin
John-ph6-Oct-07 1:45
John-ph6-Oct-07 1:45 
AnswerRe: Unable to start debugging on the web server Pin
John-ph6-Oct-07 1:51
John-ph6-Oct-07 1:51 
QuestionHow can we create PDF document which contains html(html tags like pre, bold etc) using itextsharp [modified] Pin
here2learn6-Oct-07 1:19
here2learn6-Oct-07 1:19 
Hi Friends...

i am working on a webapplication in which i have to create pdf file using itextsharp(must as customer want to use this only). here i will have a gridview which is not databound, not have any column at design time. on 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();
}




-- modified at 7:54 Saturday 6th October, 2007

People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily
Akhilesh Singh

QuestionAbout msgbox Pin
Nine Tails6-Oct-07 0:18
Nine Tails6-Oct-07 0:18 
AnswerRe: About msgbox Pin
Christian Graus6-Oct-07 0:31
protectorChristian Graus6-Oct-07 0:31 
AnswerRe: About msgbox Pin
Abhijit Jana6-Oct-07 0:35
professionalAbhijit Jana6-Oct-07 0:35 
GeneralRe: About msgbox Pin
Christian Graus6-Oct-07 0:38
protectorChristian Graus6-Oct-07 0:38 
AnswerRe: About msgbox Pin
John-ph6-Oct-07 0:42
John-ph6-Oct-07 0:42 
GeneralRe: About msgbox Pin
Abhijit Jana6-Oct-07 0:47
professionalAbhijit Jana6-Oct-07 0:47 
GeneralRe: About msgbox Pin
Abhijit Jana6-Oct-07 0:54
professionalAbhijit Jana6-Oct-07 0:54 
GeneralRe: About msgbox Pin
John-ph6-Oct-07 1:04
John-ph6-Oct-07 1:04 
GeneralRe: About msgbox Pin
Abhijit Jana6-Oct-07 1:12
professionalAbhijit Jana6-Oct-07 1:12 
GeneralRe: About msgbox Pin
John-ph6-Oct-07 1:23
John-ph6-Oct-07 1:23 
GeneralRe: About msgbox Pin
Abhijit Jana6-Oct-07 1:29
professionalAbhijit Jana6-Oct-07 1:29 
GeneralRe: About msgbox Pin
Christian Graus6-Oct-07 1:04
protectorChristian Graus6-Oct-07 1:04 
GeneralRe: About msgbox Pin
Abhijit Jana6-Oct-07 1:09
professionalAbhijit Jana6-Oct-07 1:09 
GeneralRe: About msgbox Pin
Christian Graus6-Oct-07 2:04
protectorChristian Graus6-Oct-07 2:04 
GeneralRe: About msgbox Pin
Abhijit Jana6-Oct-07 2:39
professionalAbhijit Jana6-Oct-07 2:39 
Questionpermissions for database Pin
Sonia Gupta5-Oct-07 23:45
Sonia Gupta5-Oct-07 23:45 
QuestionWhat does IISRESET do? Pin
rockyl5-Oct-07 23:32
rockyl5-Oct-07 23:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.