Click here to Skip to main content
15,885,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All

I am trying to convert html text to pdf using itextsharp..pdf is generating fine but there is a lot of gap in between words of pdf
...sample pdf file is attached...
In hdpdf.Value i am fetching all html text..
code :
VB
Dim document As Document = New iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate, 1, 1, 1, 1)
      Dim UrlDirectory As [String] = Request.Url.GetLeftPart(UriPartial.Path)
      UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/") + 1)
      Response.Write(UrlDirectory)
      PdfWriter.GetInstance(document, New FileStream(Server.MapPath(".") + "mayur.pdf", FileMode.Create))

      document.Open()
      '  Dim textFont As Font = FontFactory.GetFont("Helvetica", 1, 1, font.NORMAL, BaseColor.BLACK)
      Dim htmlText As [String] = hdpdf.Value
      Dim htmlarraylist As List(Of IElement) = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(New StringReader(htmlText), Nothing)
      ' document.SetPageSize=
      Dim font As Font = FontFactory.GetFont("Times-Roman", 9)
      For k As Integer = 0 To htmlarraylist.Count - 1
          Dim x As IElement = DirectCast(htmlarraylist(k), IElement)
          Response.Write(x.Type.ToString() + "#<br>")
      Next
      Dim mypara As New Paragraph()
      '    mypara.SetLeading(0.0F, 3.0F)


      mypara.InsertRange(0, htmlarraylist)
      document.Add(mypara)
      document.Close()
Posted
Updated 9-Aug-12 3:40am
v2
Comments
Sergey Alexandrovich Kryukov 9-Aug-12 21:07pm    
Gap between words is not space in words (which does not exist by definition of a word).
--SA
mayur mkt 10-Aug-12 2:10am    
need solution

1 solution

As your code says you are trying to convert the html text into the pdf text. While getting the text from html you are not trimming it. That's why the spaces between text is also getting written in the pdf. Try to trim your html text using Trim() function then you'll not get any problem of spacing like this.


--Amit
 
Share this answer
 
Comments
mayur mkt 9-Aug-12 9:57am    
Thanks for reply
But its not done
I am appending html text in stringbuilder as follows

strtbl.AppendLine("<div id='divrpt' style='font-size:10px;height:5px;width:100%;'>")
strtbl.AppendLine("<table id='tblrptshow' cellpadding='0' cellspacing='0' align='center' style='auto;width:99%;border-right:#E5E5E5 1px solid;border-top:#E5E5E5 1px solid;border-bottom:#E5E5E5 1px solid;border-left:#E5E5E5 1px solid' >")
'strtbl.AppendLine("<div id='divrpt' style='height:5px;width:100%;'>")
'strtbl.Append("<div id='divrpt' style='height:5px;width:100%;position:relative;top:20px'>")
'strtbl.AppendLine("<table id='tblrpt' cellpadding='0' cellspacing='0' align='center' style='auto;width:99%;border-right:#E5E5E5 1px solid;border-top:#E5E5E5 1px solid;border-bottom:#E5E5E5 1px solid;border-left:#E5E5E5 1px solid' >")
'strtbl.AppendLine("<table id='tblrpt' cellpadding='0' cellspacing='0' align='center' width='98%' style='border-top:#E5E5E5 1px solid' >")
strtbl.AppendLine("<tr><td colspan=7 ><br/></td></tr>")
strtbl.AppendLine("<tr><td colspan=7 ><br/></td></tr>")
strtbl.AppendLine("<tr><td colspan=7 ><br/></td></tr>")
...................

And finally i take all string in hiddenfield as

hdpdf.Value = strtbl.ToString().Trim//changed as you suggest

but no any effect
_Amy 9-Aug-12 10:03am    
Refer this article : Generate PDF Using C#[^].
mayur mkt 9-Aug-12 10:07am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900