Skip to content

Commit

Permalink
Manually draw barcode label
Browse files Browse the repository at this point in the history
  • Loading branch information
Deadpikle committed Jul 10, 2019
1 parent c237deb commit 1fa34a9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions SimpleInventory/Helpers/BarcodePDFGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ public int GenerateBarcodes(string outputPath)
// Generate a barcode
var barcodeCreator = new BarcodeLib.Barcode();
barcodeCreator.ImageFormat = ImageFormat.Jpeg;
barcodeCreator.IncludeLabel = true;
barcodeCreator.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
barcodeCreator.IncludeLabel = false;
//barcodeCreator.IncludeLabel = true;
//barcodeCreator.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
barcodeCreator.Alignment = BarcodeLib.AlignmentPositions.CENTER;

bool isPageFull = false;
Expand All @@ -136,17 +137,23 @@ public int GenerateBarcodes(string outputPath)
// TODO: There has got to be a better way to make things fairly consistent across computers
// with different DPI. This is ridiculous. I love WPF most of the time with its DPI
// help, but in this case.......ugh. Images come out a little blurry this way
// on computers with a non-192 DPI.
// on computers with a non-192 DPI, but scanners will probably be OK.
double ratioTo192 = (192 / image.VerticalResolution);
int resizeHeight = (int)(image.Height / ratioTo192);
int resizeWidth = (int)(image.Width / ratioTo192);
image = ResizeImage(image, resizeWidth, resizeHeight, (int)image.VerticalResolution);
// ok, now we can draw.
XImage pdfImage = XImage.FromBitmapSource(ConvertImageToBitmapImage(image));
gfx.DrawImage(pdfImage, xCoord, yCoord);
// now draw label
XFont barcodeFont = new XFont("Verdana", 16, XFontStyle.Bold);
// + 2 on the y coordinate there just to give it a teensy bit of space
gfx.DrawString(barcodeToUse.ToString(), barcodeFont, XBrushes.Black,
new XRect(xCoord, yCoord + pdfImage.PointHeight + 2, pdfImage.PointWidth, 150), XStringFormats.TopCenter);
//
xCoord += XUnit.FromPoint(pdfImage.PointWidth);
imageHeight = XUnit.FromPoint(pdfImage.PointHeight);
var blah = XUnit.FromPoint(image.Width);
//var blah = XUnit.FromPoint(image.Width);
XUnit spaceBetweenBarcodes = XUnit.FromInch(0.75);
if (xCoord + XUnit.FromPoint(pdfImage.PointWidth) + spaceBetweenBarcodes > page.Width - XUnit.FromInch(1))
{
Expand Down

0 comments on commit 1fa34a9

Please sign in to comment.