How to align content in columns using spacing, tabs or padding?

社会主义新天地 提交于 2019-12-20 05:40:05

问题


i'm trying to create a pdf looks like this

but when i try string padding, it looks like this in pdf file

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);
        }

回答1:


There are two ways to do this:

  1. use a monospaced font (e.g. Courier). Currently you're using a font of which the width of the different characters is different.
  2. download chapter 2 of my book and learn how to use TAB CHUNKS (look for that title on page 48).
  3. Use a PdfPTable as mkl indicates in his comment (maybe you were overlooking the obvious)

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.



来源:https://stackoverflow.com/questions/14982818/how-to-align-content-in-columns-using-spacing-tabs-or-padding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!