我有生成的代码,我必须在pdf文件上打印。我尝试过使用iTextSharp这是我试过的,还添加了图片以便理解
string l_strDomainName = "Example.com\n";
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Document pdfDoc = new Document(PageSize.A4, 5f, 10f, 30f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
float[] widths = new float[] { 2f, 2f, 2f, 2f, 2f, 2f, 2f, 2f, 2f };
float[] widths1 = new float[] { 12f, 8f };
Chunk domainname = new Chunk(l_strDomainName, new Font(Font.HELVETICA, 6f, Font.ITALIC, Color.RED));
PdfPTable table = new PdfPTable(9);
table.TotalWidth = 500f;
table.DefaultCell.Border = 0;
table.SetWidths(widths);
foreach (var item in CodeList)
{
if (item.ToString().Trim() != "")
{
PdfPCell C1R1 = new PdfPCell(new Phrase(domainname + item + "\n", new Font(Font.HELVETICA, 6f, Font.NORMAL, Color.BLACK)));
C1R1.Border = 1;
C1R1.FixedHeight = 25f;
C1R1.HorizontalAlignment = 1;
C1R1.VerticalAlignment = PdfPCell.ALIGN_BOTTOM;
table.AddCell(C1R1);
}
else if (item.ToString().Trim() == "")
{
table.AddCell("Used");
}
}
if ((CodeList.Count) % 9 < 9)
{
for (int rows = 0; rows < 9 - (CodeList.Count) % 9; rows++)
{
table.AddCell("");
}
}
pdfDoc.Add(table);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
输出如下
我的问题是我想在矩形框内打印此代码,如A4尺寸页面上的贴纸。因此可以将其交给客户。如下
他们有什么办法可以实现这个目标吗? 提前致谢