在asp.net中以pdf格式导出时表格格式错误 [英] error in table format when export in pdf in asp .net

查看:71
本文介绍了在asp.net中以pdf格式导出时表格格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,



i我以pdf格式导出网页..我的代码工作正常..但我的问题是即时通讯创建一个包含列的表宽度和高度..当我运行此页面时,表格显示正确,分配宽度和高度..



当我打印为pdf作为按钮点击..全部cloumn宽度不能正常工作..所有列都有相同的宽度..



我的代码中没有错误..打印成pdf后我的表格格式出现问题



哪里有问题。我无法找到..



我的一些代码是:

 <   table    对齐  =  center    bgcolor   = #669999 < span class =code-attribute>   cellpadding   =  0  

cellspacing = 0 样式 = border:薄固#333300;
宽度:900px;身高:174px; text-align:center;
border = 2 >
< tr >
< td class = style3 >
< strong style = font-size:small > SI.No < / strong > < / td >
< td class = style4 >
< ; strong style < span class =code-keyword> = font-size:small > HH否< / strong > < / td &g t;
< td class = style4 >
< strong style = font-size:small > 儿童姓名< / strong > < / td >
< td class = style3 >
< strong 样式 = font-size:小 > 男(M)< br / > /女性(F)< / strong > ; < / td >
< td class = style4 >
< strong style = < span class =code-keyword> font-size:small > 出生日期< / strong > < / td >
< td class = style3 >
< strong style = font-size:small > 残疾(如果有)< / strong > < / td >
< td class = style4 >
< strong 样式 = font-size:small > 父亲姓名< / strong > < / td >
< td class = style4 >
< strong style = font-size:small > 名称母亲< / strong > < / td >
< td class = style3 >
< strong 样式 = font-size:small > Caste < / strong > < / td >
< / tr >
< ; / table >



我的按钮点击代码用于以pdf格式导出:

 Response.ContentType =  应用/ PDF; 
Response.AddHeader( content-disposition attachment; filename = UserDetails.pdf);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this .Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
文件pdfDoc = 文件(PageSize.A4,5f,5f,0f,0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc,Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

解决方案

hii all,

i am export a web page in pdf format.. my code is working properly .. but my problem is that i m creating a table with column width and height.. when i run this page then table is showed properly with assigned width and height..

when i print as pdf as button click .. the all cloumn width is not working properly.. all the columns has same width..

there is no error in my code.. problem in my table format after print as pdf

where is problem. i m not able to find out..

my some code is:

<table align="center" bgcolor="#669999" cellpadding="0"

cellspacing="0" style="border: thin solid #333300;
width: 900px; height: 174px; text-align: center;" border="2">
    <tr>
       <td class="style3">
        <strong style="font-size: small">SI.No</strong></td>
    <td class="style4">
        <strong style="font-size: small">HH No</strong></td>
     <td class="style4">
        <strong style="font-size: small">Name of Children</strong></td>
    <td class="style3">
        <strong style="font-size: small">Male(M)<br />/Female(F)</strong></td>
  <td class="style4">
        <strong style="font-size: small">Date of Birth</strong></td>
     <td class="style3">
        <strong style="font-size: small">Disability(if any)</strong></td>
      <td class="style4">
        <strong style="font-size: small">Name of Father</strong></td>
      <td class="style4">
        <strong style="font-size: small">Name of Mother</strong></td>
    <td class="style3">
        <strong style="font-size: small">Caste</strong></td>
</tr>
</table>


my button click code is for export in pdf is:

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 5f, 5f, 0f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

解决方案

这篇关于在asp.net中以pdf格式导出时表格格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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