繁体   English   中英

使用 itextsharp 以 pdf 格式打印 icard

[英]print an icard in pdf using itextsharp

我想创建一个包含 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 等。

想出解决办法:

Document IcardDoc = new Document(new Retangele(200f, 315f),35f,35f,0f,0f);

并相应地调整表格的宽度:

PdfPTable icardTable = new PdfPTable(2);
icardTable.WidthPercentage = 140f;

使表格完全适合页面,如果减小矩形width则增加表格WidthPercentage ,反之亦然。 您还需要注意在Document类构造函数中定义为 35f 的左右边距

这对我有用。

var pgSize = new iTextSharp.text.Rectangle(1042, 651);
var doc = new iTextSharp.text.Document(pgSize, 0, 0, 0, 0);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM