I've got a couple of questions related to converting inches to pixels and how that relates to a standard 8.5" x 11" sheet of paper that these labels or on.
The current labels that I'm writing on are on a standard paper 8.5 x 11 with 3 columns and 10 rows.
I've started this out by creating a SheetInfo class.
When I create my Bitmap that I'm calling Sheet is it necessary to set the width and height of the Bitmap "Sheet" to be oversized like I'm noticing others mentioning on the net. They're saying set the sheet to 1700 x 2200 pixels so that the user can choose fit to page when printing, and this will produce a better quality print.
The thing that is throwing me off is when I drawstring to a label in a loop then i get to the very next label in the same row but the next column I need the formula to write the text correctly, since I'm not writing to an oversized Bitmap.
public class SheetInfo
{
public byte Columns { get; set; }
public byte Rows { get; set; }
public decimal ContentWidth { get; set; }
public decimal ContentHeight { get; set; }
public short SheetWidth { get; set; }
public short SheetHeight { get; set; }
public SheetInfo() { }
public SheetInfo(byte columns, byte rows, decimal contentWidth, decimal contentHeight, short sheetWidth, short sheetHeight)
{
this.Columns = columns;
this.Rows = rows;
this.ContentWidth = contentWidth;
this.ContentHeight = contentHeight;
this.SheetWidth = sheetWidth;
this.SheetHeight = sheetHeight;
}
}
SheetInfo sinfo = new SheetInfo(3, 10, 2.6250m, 1, 1700, 2200);
sheets = ContentContainers.GetLabels(this.Optimized.OrderBy(o => o.CutPart.PartNumber).ToList<IGroupedPart>(), sinfo);
public static List<Bitmap> GetLabels(List<IGroupedPart> optimized, SheetInfo sheetInfo)
{
int totalParts = optimized.Count();
byte currowCnt = 0,
currColumnCnt = 0;
float left = 10.0f,
margin = 10.0f,
startX = margin + left,
startY = margin + left;
List<Bitmap> sheets = new List<Bitmap>();
using (var f = new Font(DrawingOptions.DETAIL_BOX_FONT.FontFamily, 12))
{
var sheet = new Bitmap(sheetInfo.SheetWidth, sheetInfo.SheetHeight);
using (var dc = Graphics.FromImage(sheet))
{
for (short i = 0; i < totalParts; i++)
{
string len = optimized[i].CutPart.Length.ToString("N4"),
nm = optimized[i].CutPart.Name;
int cnt = optimized[i].Total;
for (int ii = 0; ii < cnt; ii++)
{
dc.DrawString("line 1 text", f, Brushes.Black, new PointF(startX, startY));
startX = margin + left + ((float)sheetInfo.ContentWidth * (i + 1));
currColumnCnt += 1;
if (currColumnCnt == sheetInfo.Columns/*new row needed*/)
{
startY = margin + left + ((float)sheetInfo.ContentHeight * (i + 1));
}
if ((i + 1) == sheetInfo.Rows/*new sheet needed*/)
{
//
}
else
{
// startY = margin + left;
}
};
};
sheets.Add(sheet);
};
};
return sheets;
}
Are there a couple of variables that I can set to add to the X and Y poistions that will relate to the oversized Bitmap "Sheet"?