Multiple gridviews to single pdf using iTextsharp - c#

I am trying to export multiple gridviews into single pdf using iTextSharp. I am looping through the gridviews and then looping through the rows of the gridview. The looping is going ok. But after pdf download, only the last gridview can be seen. It seems the gridviews are overwriting each other and only last one remains. Here is my code. What am I doing wrong?
protected void btnExportToPDF_Click(object sender, EventArgs e)
{
GridView[] gvExcel = new GridView[] { gridvw1,gridvw2,gridvw3 };
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
for (int i = 0; i < gvExcel.Length; i++)
{
if (gvExcel[i].Visible)
{
PdfPTable pdfTbl = new PdfPTable(gvExcel[i].HeaderRow.Cells.Count);
foreach (TableCell headerTblCell in gvExcel[i].HeaderRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(gvExcel[i].HeaderStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(headerTblCell.Text));
pdfCell.BackgroundColor = new BaseColor(gvExcel[i].HeaderStyle.ForeColor);
pdfTbl.AddCell(pdfCell);
}
foreach (GridViewRow gvRow in gvExcel[i].Rows)
{
foreach (TableCell tblCell in gvRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(gvExcel[i].RowStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(tblCell.Text));
pdfCell.BackgroundColor = new BaseColor(gvExcel[i].RowStyle.ForeColor);
pdfTbl.AddCell(pdfCell);
}
}
//Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
pdfDoc.Add(pdfTbl);
}
}
pdfDoc.Close();
//Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=report_" + startDate + "-" + endDate + ".pdf");
Response.Write(pdfDoc);
Response.Flush();
Response.End();
}

