How to generate pdf with my datamatrix like a sample. I try to do that :
private void buttonAchatPrintDataMatrix_Click(object sender, EventArgs e)
{
float borderTop, borderLeft, borderRight, borderBottom;
borderTop = borderLeft = borderRight = borderBottom = 60.0f;
float horizontalMargin, verticalMargin, codeHeight, codeWidth;
verticalMargin = 10.0f;
horizontalMargin = 20.0f;
codeWidth = 42.0f;
codeHeight = 42.0f;
int maxColCount, maxRowCount;
maxColCount = 5;
maxRowCount = 20;
String output = "DataMatrix_0.pdf";
Document doc = new Document();
PdfWriter writer = null;
int x = 0;
while (File.Exists(output))
output = "DataMatrix_" + Convert.ToString(++x) + ".pdf";
writer = PdfWriter.GetInstance(doc, new FileStream(output, FileMode.Create));
doc.Open();
if (doc.PageSize.Width < codeWidth)
{
codeWidth = doc.PageSize.Width;
}
if (doc.PageSize.Height < codeHeight)
{
codeHeight = doc.PageSize.Height;
}
try
{
float top = borderTop;
float left = borderLeft;
int colIndex = 0;
int rowIndex = 0;
for (int i = 0; i < listBoxAchatProduit.Items.Count; ++i)
{
BarcodeDatamatrix barcodeDatamatrix = new BarcodeDatamatrix();
barcodeDatamatrix.Generate(listBoxAchatProduit.Items[i].ToString());
iTextSharp.text.Image img = barcodeDatamatrix.CreateImage();
float widthRatio = img.Width / codeWidth;
float heightRatio = img.Height / codeHeight;
if (widthRatio > heightRatio)
{
img.ScalePercent(100.0f/widthRatio);
}
else
{
img.ScalePercent(100.0f/heightRatio);
}
img.SetAbsolutePosition(left, doc.PageSize.Height - top - img.ScaledHeight);
doc.Add(barcodeDatamatrix.CreateImage());
top += horizontalMargin + codeHeight;
if (++rowIndex > maxRowCount)
{
left = borderLeft;
top = borderTop;
colIndex = 0;
rowIndex = 0;
doc.NewPage();
}
if (top + codeHeight > doc.PageSize.Height - borderBottom)
{
top = borderTop;
rowIndex = 0;
colIndex++;
left = borderLeft + colIndex * (codeWidth + verticalMargin);
if (colIndex >= maxColCount || (left + codeWidth) > doc.PageSize.Width - borderRight)
{
left = borderLeft;
top = borderTop;
colIndex = 0;
rowIndex = 0;
doc.NewPage();
}
}
}
}
catch (Exception ex)
{
FoveaManager.MsgError("buttonAchatPrintDataMatrix_Click : Error generating code '{0}': {1}" + ex.Message);
}
finally
{
doc.Close();
}
}
I was copy and paste a sample and modify what I want but a result isvery strange. When I generate a datamatrix with a same parameters I have biggest Image.
Thank for your help
sorry to my bad english i'm french
result