我想创建一个显示在其中的Icard的PDF文件。
代码如下:
iTextSharp.text.Font custFont = new iTextSharp.text.Font() { Size=6f};
int borderSize = 1;
Document IcardDoc = new Document(PageSize.HALFLETTER);
PdfWriter.GetInstance(IcardDoc, Response.OutputStream);
IcardDoc.Open();
PdfPTable icardTable = new PdfPTable(2);
iTextSharp.text.Image logoImage = iTextSharp.text.Image.GetInstance(Server.MapPath("~/images/logo.jpg"));
logoImage.WidthPercentage = 15f;
PdfPCell cell = new PdfPCell(logoImage, false);
cell.PaddingLeft = 10f;
cell.PaddingTop = 10f;
cell.PaddingBottom = 10f;
cell.PaddingRight = 10f;
cell.Colspan = 2;
cell.Border = 0;
cell.HorizontalAlignment = 1;
icardTable.AddCell(cell);
icardTable.AddCell(new PdfPCell(new Phrase("Name:", custFont)) { Border = borderSize });
icardTable.AddCell(new PdfPCell(new Phrase(student.firstname + " " + student.lastname, custFont)) { Border = borderSize });打印文档的高度为8.5厘米,宽度为5.4厘米。
所以需要以这种方式来适应它,有什么解决方案吗,因为上面的代码不适合页面上的表格和合适的大小?
任何其他格式也可以,如word等。
发布于 2012-06-13 18:30:56
想出了解决方案:
Document IcardDoc = new Document(new Retangele(200f, 315f),35f,35f,0f,0f);并相应地调整表格的宽度:
PdfPTable icardTable = new PdfPTable(2);
icardTable.WidthPercentage = 140f;要使表格精确地显示在页面上,如果减小rectangle width,则增加表格WidthPercentage,反之亦然。您还需要注意在Document类构造函数中定义为35f的左右边距
这对我很有效。
发布于 2020-09-02 17:01:15
var pgSize = new iTextSharp.text.Rectangle(1042, 651);
var doc = new iTextSharp.text.Document(pgSize, 0, 0, 0, 0);https://stackoverflow.com/questions/10992216
复制相似问题