I am trying to create a PDF using iTextSharp library (version 4.1.2.0). At the top of the document, I want to add a logo, horizontal line and - below the line - some text (title).
I'm trying to achieve this by:
- creating a PdfPTable with one column size
- adding to it a PdfPCell with border set to BOTTOM_BORDER containing the logo image
- adding another PdfPCell with the title text to the PdfPTable
However, in the resulting PDF the image overwrites the bottom border (which otherwise shows开发者_如何学运维 fine). How can I stop it from overwriting it? The only way I've been able to do it is by setting FIT parameter of the PdfPCell constructor to true, but this completely destroys the layout (the image is enormous).
The code:
document.Open();
Image img = Image.GetInstance("Logo.PNG");
PdfPCell cell = new PdfPCell(img, false);
PdfPTable table = new PdfPTable(1);
cell.Border = PdfPCell.BOTTOM_BORDER;
table.DefaultCell.Border = PdfPCell.NO_BORDER;
table.WidthPercentage = 100;
table.AddCell(cell);
PdfPCell cell2 = new PdfPCell(new Phrase("Title"));
cell2.Border = PdfPCell.TOP_BORDER;
table.AddCell(cell2);
document.Add(table);
document.Close();
And this is how it looks like:
This is how it looks like
Try adding this:
cell.PaddingBottom = 5;
So the updated code would be:
PdfPTable table = new PdfPTable(1);
table.DefaultCell.Border = PdfPCell.NO_BORDER;
table.WidthPercentage = 100;
Image img = Image.GetInstance("Logo.PNG");
PdfPCell cell = new PdfPCell(img, false);
cell.Border = PdfPCell.BOTTOM_BORDER;
cell.PaddingBottom = 5;
table.AddCell(cell);
PdfPCell cell2 = new PdfPCell(new Phrase("Title"));
table.AddCell(cell2);
document.Add(table);
document.Close();
Something else to try:
cell.UseBorderPadding = true;
精彩评论