如何在pdf单词中删除空格 [英] How to remove space in words of pdf

查看:145
本文介绍了如何在pdf单词中删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人

我正在尝试使用itextsharp将html文本转换为pdf..pdf生成的很好,但是pdf单词之间存在很多差距
...附有样本pdf文件...
在hdpdf.Value中,我正在获取所有html文本..
代码:

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 :

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()

推荐答案

如您的代码所述,您正在尝试将html文本转换为pdf文本.从html获取文本时,您不会对其进行修整.这就是为什么文本之间的空格也会在pdf中写入的原因.尝试使用Trim()函数修剪html文本,这样就不会出现任何间距问题.


--Amit
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


这篇关于如何在pdf单词中删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