Here is the layout of my page that I am exporting:
-------------------------------
' Text text text '
' '
' Gridview '
' '
' Text text text '
--------------------------------
Here is my table after rendering to HTML
<table cellspacing="0" id="mytest_gvMain" style="width:100%;border-collapse:collapse;">
<tbody>
<tr>
<th scope="col">Item</th>
<th scope="col">Description</th>
<th scope="col">Quantity</th>
<th scope="col">Unit</th>
<th scope="col">Rate</th>
</tr>
<tr>
</tr>
</tbody>
</table>
As you see the gridview is in the middle of the page. Because the gridview can of any size expanding to different pages, I would like to set SplitLate = false, so the row stays together. Now some of the text in the last row is on page 1 and the some of it on the first row of page 2. Please have a look at this image .
Some data on last row of page 5 and some on first row of page 6. I have read some documents suggesting document.add(table) but that will add the table to the end of my document. Is there a way I set SplitLate on the gridview itself?
Based on Chris suggestion, I have updated my code to use xmlworker based on this link Cannot get CSS to work in iTextSharp (5.4.3) when making pdf.
Using input As New MemoryStream(bytes, False)
Dim ms As New MemoryStream()
Dim document As New iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 36, 36, 36, 36)
Dim writer As PdfWriter = PdfWriter.GetInstance(document, ms)
writer.CloseStream = False
document.Open()
Dim htmlContext As HtmlPipelineContext = New HtmlPipelineContext(Nothing)
htmlContext.SetAcceptUnknown(True)
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory())
Dim cssResolver As ICSSResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(False)
cssResolver.AddCssFile(HttpContext.Current.Server.MapPath("/assets/css/pdf.css"), True)
Dim pipeline As New CssResolverPipeline(cssResolver, New HtmlPipeline(htmlContext, New PdfWriterPipeline(document, writer)))
Dim pdfworker As New XMLWorker(pipeline, True)
Dim p As New XMLParser(True, pdfworker, New System.Text.UTF8Encoding)
Try
'p.AddListener(pdfworker)
'p.Parse(input, Encoding.UTF8)
XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, input, New FileStream(HttpContext.Current.Server.MapPath("~/assets/css/pdf.css"), FileMode.Open, FileAccess.Read))
Catch
Finally
pdfworker.Close()
End Try
document.Close()
ms.Position = 0
Response.Buffer = True
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=preview.pdf")
Response.BinaryWrite(ms.GetBuffer())
Response.Flush()
End Using
Any help appreciated.