I am a bit stuck and it's my first time using iTextsharp, I am trying to create a C# application that generate random numbers then print it into PDF file as a label Report, the user is going to have a panel and a label in witch he can move any where with in the panel and can change the panel size as will as adding an image as a background image .
Now after the user enters the specified size and "drag and drop" the label it to the desired location inside the panel and choose an image as background image, My code will start making iTextsharp table with the number of columns and rows depending on the user input, and every cell is must be as the size as the panel from the Form and have the same Background image and the text must be in the exact place as but by the user,
The things that work:
1- Drag and drop is working fine.
2- I can print the table cells with the exact size as the user input.
Things that doesn't work:
1- I can add an image but i can't stretch it to the size of the cell when printing to PDF
2- I can't align the text at an exact position ,only (CENTER ,TOP_LEFT ,..etc)
3- I can't add a text on top of the image
This is a screen shot of the Form :
http://imgur.com/a/LAnSX
This is the code for creating the table and adding the image and text
private iTextSharp.text.Image myImage;
private ImagePath = "path";
private void ExportToPDF_Click(object sender, EventArgs e)
{
try
{
saveFileDialog1.Filter = "pdf File |*.pdf";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
FilePath = saveFileDialog1.FileName.ToString();
FileStream fs = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
Document document = new Document(PageSize.A4, pageLeftMargen, pageRightMargen, pageTopMargen, pageBottomMargen);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
PdfPTable table = new PdfPTable(Get_Columens_Count());
table.LockedWidth = true;
table.TotalWidth = Get_Tabel_Width();
float[] a = new float[Get_Columens_Count()];
for (int i = 0; i < Get_Columens_Count(); i++)
{
a[i] = Convert.ToInt32(Get_CellsWidth());
}
table.SetWidths(a);
PdfPCell cell = new PdfPCell();
cell.BorderWidth = CellBorderWidth;
cell.Padding = CellsPadding;
cell.FixedHeight = Convert.ToInt32(Get_Cells_Height());
if (checkBox1.Checked == true && File.Exists(ImagePath) == true)
{
myImage = iTextSharp.text.Image.GetInstance(ImagePath);
cell.AddElement(myImage);
}
for (int i = 0; i < Convert.ToInt32(Get_Records_Count()); i++)
{
table.AddCell(cell);
}
document.Add(table);
document.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw;
}
}
What I have tried:
What have i tried :
Almost every thing that i could try and find by googling and searching the forms nothing seems to work as a wanted.
ScaleAbsolute
ScaleToFit
and punch of other stuff that i can't remember at the moment .
is there better a broach than the one that i am using ?
thanks in advance :)