One of your errors is not an iText error; it's is a simple logical error that can be solved with common sense. The other error is weird. You aren't using the Response correctly.
protected void btnExportToPDF_Click(object sender, EventArgs e)
{
GridView[] gvExcel = new GridView[] { gridvw1,gridvw2,gridvw3 };
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
MemoryStream ms = new MemoryStream();
PdfWriter.GetInstance(pdfDoc, ms);
pdfDoc.Open();
for (int i = 0; i < gvExcel.Length; i++)
{
if (gvExcel[i].Visible)
{
PdfPTable pdfTbl = new PdfPTable(gvExcel[i].HeaderRow.Cells.Count);
pdfTbl.SpacingAfter = 20f;
foreach (TableCell headerTblCell in gvExcel[i].HeaderRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(gvExcel[i].HeaderStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(headerTblCell.Text));
pdfCell.BackgroundColor = new BaseColor(gvExcel[i].HeaderStyle.ForeColor);
pdfTbl.AddCell(pdfCell);
}
foreach (GridViewRow gvRow in gvExcel[i].Rows)
{
foreach (TableCell tblCell in gvRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(gvExcel[i].RowStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(tblCell.Text));
pdfCell.BackgroundColor = new BaseColor(gvExcel[i].RowStyle.ForeColor);
pdfTbl.AddCell(pdfCell);
}
}
pdfDoc.Add(pdfTbl);
}
}
pdfDoc.Close();
byte[] content = ms.ToArray();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=report_" + startDate + "-" + endDate + ".pdf");
Response.BinaryWrite(content);
Response.Flush();
Response.End();
}
There might be some other issues, but I hope you understand the logical error:
You created a new PDF file with PdfWriter every time you entered the loop. You should only create one PdfWriter instance if you only want to create one PDF.
It's better to create the PDF in a MemoryStream, and then write the content of that stream to the Response object as a binary stream. I really didn't understand what you were doing there (and why you tried to do it that way).
I also introduced a SpacingAfter of 20 user units, otherwise it will look as if all tables all glued together into one big table.
There may still be some errors in the way you send the file to the Response, but this should already get you on your way. (Why aren't you sending the file size to the browser? You know that size, don't you? It's the number of bytes in the content object.)

Related

How to export multiple gridviews into a single pdf file in dot net

I have 11 grid view in my page I want to export it into single pdf file, I searched this query and implemented the code which I got but it didn't work and generate pdf with black background only headers is showing not the content. Please provide me the code to export all 10 grid views into single pd
protected void btnExportToPDF_Click(object sender, EventArgs e)
{
GridView[] gvpdf = new GridView[] { GV1,GV2,GV3,GV4,GV5,GV6,GV7,GV8,GV9,GV10,GV11};
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
MemoryStream ms = new MemoryStream();
PdfWriter.GetInstance(pdfDoc, ms);
pdfDoc.Open();
for (int i = 0; i < gvpdf.Length; i++)
{
if (gvpdf[i].Visible)
{
PdfPTable pdfTbl = new PdfPTable(gvpdf[i].HeaderRow.Cells.Count);
pdfTbl.SpacingAfter = 20f;
foreach (TableCell headerTblCell in gvpdf[i].HeaderRow.Cells)
{
System.Drawing.Font font = new System.Drawing.Font("Arial", 24, FontStyle.Bold);
font.Color = new BaseColor(gvpdf[i].HeaderStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(headerTblCell.Text));
pdfCell.BackgroundColor = new BaseColor(gvpdf[i].HeaderStyle.ForeColor);
pdfTbl.AddCell(pdfCell);
}
foreach (GridViewRow gvRow in gvpdf[i].Rows)
{
foreach (TableCell tblCell in gvRow.Cells)
{
System.Drawing.Font font = new System.Drawing.Font("Arial", 24, FontStyle.Bold);
font.Color = new BaseColor(gvpdf[i].RowStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(tblCell.Text));
pdfCell.BackgroundColor = new BaseColor(gvpdf[i].RowStyle.ForeColor);
pdfTbl.AddCell(pdfCell);
}
}
pdfDoc.Add(pdfTbl);
}
}
pdfDoc.Close();
byte[] content = ms.ToArray();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=report_" + ".pdf");
Response.BinaryWrite(content);
Response.Flush();
Response.End();
}
You may want to try another approach. Just read all your data from mentioned grids, store it in POCO classes and then use some library to convert this information into a PDF file with desired formatting.
Personally, I recommend a free and open-source library called QuestPDF (notice, I am its creator). It offers an easy to use fluent API, detailed documentation and a getting started tutorial showing how to generate an invoice document.

header and footer using itextsharp using c#

I am using itextsharp for pdf generation using .net web applications. I have installed the following version of itextsharp using nuget package Install-Package iTextSharp -Version 5.5.10. I have seen the samples and developed
code sample to generate the pdf and it is working. However i am not able to understand or get the header footer been added to the pdf. Here is the sample code i am using
public class Header : PdfPageEventHelper
{
protected Phrase header;
public void setHeader(Phrase header)
{
this.header = header;
}
public void onEndPage(PdfWriter writer, Document document)
{
PdfContentByte canvas = writer.DirectContent;
ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, header, 559, 806, 0);
}
}
Document pdfReport = null;
MemoryStream msReport = new MemoryStream();
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfReport, msReport);
if (!string.IsNullOrEmpty(HeaderText))
{
Header objHeaderFooter = new Header();
//Here i need to assign the string HeaderText to Header. I dont know how to do it.
}
Please help to know how to assign HeaderText using itextSharp. Most of the developers examples are on java
but i am using .net c#.
You want to assign HeaderText to objHeaderFooter in
if (!string.IsNullOrEmpty(HeaderText))
{
Header objHeaderFooter = new Header();
//Here i need to assign the string HeaderText to Header. I dont know how to do it.
}
Assuming HeaderText to be a string you can do so using the Header method setHeader:
objHeaderFooter.setHeader(new Phrase(HeaderText));
Furthermore, you have to assign objHeaderFooter to your PdfWriter instance:
pdfWriter.PageEvent = objHeaderFooter;
Thus:
if (!string.IsNullOrEmpty(HeaderText))
{
Header objHeaderFooter = new Header();
objHeaderFooter.setHeader(new Phrase(HeaderText));
pdfWriter.PageEvent = objHeaderFooter;
}
Furthermore, whenever you override a method in c#, mark it accordingly as override. In particular in your page event listener, use
public override void onEndPage(PdfWriter writer, Document document)
This is easy to forget, especially when porting java examples because in java the corresponding marker #Override is optional.
Below is the sample code provided by the op.
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=abc.pdf");
Response.Charset = "";
Response.BinaryWrite(getbinary());
Response.End();
public byte[] getbinary()
{
Document pdfReport = null;
pdfReport = new Document(PageSize.A4, 25, 25, 40, 25);
MemoryStream msReport = new MemoryStream();
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfReport, msReport);
pdfReport.Open();
if (!string.IsNullOrEmpty("Header Text"))
{
Header objHeaderFooter = new Header();
objHeaderFooter.SetHeader(new Phrase("Header Text"));
pdfWriter.PageEvent = objHeaderFooter;
}
PdfPTable ptData1 = new PdfPTable(1);
ptData1.SpacingBefore = 8;
ptData1.DefaultCell.Padding = 1;
ptData1.WidthPercentage = 100;
ptData1.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
ptData1.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
PdfPCell cell1 = new PdfPCell();
cell1.BorderWidth = 0.001F;
cell1.BackgroundColor = new BaseColor(250, 250, 250);
cell1.BorderColor = new BaseColor(100, 100, 100);
cell1.Phrase = new Phrase("Sample text");
ptData1.AddCell(cell1);
PdfPCell cell = new PdfPCell();
cell.BorderWidth = 0.001F;
cell.BackgroundColor = new BaseColor(200, 200, 200);
cell.BorderColor = new BaseColor(100, 100, 100);
cell.Phrase = new Phrase("test value");
ptData1.AddCell(cell);
pdfReport.Add(ptData1);
pdfReport.Close();
return msReport.ToArray();
}
public class Header : PdfPageEventHelper
{
protected Phrase header;
public void SetHeader(Phrase header)
{
this.header = header;
}
public void onEndPage(PdfWriter writer, Document document)
{
PdfContentByte canvas = writer.DirectContent;
ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, header, 559, 806, 0);
}
}
May be this could be used as a workaround. Added header as another cell value
Below is the code
if (!string.IsNullOrEmpty(HeaderText))
{
PdfPTable Header = new PdfPTable(1);
Header.SpacingBefore = 8;
Header.DefaultCell.Padding = 1;
Header.WidthPercentage = 100;
Header.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
Header.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
PdfPCell cell1 = new PdfPCell();
cell1.BorderWidth = 0.001F;
cell1.BackgroundColor = new BaseColor(250, 250, 250);
cell1.BorderColor = new BaseColor(100, 100, 100);
cell1.Phrase = new Phrase(HeaderText, fontBold);
Header.AddCell(cell1);
pdfReport.Add(ptDataHeader);
}

