I have 2 tables in my form. I am generating PDF file with the help of itextsharp.dll
I want to break the page when 2nd table is started but it can't work right now
I inserted 2 tables in panel & write following code
*******************************************************************************************
Response.AddHeader("content-disposition", "attachment;filename=Report.pdf");
Response.ContentType = "application/pdf";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
panelPrint.RenderControl(htmlWrite);
System.IO.StringReader sr = new System.IO.StringReader(stringWrite.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 7f);
//Document pdfDoc = new Document(
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
Response.ContentType = "application/pdf";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
panelPrint.RenderControl(htmlWrite);
System.IO.StringReader sr = new System.IO.StringReader(stringWrite.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 7f);
//Document pdfDoc = new Document(
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
***********************************************************************************************
So please tell me how to break that page when 2nd table is started?

Jack Fandora2 reputationPosted Apr 2, 2015, 7:04 AM EDT
http://forums.asp.net/t/1428577.aspx?Add+a+new+page+in+iTextSharp
Alex SmithRank #4,089 · 366 reputationPosted Apr 27, 2015, 11:03 PM EDT
//create a PDF document and load file
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");
//insert blank page at the end of the PDF file
doc.Pages.Add();
//insert blank page as the second page
doc.Pages.Insert(1);
After creating the new page, you can then insert 2nd table to this page.
Jonathan Sterling19 reputationPosted Jun 19, 2015, 12:26 AM EDT
// Load HTML text. DocumentModel document; var options = LoadOptions.HtmlDefault; using (var htmlStream = new MemoryStream(options.Encoding.GetBytes(stringWrite.ToString()))) document = DocumentModel.Load(htmlStream, options); // Get second Table element. var secondTable = document.GetChildElements(true, ElementType.Table).Skip(1).First(); // Insert PageBrak element. secondTable.Content.Start.InsertRange( new Paragraph(document, new SpecialCharacter(document, SpecialCharacterType.PageBreak)).Content); // Download PDF file. document.Save(this.Response, "Report.pdf");anushree partani25 reputationPosted Jun 7, 2017, 4:39 AM EDT
Ravi SangtaniRank #1,947 · 751 reputationPosted Jun 7, 2017, 5:33 AM EDT
Satyaprakash SamantarayRank #101 · 21.1K reputationPosted Jul 3, 2017, 8:30 PM EDT
Satyaprakash SamantarayRank #101 · 21.1K reputationPosted Jul 3, 2017, 8:36 PM EDT
Satyaprakash SamantarayRank #101 · 21.1K reputationPosted Jul 3, 2017, 8:36 PM EDT