从itextsharp创建pdf时,如何保持列的宽度不变 [英] How do I keep the width of columns intact while creating pdf from itextsharp

查看:95
本文介绍了从itextsharp创建pdf时,如何保持列的宽度不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在aspx页面创建一个面板的pdf文件,它有多个表和控件,设计各异。但是pdf是为所有表创建的,具有相同大小的列,从而破坏了所有格式。以下是从网上获取的代码。



我无法再设计整个页面,请建议保持列大小不变。



谢谢提前



Hi All,

I am creating pdf file of a panel in aspx page which has multiple tables and controls with varied designing. But the pdf is created with equal size columns for all tables thus ruining all the formatting. Following is the code used as taken from net.

I cannot design the whole page again, pls suggest to keep the columns size intact.

Thanks in advance

Dim appPath As String = HttpContext.Current.Request.ApplicationPath
      Dim path As String = Server.MapPath(appPath & "/Attachments/Test.pdf")
      Dim sw As New StringWriter()
      Dim hw As New HtmlTextWriter(sw)
      Panel1.RenderControl(hw)

      Dim output = New FileStream(path, FileMode.Create)
      Dim sr As New StringReader(sw.ToString())
      Dim pdfDoc As New iTextSharp.text.Document(PageSize.A4, 10.0F, 10.0F, 50.0F, 0.0F)
      Dim htmlparser As New HTMLWorker(pdfDoc)
      iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, output)
      pdfDoc.Open()
      htmlparser.Parse(sr)
      pdfDoc.Close()

推荐答案





查看此....



Hi,

Check this....

Dim columnWidths_new As Single() = New Single() {5.0F, 30.0F, 15.0F}
           table_new.SetWidths(columnWidths_new)







希望这会对你有所帮助。



干杯




Hope this will help you.

Cheers


这篇关于从itextsharp创建pdf时,如何保持列的宽度不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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