从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