We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

content (html) repeated in pdf

We have an issue with a static html page when converting it to a pdf-file.
This is a simplified version of the html that we experience the same problem with:

After 42 pages the first page reappears in the pdf - and again at page 82 (pdf attached)

Below I have pasted our code.
Any help in this regard would be greatly appreciated.

Dim filename as String = ""
Dim urltoparse as String = ""


If InStr(urltoparse,"?")>0 Then
End if

Dim margins As String = ""
margins = (request("margins"))
If Not isnumeric(margins) Or Len(margins)=0 Then margins="10"

Dim doc As PdfDocument
doc = New PdfDocument()


Dim Orientation As String = ""
Orientation = LCase((request("Orientation")))

If Orientation="landscape"  Then 
doc.PageSettings.Orientation = PdfPageOrientation.Landscape
doc.PageSettings.Orientation = PdfPageOrientation.Portrait
End if

doc.PageSettings.Rotate = CType(System.Enum.Parse(GetType(PdfPageRotateAngle), "RotateAngle0"), PdfPageRotateAngle)

Dim page As PdfPage = Nothing
Dim pageSize As SizeF = SizeF.Empty
Dim convertor As New PdfUnitConvertor()
Dim width As Single = -1
Dim height As Single = -1

page = doc.Pages.Add()

pageSize = page.GetClientSize()

'Calculates the height and width of the pdf image.
width = convertor.ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point)

dim html As HtmlConverter = New HtmlConverter()

html.EnableHyperlinks = True 
html.AutoDetectPageBreak = True
html.EnableJavaScript = True

Dim result As HtmlToPdfResult = html.Convert(urltoparse, ImageType.Metafile, CInt(Fix(width)), CInt(Fix(height)), AspectRatio.KeepWidth)

If Not result Is Nothing Then
Dim mf As PdfMetafile = New PdfMetafile(TryCast(result.RenderedImage, Metafile))
mf.Quality = 100

Dim format As PdfMetafileLayoutFormat = New PdfMetafileLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
doc.PageSettings.Height = result.RenderedImage.Size.Height
format.SplitTextLines = false
format.SplitImages = false

result.Render(page, format)
Response.Write("Warning ! Please check the HTML link")
End If

Dim rect As RectangleF = New RectangleF(0, 0, doc.Pages(0).GetClientSize().Width, 50)
Dim footer As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
Dim font As PdfStandardFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10.5F)
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.Black)

'Create page number field
Dim pageNumber As PdfPageNumberField = New PdfPageNumberField(font, brush)

'Create page count field
Dim count As PdfPageCountField = New PdfPageCountField(font, brush)

'Add the fields in composite fields
Dim compositeField As PdfCompositeField = New PdfCompositeField(font, brush, "Side {0} af {1}", pageNumber, count)
compositeField.Bounds = footer.Bounds

'Draw the composite field in footer
compositeField.Draw(footer.Graphics, New PointF(470, 40))

'Add the footer template at the bottom
doc.Template.Bottom = footer

doc.Save(filename, Response, HttpReadType.Save)


1 Reply

PH Praveenkumar H Syncfusion Team August 30, 2013 04:10 AM UTC

Hi Jimmy,

Thank you for your interest in Syncfusion products.

We are able to reproduce the mentioned issue.

Could you please report this issue through Direct Trac Developer Support System (https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents because you can take the advantage of the expertise of a dedicated support engineer and a guaranteed response time and we hope you will take advantage of this system as well. If you have already reported, please ignore this.


Live Chat Icon For mobile
Up arrow icon