Cannot access a non-static member of outer type 'System.Web.UI.Page' via nested type 'PrintToPdf._events'

I have been trying to add an image to all pages using iTextSharp.
According to this web page I need to look into the PdfPageEventHelper of iTextSharp.
It provides a method called OnEndPage that allows such things.
Basically, treat the image as being in the header or footer of the document, and use absolute positioning to put it where you want, instead of just in the flow of the page content.
The below code response with error :
Cannot access a non-static member of outer type 'System.Web.UI.Page'
via nested type 'PrintToPdf._events'
On :
PdfPCell cell2 = new PdfPCell(Image.GetInstance(Server.MapPath(imagepath)));
Is there any way to insert the image in the same way in all pages?
Can you help me ?
Thank you in advance.
class _events : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfPTable table = new PdfPTable(1);
table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
PdfPTable table2 = new PdfPTable(2);
string imagepath = #"Img\Logo.jpg";
PdfPCell cell2 = new PdfPCell(Image.GetInstance(Server.MapPath(imagepath)));
cell2.Colspan = 2;
table2.AddCell(cell2);
PdfPCell cell = new PdfPCell(table2);
table.AddCell(cell);
table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 36, writer.DirectContent);
}
}
private void PdfFiles()
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=test.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnPrint.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
string imagepath = #"Img\Logo.jpg";
Document pdfDoc = new Document(PageSize.A4, 20f, 20f, 10f, 20f);
try
{
_events e = new _events();
PdfWriter pw = PdfWriter.GetInstance(pdfDoc, new FileStream("test.pdf", FileMode.Create));
pw.PageEvent = e;
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
for (int i = 0; i < 5; i++)
{
Image image = Image.GetInstance(Server.MapPath(imagepath));
image.Alignment = Image.ALIGN_LEFT;
pdfDoc.Add(image);
htmlparser.Parse(sr);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
pdfDoc.Close();
Response.End();
}
}
Edit #1
protected class MyEvent : PdfPageEventHelper
{
Image image;
public override void OnOpenDocument(PdfWriter writer, Document document)
{
image = Image.GetInstance(#"C:\\intepub\\wwwroot\\img\\Logo.jpg");
image.SetAbsolutePosition(12, 300);
}
public override void OnEndPage(PdfWriter writer, Document document)
{
writer.DirectContent.AddImage(image);
}
}
// step 1
Document pdfDoc = new Document(PageSize.A4, 20f, 20f, 10f, 20f);
// step 2
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
MyEvent e = new MyEvent();
writer.PageEvent = e;
// step 3
pdfDoc.Open();
// step 4
pdfDoc.Add(new Paragraph("Hello World!"));
// step 5
pdfDoc.Close();

itextsharp pdf not showing

I am using the following code to generate a PDF using iTextSharp from a GridView however the generated PDF is not visible to me. How can I view it in my html page?
GridView1.Visible = false;
SqlConnection sql = Connection.con();
sql.Open();
SqlCommand cmd = new SqlCommand("spGetSalesbyCustomer", sql);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#CustomerId", Convert.ToInt32(TextBox1.Text));
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dd = new DataTable();
adp.Fill(dd);
GridView2.DataSource = dd;
GridView2.DataBind();
int cellCount = GridView2.Columns.Count;
sql.Close();
if (cellCount > 0)
{
GridView2.AllowPaging = false;
GridView2.DataBind();
BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + #"\fonts\ARIALUNI.TTF", BaseFont.IDENTITY_H, true);
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(cellCount);
int[] widths = new int[cellCount];
for (int x = 0; x < cellCount; x++)
{
widths[x] = (int)GridView2.Columns[x].ItemStyle.Width.Value;
string cellText = Server.HtmlDecode(GridView2.HeaderRow.Cells[x].Text);
//Set Font and Font Color
iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
//font.Color = new Color(GridView2.HeaderStyle.ForeColor);
iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
//Set Header Row BackGround Color
//cell.BackgroundColor = new Color(GridView2.HeaderStyle.BackColor);
table.AddCell(cell);
}
table.SetWidths(widths);
for (int i = 0; i < GridView2.Rows.Count; i++)
{
if (GridView2.Rows[i].RowType == DataControlRowType.DataRow)
{
for (int j = 0; j < GridView2.Columns.Count; j++)
{
string cellText = Server.HtmlDecode(GridView2.Rows[i].Cells[j].Text);
//Set Font and Font Color
iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
//font.Color = new Color(GridView2.RowStyle.ForeColor);
iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
//Set Color of row
if (i % 2 == 0)
{
//Set Row BackGround Color
//cell.BackgroundColor = new Color(GridView2.RowStyle.BackColor);
}
table.AddCell(cell);
}
}
}
//Create the PDF Document
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
int pages = pdfDoc.;
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
Your question is a little unclear but if your code is correct (and I know it isn't 100% based on the seventh last line) then you're not actually adding your PdfPTable to the Document:
//Create the PDF Document
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
//Bind a writer to our document abstraction and our output stream
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
//Open the document for writing
pdfDoc.Open();
//This next line is a syntax error
//int pages = pdfDoc.;
//Add the table to the PDF
pdfDoc.Add(table);
//Close the document
pdfDoc.Close();
//ASP.Net/HTTP stuff
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
//Do not use this next line, it doesn't do what you think it does
//Response.Write(pdfDoc);
Response.End();

Creating multiple page pdf using iTextSharp

I am trying to create pdf with multiple pages using iTextSharp
Document document = new Document(PageSize.A4, 2, 2, 10, 10);
private PdfContentByte _pcb;
try
{
PdfWriter writer = PdfWriter.GetInstance(document, output);
document.Open();
document.NewPage();
_pcb = writer.DirectContent;
_pcb.BeginText();
_pcb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, x, y, 0);
_pcb.EndText();
writer.Flush();
}
catch(e)
{
}
finally
{
document.Close();
}
This is working fine for me. When I am trying to add a new page on the same document, it is replacing the existing written text with new page and no new page is getting added. Below is the code which is not working.
_pcb.EndText();
writer.Flush();
document.NewPage();
_pcb = writer.DirectContent;
_pcb.BeginText();
_pcb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, x, y, 0);
_pcb.EndText();
writer.Flush();
Below is my attempt to clean-up and unify your code. Generally avoid try-catch until you actually have to, you'll often miss some very important errors. (For instance, you're not actually setting the font and size which is required but maybe you just omitted that code.) Also, unless you are writing a very large PDF there's really no reason to flush the buffers, leave that to the OS to do for you when necessary.
When I run the code below I get two pages with text on both pages, does it work for you? (Targeting iTextSharp 5.2.0.0)
var output = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Output.pdf");
var bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
using (FileStream fs = new FileStream(output, FileMode.Create, FileAccess.Write, FileShare.None)) {
using (Document doc = new Document(PageSize.A4, 2, 2, 10, 10)) {
PdfContentByte _pcb;
using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) {
//Open document for writing
doc.Open();
//Insert page
doc.NewPage();
//Alias to DirectContent
_pcb = writer.DirectContent;
//Set the font and size
_pcb.SetFontAndSize(bf, 12);
//Show some text
_pcb.BeginText();
_pcb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Page 1", 40, 600, 0);
_pcb.EndText();
//Insert a new page
doc.NewPage();
//Re-set font and size
_pcb.SetFontAndSize(bf, 12);
//Show more text on page 2
_pcb.BeginText();
_pcb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Page 2", 100, 400, 0);
_pcb.EndText();
doc.Close();
}
}
}
Why do you use the DirectContent? If you just want to create a PDF from scratch, just add content to the Document.
try
{
iTextSharp.text.Document doc = new iTextSharp.text.Document();
PdfWriter.GetInstance(doc, new FileStream("HelloWorld.pdf", FileMode.Create));
doc.Open();
doc.Add(new Paragraph("Hello World!"));
doc.NewPage();
doc.Add(new Paragraph("Hello World on a new page!"));
}
catch (Exception ex)
{
}
finally
{
doc.Close();
}
Below Code is working
string str = "Page1Page1Page1Page1Page1Page1Page1Page1Page1Page1";
string str2 = "Page2Page2Page2Page2Page2Page2Page2Page2Page2Page2";
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
using (var htmlWorker = new HTMLWokExtend(pdfDoc))
{
using (var sr = new StringReader(str))
{
htmlWorker.Parse(sr);
}
}
pdfDoc.NewPage();
using (var htmlWorker = new HTMLWokExtend(pdfDoc))
{
using (var sr = new StringReader(str2))
{
htmlWorker.Parse(sr);
}
}
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;" +
"filename=Proforma_Invoice.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
You can populate string from HTML body using below function
private string populatebody()
{
string body="";
using (StreamReader reader = new StreamReader(Server.MapPath("~/Dir/Page.html")))
{
body = reader.ReadToEnd();
}
body = body.Replace("{Content in htmlpage}", "Your Content");
return body
}
And then return this body to string in upper code.
You can manipulate with this code as per your requirement.
Below is HTMLWokExtend Class:
public class HTMLWokExtend : HTMLWorker
{
LineSeparator line = new LineSeparator(1f, 90f, BaseColor.GRAY, Element.ALIGN_CENTER, -12);
public HTMLWokExtend(IDocListener document) : base(document)
{
}
public override void StartElement(string tag, IDictionary<string, string> str)
{
if (tag.Equals("hrline"))
document.Add(new Chunk(line));
else
base.StartElement(tag, str);
}
}

Categories

Resources