Reputation: 1533
I have in my project changing number of tables and in the end of all of the tables I added image.
My problem is that if I added too many tables, the image just shrink and not moving to the next page.
Also I have more report that I want to auto paging them, so if one table is out of rage of current page, it automatically move this table to next page.
I write in C# on VS 2010
This is part of my code:
private void CreateQCTable(Document mdoc, DataRow Headers, DataTable Table, String imgurl, int lb_or_ss)
{
PdfPTable table;
PdfPCell cell;
CultureInfo currentCulture = new CultureInfo("he-IL");
Font ArialSmall = FontFactory.GetFont("Arial", 7F, Font.NORMAL, BaseColor.BLACK);
Font ArialSmallRowSpan = FontFactory.GetFont("Arial", 7F, Font.NORMAL, BaseColor.BLACK);
Font ArialSmallGreen = FontFactory.GetFont("Arial", 7F, Font.NORMAL, new BaseColor(0, 100, 0));
Font ArialSmallRed = FontFactory.GetFont("Arial", 7F, Font.NORMAL, BaseColor.RED);
Font ArialSmallBlue = FontFactory.GetFont("Arial", 7F, Font.NORMAL, new BaseColor(0, 68, 136));
Font ArialBold = FontFactory.GetFont("Arial", 8F, Font.BOLD, BaseColor.BLACK);
String NewGroupName = Table.Rows[0]["group"].ToString();
String OldGroupName = Table.Rows[0]["group"].ToString();
int i = 0;
while (i < Table.Rows.Count)
{
float[] headersparam = new float[Headers.ItemArray.Length - 1];
for (int j = 0; j < Headers.ItemArray.Length - 1; j++)
{
headersparam[j] = 0.1f;
}
table = new PdfPTable(headersparam);
table.WidthPercentage = 90;
table.SpacingBefore = 0;
int internalRowCount = 0;
if (internalRowCount == 0)
{
cell = new PdfPCell(new Phrase("DATE: " + Table.Rows[i]["group"].ToString(), ArialBold));
cell.PaddingTop = 25;
cell.Colspan = Headers.ItemArray.Length - 1;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.BorderWidth = 0f;
cell.BorderWidthBottom = 0.6f;
table.AddCell(cell);
foreach (object obj in Headers.ItemArray)
{
if (obj.ToString() != "")
{
cell = new PdfPCell(new Phrase(obj.ToString(), ArialBold));
cell.PaddingTop = 10;
cell.PaddingBottom = 5;
cell.Colspan = 1;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.BorderWidth = 0f;
cell.BorderWidthBottom = 0.6f;
table.AddCell(cell);
}
}
internalRowCount++;
}
while (OldGroupName == NewGroupName && i < Table.Rows.Count)
{
i++;
if (i < Table.Rows.Count)
OldGroupName = Table.Rows[i]["group"].ToString();
foreach (object obj in Table.Rows[i - 1].ItemArray)
{
if ( obj.ToString() != Table.Rows[i - 1]["group"].ToString())
{
if (obj.ToString() == "PASSED")
AddTextCell(table, new PdfPCell(new Phrase(obj.ToString(), ArialSmallGreen)), Element.ALIGN_LEFT, 1, 1, 0, 0.5F, 0, 0, 5, 5, BaseColor.WHITE);
else if(obj.ToString() == "FAILED")
AddTextCell(table, new PdfPCell(new Phrase(obj.ToString(), ArialSmallRed)), Element.ALIGN_LEFT, 1, 1, 0, 0.5F, 0, 0, 5, 5, BaseColor.WHITE);
else
AddTextCell(table, new PdfPCell(new Phrase(obj.ToString(), ArialSmall)), Element.ALIGN_LEFT, 1, 1, 0, 0.5F, 0, 0, 5, 5, BaseColor.WHITE);
}
}
}
mdoc.Add(table);
if (i < Table.Rows.Count)
{
NewGroupName = Table.Rows[i]["group"].ToString();
}
}
table = new PdfPTable(new float[] { 0.1f});
table.WidthPercentage = 90;
table.SpacingBefore = 0;
FileStream fs;
fs = File.OpenRead(imgurl);
int length = (int)fs.Length;
byte[] logo = new byte[length];
fs.Read(logo, 0, length);
fs = null;
var stream = new System.IO.MemoryStream();
if (logo.Length != 0)
{
System.Drawing.Image img2 = System.Drawing.Image.FromStream(new MemoryStream(logo));
img2.Save(stream, ImageFormat.Jpeg);
stream.Position = 0;
}
cell = new PdfPCell(iTextSharp.text.Image.GetInstance(stream), true);
cell.Rowspan = 1;
cell.PaddingTop = 25;
cell.PaddingBottom = 50;
cell.PaddingLeft = 50;
cell.PaddingRight = 50;
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.BorderWidth = 0f;
table.AddCell(cell);
mdoc.Add(table);
}
Thanks for help!
Upvotes: 1
Views: 1779
Reputation: 77528
In Java one would use:
image.setScaleToFitHeight(false);
The corresponding syntax in iTextSharp is:
Image.ScaleToFitLineWhenOverflow = false;
(See comment by user2235615)
Upvotes: 2