C# 如何设置一个表,每行有不同数量的列?
我只是在学习iText7,但我似乎无法调整我的桌子布局。 我在绘画中画了我想要的东西,只是为了向你们展示(请不要讨厌我的绘画技巧:P) 仅供参考:C# 如何设置一个表,每行有不同数量的列?,c#,pdf,itext7,C#,Pdf,Itext7,我只是在学习iText7,但我似乎无法调整我的桌子布局。 我在绘画中画了我想要的东西,只是为了向你们展示(请不要讨厌我的绘画技巧:P) 仅供参考: 第一行将是文本 第二行首先是文本,然后是图片 然后是一小行文字 然后是一段文字和旁边的一张图片 不知何故,我的第一行一直在设置下面所有单元格的宽度 我试着使用一个普通的细胞和一个头部细胞,但我一直得到相同的结果 private void TestPDF() { var CustomSize= new Rectan
- 第一行将是文本
- 第二行首先是文本,然后是图片
- 然后是一小行文字
- 然后是一段文字和旁边的一张图片
private void TestPDF()
{
var CustomSize= new Rectangle(241, 142);
var writer = new PdfWriter("Test " + DateTime.Now.ToString("dd-MM-yyy") + ".pdf");
var pdf = new PdfDocument(writer);
var document = new Document(pdf, new PageSize(CustomSize));
document.SetMargins(0, 0, 0, 0);
var tableinformatie = new Table(2);
tableinformatie.SetWidth(241);
tableinformatie.SetHeight(142);
tableinformatie.SetPadding(0);
tableinformatie.AddHeaderCell("test").UseAllAvailableWidth();
tableinformatie.AddCell("test").SetWidth(241);
tableinformatie.AddCell("test").SetWidth(100);
document.Add(tableinformatie);
document.Close();
}
这是到目前为止我的代码,我尝试使用固定的布局。设置每个单元格的宽度和高度,但不起作用
我一定是忽略了什么
先谢谢你
编辑:
我想多张桌子,而不是一张桌子。这对我来说是成功的:)
这将创建具有正确大小的正确表格
谢谢保罗·苏亚雷斯的创意
private void StickerInMM()
{
var Sticker = new Rectangle(241, 142);
var writer = new PdfWriter("Test " + DateTime.Now.ToString("dd-MM-yyy") + ".pdf");
var pdf = new PdfDocument(writer);
var document = new Document(pdf, new PageSize(Sticker));
document.SetMargins(0, 0, 0, 0);
ImageData data = ImageDataFactory.Create("c:/Users/Public/Cyaan.jpg");
Image img = new Image(data);
img.SetHeight(15);
ImageData data2 = ImageDataFactory.Create("c:/Users/Public/Tekst.jpg");
Image img2 = new Image(data2);
img2.ScaleToFit(100, 100);
var EANFONT = PdfFontFactory.CreateFont("c:/Users/Public/ean13.ttf", PdfEncodings.IDENTITY_H, true);
var cellean = new Paragraph(richTextBox2.Text)
.SetFontSize(38)
.SetFont(EANFONT);
var table = new Table(new float[] { 1 });
table.SetWidth(UnitValue.CreatePercentValue(100));
table.AddCell("Laser toner cartridge");
document.Add(table);
var table2 = new Table(new float[] { 3, 1 });
table2.SetWidth(UnitValue.CreatePercentValue(100));
table2.AddCell("Test");
table2.AddCell(img);
document.Add(table2);
var table3 = new Table(new float[] { 1 });
table3.SetWidth(UnitValue.CreatePercentValue(100));
table3.AddCell("Test");
document.Add(table3);
var table4 = new Table(new float[] { 2, 2 });
table4.SetWidth(UnitValue.CreatePercentValue(100));
table4.AddCell(img2);
table4.AddCell(cellean);
document.Add(table4);
document.Close();
}
用上面的代码修复了它:D 您想要的不是一张桌子,而是一组堆叠的桌子。您可以使用列span,但使用多个表可能更容易。这是一个很好的解决方法,但在表之间留下了空白。不知道该如何表达:请用解决方案对您的问题进行编辑,使其成为您可以接受的问题的实际答案(而不是对问题的编辑):“您应该在标题中使用标记的唯一时间是当它们与标题的对话基调有机结合时。”
private void StickerInMM()
{
var Sticker = new Rectangle(241, 142);
var writer = new PdfWriter("Test " + DateTime.Now.ToString("dd-MM-yyy") + ".pdf");
var pdf = new PdfDocument(writer);
var document = new Document(pdf, new PageSize(Sticker));
document.SetMargins(0, 0, 0, 0);
ImageData data = ImageDataFactory.Create("c:/Users/Public/Cyaan.jpg");
Image img = new Image(data);
img.SetHeight(15);
ImageData data2 = ImageDataFactory.Create("c:/Users/Public/Tekst.jpg");
Image img2 = new Image(data2);
img2.ScaleToFit(100, 100);
var EANFONT = PdfFontFactory.CreateFont("c:/Users/Public/ean13.ttf", PdfEncodings.IDENTITY_H, true);
var cellean = new Paragraph(richTextBox2.Text)
.SetFontSize(38)
.SetFont(EANFONT);
var table = new Table(new float[] { 1 });
table.SetWidth(UnitValue.CreatePercentValue(100));
table.AddCell("Laser toner cartridge");
document.Add(table);
var table2 = new Table(new float[] { 3, 1 });
table2.SetWidth(UnitValue.CreatePercentValue(100));
table2.AddCell("Test");
table2.AddCell(img);
document.Add(table2);
var table3 = new Table(new float[] { 1 });
table3.SetWidth(UnitValue.CreatePercentValue(100));
table3.AddCell("Test");
document.Add(table3);
var table4 = new Table(new float[] { 2, 2 });
table4.SetWidth(UnitValue.CreatePercentValue(100));
table4.AddCell(img2);
table4.AddCell(cellean);
document.Add(table4);
document.Close();
}