Hi,
we are using the Syncfusion PDF dll (version 4.402.0.51) in our ASP.NET application to generate a PDF document.
we are looping through a datatable to generate the pdf by using graphics.drawmultitext method.
However we are facing issue, whenever the text is breaking to a new page, we are missing initial part of the text in the newpage.
Is it possible to find when the text is going to the new page. Else please provide a way to fix the issue.
Please find the code and sample file attached.,please reply ASAP.
Public Sub Generatepdfdoc(ByVal datatable As DataTable)
Dim LetterHeight, ReferenceHeight, DescriptionHeight As Single
Dim AcronymWidth As Single
Dim x As Single = 5
Dim y As Single = 15
Dim HorizantalWidth As Single = 5
Dim filePath As String
Dim PdfDoc As Syncfusion.Pdf.PDFDocument = New Syncfusion.Pdf.PDFDocument()
PdfDoc.AutoCreatePages = True
AddFooter(PdfDoc)
Dim font As IPDFFont = PdfDoc.Fonts.Add(New Font("Arial", 8))
Dim GraphicState As IPDFGraphicState = PdfDoc.CreateGraphicState()
GraphicState.BreakBehavior = AutoBreakBehavior.MultiLineTextBreak
Dim page As IPDFPage = PdfDoc.CreatePage()
Dim graphic As IPDFGraphics = PdfDoc.Graphics()
Dim pageWidth As Single = page.DrawingWidth
Dim heightinline As Integer = 0
For i As Integer = 0 To datatable.Rows.Count - 1
LetterHeight = ReferenceHeight = DescriptionHeight = 0
LetterHeight = PdfDoc.Graphics.MeasureString(datatable.Rows(i)("LETTER_REFERENCE").ToString.Trim(), font).Height
ReferenceHeight = PdfDoc.Graphics.MeasureString(datatable.Rows(i)("REFERENCE").ToString.Trim(), font).Height
DescriptionHeight = PdfDoc.Graphics.MeasureString(datatable.Rows(i)("DESCRIPTION").ToString.Trim(), font, pageWidth, GraphicState).Height
AcronymWidth = PdfDoc.Graphics.MeasureString(datatable.Rows(i)("ACRONYM").ToString.Trim(), font).Width
graphic.DrawMultiText(New RectangleF(x, y, pageWidth, LetterHeight), datatable.Rows(i)("LETTER_REFERENCE").ToString.Trim(), font)
y = y + LetterHeight + HorizantalWidth
If Not String.IsNullOrEmpty(datatable.Rows(i)("ACRONYM").ToString) Then
graphic.DrawMultiText(New RectangleF(x, y, pageWidth, ReferenceHeight), datatable.Rows(i)("ACRONYM").ToString.Trim(), font)
x = x + AcronymWidth + HorizantalWidth
End If
heightinline = PdfDoc.Graphics.ClientRectangle.Bottom
graphic.DrawMultiText(New RectangleF(x, y, pageWidth, ReferenceHeight), datatable.Rows(i)("REFERENCE").ToString.Trim(), font)
x = 5
y = y + ReferenceHeight + HorizantalWidth
graphic.DrawMultiText(New RectangleF(x, y, pageWidth, DescriptionHeight), datatable.Rows(i)("DESCRIPTION").ToString.Trim(), font, GraphicState)
y = y + DescriptionHeight + HorizantalWidth + HorizantalWidth
Next
filePath = Server.MapPath("temp/" & "Glossary" & DateTime.Now.ToString("ddMMyyyyhhmmss") & ".pdf")
PdfDoc.Save(filePath)
PdfDoc.Close()
Context.Response.ContentType = "application/pdf"
Context.Response.Charset = ""
Context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + "Glossary" & DateTime.Now.ToString("ddMMyyyyhhmmss") + ".pdf")
Context.Response.TransmitFile(filePath)
Context.Response.End()
End Sub
Public Sub AddFooter(ByVal pdfdoc As PDFDocument)
Dim font As IPDFFont
Dim footer As PDFTemplateArea = pdfdoc.Templates.Add(New SizeF(pdfdoc.LastPage.DrawingWidth, 40))
font = pdfdoc.Fonts.Add(New Font("Arial", 10, System.Drawing.FontStyle.Regular))
Dim FooterText As String = System.DateTime.Now.ToString("MMMM-yyyy")
Dim pagenumber As String = "Page #p; of #P;"
Dim bounds As RectangleF = New RectangleF(0, 30, footer.Size.Width, footer.Size.Height)
Dim FooterTextGraphicState As IPDFGraphicState = pdfdoc.CreateGraphicState()
FooterTextGraphicState.TextAlignment = TextAlignment.Right
FooterTextGraphicState.BreakBehavior = AutoBreakBehavior.MultiLineTextBreak
footer.Graphics.DrawMultiText(bounds, FooterText, font, FooterTextGraphicState, bounds)
FooterTextGraphicState = pdfdoc.CreateGraphicState()
Dim PageNumberGraphicState As IPDFGraphicState = pdfdoc.CreateGraphicState()
PageNumberGraphicState.TextAlignment = TextAlignment.Center
PageNumberGraphicState.BreakBehavior = AutoBreakBehavior.MultiLineTextBreak
footer.Graphics.DrawMultiText(bounds, pagenumber, font, PageNumberGraphicState, bounds)
PageNumberGraphicState = pdfdoc.CreateGraphicState()
pdfdoc.Templates.Footer = footer
End Sub