如何使用间距,制表符或填充来对齐列中的内容? [英] How to align content in columns using spacing, tabs or padding?
本文介绍了如何使用间距,制表符或填充来对齐列中的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建这样的pdf
i'm trying to create a pdf looks like this
但是当我尝试字符串填充时,它在pdf文件中看起来像这样
but when i try string padding, it looks like this in pdf file
这里是我试过的c#代码的一部分。 myExcelData是从excel文件中填充的。
here is the part of the c# code i tried. myExcelData is filled from excel file.
for (int i = 0; i < 15; i++)
{
Chunk cSira = new Chunk((i + 1).ToString().PadRight(10), icerikFont);
Chunk cHizmet = new Chunk(myExcelData.Tables[0].Rows[i][6].ToString().PadRight(80), icerikFont);
Chunk cAdet = new Chunk(myExcelData.Tables[0].Rows[i][1].ToString().PadRight(10), icerikFont);
Chunk cBirimFiyat = new Chunk(myExcelData.Tables[0].Rows[i][2].ToString().PadRight(20), icerikFont);
Chunk cTutar = new Chunk(myExcelData.Tables[0].Rows[i][3].ToString().PadRight(20), icerikFont);
d.Add(cSira);
d.Add(cHizmet);
d.Add(cAdet);
d.Add(cBirimFiyat);
d.Add(cTutar);
d.Add(Chunk.NEWLINE);
}
推荐答案
有两种方法可以做这个:
There are two ways to do this:
- 使用等宽字体(例如Courier)。目前,您使用的字体宽度不同。
- download 我的书的第2章并学习如何使用TAB CHUNKS(在第48页查找该标题)。
- 使用PdfPTable作为mkl表示在他的评论中(也许你忽视了明显的)
- use a monospaced font (e.g. Courier). Currently you're using a font of which the width of the different characters is different.
- download chapter 2 of my book and learn how to use TAB CHUNKS (look for that title on page 48).
- Use a PdfPTable as mkl indicates in his comment (maybe you were overlooking the obvious)
如果您需要选项2的代码片段,请查看< a href =http://itextpdf.com/examples/iia.php?id=45 =nofollow> DirectorOverview3 示例。结果类似于此。如果您不了解Java,请阅读 C#示例。
If you need a code snippet for option 2, take a look at the DirectorOverview3 example. The result looks like this. If you don't understand Java, read the C# example.
这篇关于如何使用间距,制表符或填充来对齐列中的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文