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

我在使用页面设置为信封,横向格式创建.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)

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

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...