问题描述
我有问题,与页面设置为信封,横向格式创建.pdf文件。
I have problem on creating .pdf file with the Page settings as Envelope ,landscape format.
下面是我的code到ASP页面转换成PDF在iTextSharp的
Here is my Code to convert the asp page into pdf in Itextsharp
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, 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了它,但我找不到信封size.How做我设置页面大小的信封,景观动态
i googled it but i couldn't find Envelope size.How do i set the page size as Envelope ,Landscape in dynamically
在此先感谢
推荐答案
您正在创建横向格式的文件A4这一行:
You are creating an A4 document in landscape format with this line:
Document pdfDoc = new Document(PageSize.A4.Rotate(), 10f, 10f, 100f, 0f);
如果您要创建信封格式的文档,你不应该创建一张A4纸,而不是你应该这样做:
If you want to create a document in envelope format, you shouldn't create an A4 page, instead you should do this:
Document pdfDoc = new Document(envelope, 10f, 10f, 100f, 0f);
在这一行,信封
是类型的对象长方形
。
In this line, envelope
is an object of type Rectangle
.
有没有这样的事情在信封尺寸。有不同的信封尺寸可供选择:
There is no such thing as the envelope size. There are different envelope sizes to choose from: http://www.paper-papers.com/envelope-size-chart.html
举例来说,如果你想用的,那么你需要创建一个3.5英寸的衡量6的矩形。在PDF中的测量系统不使用英寸,但用户的单位。默认情况下,1用户单位= 1点,1英寸= 72点。
For instance, if you want to create a page with the size of a 6-1/4 Commercial Envelope, then you need to create a rectangle that measures 6 by 3.5 inch. The measurement system in PDF doesn't use inches, but user units. By default, 1 user unit = 1 point, and 1 inch = 72 points.
因此,你会这样定义信封
变量:
Hence you'd define the envelope
variable like this:
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)
如果你想有一个不同的信封类型,你必须做的数学与信封格式的尺寸。
If you want a different envelope type, you have to do the Math with the dimensions of that envelope format.
这篇关于如何设置页面大小与横向方向来的信封尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!