加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何使用横向方向将页面大小设置为信封大小?

发布时间:2020-12-16 00:09:27 所属栏目:asp.Net 来源:网络整理
导读:我在使用页面设置为信封,横向格式创建.pdf文件时遇到问题. 这是我在Itextsharp中将asp页面转换为pdf的代码 Response.ContentType = "application/pdf";Response.AddHeader("content-disposition","attachment;filename=Receipt.pdf");Response.Cache.SetCach
我在使用页面设置为信封,横向格式创建.pdf文件时遇到问题.

这是我在Itextsharp中将asp页面转换为pdf的代码

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition","attachment;filename=Receipt.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
bind_Data();
this.Page.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4.Rotate(),10f,100f,0f);
//here i need to set Pagesize as Envelope.
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc,Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

我google了它,但我找不到信封大小.如何将页面大小设置为信封,动态景观

提前致谢

解决方法

您正在使用此行创建横向格式的A4文档:
Document pdfDoc = new Document(PageSize.A4.Rotate(),0f);

如果要以信封格式创建文档,则不应创建A4页面,而应该执行以下操作:

Document pdfDoc = new Document(envelope,0f);

在此行中,envelope是Rectangle类型的对象.

没有信封大小这样的东西.有不同的信封尺寸可供选择:http://www.paper-papers.com/envelope-size-chart.html

例如,如果要创建大小为6-1/4 Commercial Envelope的页面,则需要创建一个尺寸为6 x 3.5英寸的矩形. PDF中的测量系统不使用英寸,而是使用用户单位.默认情况下,1个用户单位= 1个点,1英寸= 72个点.

因此,您可以像这样定义包络变量:

Rectangle envelope = new Rectangle(432,252);

因为:

6 inch x 72 points = 432 points (the width)
3.5 inch x 252 points = 252 points (the height)

如果您需要不同的信封类型,则必须使用该信封格式的尺寸进行数学运算.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读