Trouble with barcode rotation using Lesinowsky plugin - c#

Working with this small barcode.dll from Lesinowsky(AKA limilabs barcode plugin). Straight barcode no problem, working as advertised but now I am attempting to rotate barcode image by 90 degrees.
And following error occurs:
Cannot implicitly convert type 'int' to 'Lesnikowski.Barcode.RotationType'
Below is exact code which I am using:
string barCode = barCodeTrans + barCodeSeq + barCodeIndex + rotationindex.ToString();
Lesnikowski.Barcode.Barcode128 bc = new Lesnikowski.Barcode.Barcode128();
bc.Rotation = 1; -- error goes away once I remove this line but I need to rotate image
bc.Number = barCode;
bc.CustomText = "";
bc.Height = 28;
bc.NarrowBarWidth = 2;
Bitmap bcBitMap = bc.GenerateBitmap();
string fileName = barCode + ".jpg";
bcBitMap.Save(outputDir + "/" + fileName, ImageFormat.Jpeg);
return fileName;
Please advise what is wrong and how to fix this unless that DLL no longer supports rotation of the barcode. Then it would be a shame.
Thanks

Below working code. Just make sure that when you passing variables to string barCode -- it is not empty or nulls. Single null in that string formation will ruin your day.
string barCode = barCodeTrans + barCodeSeq + barCodeIndex + rotationindex.ToString();
Lesnikowski.Barcode.Barcode128 bc = new Lesnikowski.Barcode.Barcode128();
bc.Rotation = Lesnikowski.Barcode.RotationType.Degrees90
bc.Number = barCode;
bc.CustomText = "";
bc.Height = 28;
bc.NarrowBarWidth = 2;
Bitmap bcBitMap = bc.GenerateBitmap();
string fileName = barCode + ".jpg";
bcBitMap.Save(outputDir + "/" + fileName, ImageFormat.Jpeg);
return fileName;

Related

capturing an image from the camera

I am working on a winforms application, the application will attempt to capture an image and save it to the hard drive without the need to present the result or the live stream to the form.
I was using AForge and suddenly I started getting null in my image variable, I tried several other packages and they are all giving the same problem.
I want to know if there is a setting on my system or in my code that is preventing the image from being copied to the variable.
the last one I tried was Microsoft Media Capturing package and the code as follows.
System.Drawing.Imaging.ImageFormat format = null;
format = System.Drawing.Imaging.ImageFormat.Jpeg;
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
string name = InitialSetup.currentLkr.Name /*+ #"\" + InitialSetup.currentLkr.Name + "_" + DateTime.Now.ToString() + ".jpg"*/;
name = name.Replace(#"/", "_");
name = name.Replace(" ", "_");
name = name.Replace(":", "-");
name = #"D:\" + name;
StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync(name,CreationCollisionOption.OpenIfExists);
await photo.CopyAsync(sf, InitialSetup.currentLkr.Name + "_" + DateTime.Now.ToString() + ".jpg", NameCollisionOption.ReplaceExisting);
await photo.DeleteAsync();
//img.Save(name);
//webcam.Stop();
return name+ InitialSetup.currentLkr.Name + "_" + DateTime.Now.ToString() + ".jpg";

How to print image using ESC/POS

I am working on C# POS. I am using raw printing helper and I am trying to print an image using ESC/POS commands with the command: ESC *.
So far I am able to:
string carriageReturn = Convert.ToString((char)13);
string lineFeed = carriageReturn + Convert.ToString((char)10);
string cutPaper = Convert.ToString((char)27) + Convert.ToString((char)105);
string horizontalTab = Convert.ToString((char)9);
string fontSize4 = Convert.ToString((char)29) + Convert.ToString((char)33) + Convert.ToString((char)51);
And I send the data to print with this:
printWithStringAndPrinter(fontSize4 + "this" + lineFeed + "is" + lineFeed + fontSize2 + "test" + lineFeed + cutPaper, p.name);
The only problem is with the image, I can not get it to print. I have tried this:
Bitmap bmp = new Bitmap("C:\\test.bmp");
string image = Convert.ToString((char)27) + Convert.ToString((char)42) + Convert.ToString((char)33) + Convert.ToString((char)0) + Convert.ToString((char)86) + bmp.ToString();
But nothing works. Can someone give an advice or an example of how to print an image?
Even though there are a lot of questions about the same topic, any of them has helped me.

Writing to docx using xceed.words.net.docx, works when run in VS, writes a line per page when run as built exe

I've been using this for a while and it's always worked fine. The project writes to a docx log file as it runs. I recently made a modification to the path it writes the log to for someone else to use. Since then, when I run it as a built exe it writes one line per page. But when I attempt to fix the problem, I can't recreate it running it in VS. From there it works like it always had.
Any ideas? A direction someone can point me toward?
public static void WritetoLogFile(string logUpdate)
{
DateTime now = DateTime.Now;
string logDate = now.ToString("MM-dd");
string folderNameDate = now.ToString("MM_dd_yyyy");
string folderName = folderNameDate + "_Logs";
string stateFolder = " ";
System.IO.Directory.CreateDirectory(Crawlspace.networkSharePath + "//" + folderName);
string logName = logDate + "_" + Crawlspace.browser + "_" + Crawlspace.computerName + "_" + Crawlspace.SuiteTable + ".docx";
Crawlspace.LogFileName = logName;
System.IO.Directory.CreateDirectory(Crawlspace.networkSharePath + folderName + "//" + stateFolder);
Crawlspace.LogFile = Crawlspace.networkSharePath + folderName + "//" + stateFolder + "//" + logName;
if (System.IO.File.Exists(Crawlspace.LogFile))
{
using (DocX document = DocX.Load(Crawlspace.LogFile))
{
Paragraph par1 = document.InsertParagraph();
par1.Append(logUpdate);
par1.Font("Courier New");
par1.FontSize(8);
document.Save();
}
}
else
{
using (DocX document = DocX.Create(Crawlspace.LogFile))
{
Paragraph par1 = document.InsertParagraph();
par1.Append(logUpdate);
par1.Font("Courier New");
par1.FontSize(8);
document.Save();
}
}
}
RESOLVED:
I checked the xceed.words.net.docx dll in the nuget manager and found there was an update. Updated to the latest and modified my using statements to reflect the update and it's now working....
using Image = Xceed.Document.NET.Image;
using Paragraph = Xceed.Document.NET.Paragraph;
using Picture = Xceed.Document.NET.Picture;

C# OPOS printing next to a bitmap on a rotated receipt

This problem concerns a thermal receipt printer. I have downloaded C# EPSON OPOS receipt printing examples in attempt to implement such a printer in my current project, all is working well but when I print a bitmap logo, successive text is being printed under it, and I need to print some text to the right side of it. Here is an approximation of what it does now:
This is what I need it to do:
My current code, pretty much as-is from EPSON's samples:
private void btnReceipt_Click(object sender, System.EventArgs e)
{
//<<<step8>>>--Start
//Initialization
DateTime nowDate = DateTime.Now; //System date
DateTimeFormatInfo dateFormat = new DateTimeFormatInfo(); //Date Format
dateFormat.MonthDayPattern = "MMMM";
string strDate = nowDate.ToString("MMMM,dd,yyyy HH:mm",dateFormat);
int iRecLineSpacing;
int iRecLineHeight;
bool bBuffering = true;
bool bBitmapPrint = false;
int iPrintRotation = 0;
string strCurDir = Directory.GetCurrentDirectory();
string strFilePath = strCurDir.Substring(0,
strCurDir.LastIndexOf("Step8") + "Step8\\".Length);
strFilePath += "bitmap_logo.bmp";
Cursor.Current = Cursors.WaitCursor;
Rotation[] arBitmapRotationList = m_Printer.RecBitmapRotationList;
Rotation[] arBarcodeRotationList = m_Printer.RecBarCodeRotationList;
//Check rotate bitmap
for (int i = 0; i < arBitmapRotationList.Length; i++)
{
if (arBitmapRotationList[i].Equals(Rotation.Left90))
{
bBitmapPrint = true;
iPrintRotation = (iPrintRotation | (int)PrintRotation.Left90)
| ((int)PrintRotation.Bitmap);
}
}
iRecLineSpacing = m_Printer.RecLineSpacing;
iRecLineHeight = m_Printer.RecLineHeight;
if (m_Printer.CapRecPresent == true)
{
try
{
m_Printer.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Transaction);
m_Printer.RotatePrint(PrinterStation.Receipt, (PrintRotation)iPrintRotation);
if (bBitmapPrint == true)
{
m_Printer.PrintBitmap(PrinterStation.Receipt, strFilePath, m_Printer.RecLineWidth, PosPrinter.PrinterBitmapCenter);
}
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|4C" + "\u001b|bC" + " Receipt ");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|3C" + "\u001b|2uC" + " Mr. Brawn\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|2uC" + " \n\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|2uC" + "\u001b|3C" + " Total payment $" +"\u001b|4C" + "21.00 \n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|1C\n" );
m_Printer.PrintNormal(PrinterStation.Receipt,strDate + " Received\n\n");
m_Printer.RecLineHeight = 24;
m_Printer.RecLineSpacing = m_Printer.RecLineHeight;
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|uC" + " Details \n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|1C" + " " + "\u001b|2C" + "OPOS Store\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|uC" + " Tax excluded $20.00\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|1C" + " " + "\u001b|bC" + "Zip code 999-9999\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|uC" + " Tax(5%) $1.00" + "\u001b|N" + " Phone#(9999)99-9998\n");
}
catch(PosControlException ex)
{
if(ex.ErrorCode == ErrorCode.Illegal && ex.ErrorCodeExtended == 1004)
{
MessageBox.Show("Unable to print receipt.\n", "Printer_SampleStep8", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// Clear the buffered data since the buffer retains print data when an error occurs during printing.
m_Printer.ClearOutput();
bBuffering = false;
}
}
try
{
m_Printer.RotatePrint(PrinterStation.Receipt, PrintRotation.Normal);
if(bBuffering == true)
{
m_Printer.PrintNormal(PrinterStation.Receipt, "\u001b|fP");
}
m_Printer.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Normal);
}
catch(PosControlException)
{
// Clear the buffered data since the buffer retains print data when an error occurs during printing.
m_Printer.ClearOutput();
}
}
m_Printer.RecLineSpacing = iRecLineSpacing;
m_Printer.RecLineHeight = iRecLineHeight;
Cursor.Current = Cursors.Default;
//<<<step8>>>--End
}
If there is a method to do absolute text positioning or being able to write to the same line where the bitmap is, it would solve my issue. Any directions appreciated!
Please ask EPSON whether you can print with the layout you want with one set of RotatePrint.
As an alternative, consider dividing it into two sets of RotatePrint.
If you first set of RotatePrint with Bitmap and "Some other text", and the second set of RotatePrint with "Sample text 1" to "Sample text 3", it will be close to the layout you want.
In addition:
Epson OPOS seems to support PageMode, so can you print it?
As for explanation of Japanese, please look through google translation etc.

gadget's name used as parameter on a method

enter code here:
//Displays the primary color
var ralnr = 9004;
var primColor = 2;
String primaryColor = column[firstIndex, primColor];
var primary = ralcode(primaryColor, out ralnr);
primaryRAL.Text = primaryColor + " " + "RAL" + " " + ralnr;
PictureBox gadget1 = primaryColorBox1;
string ral1 = ralnr.ToString();
backgroundcolorchange(gadget1, ral1);
//Displays the secondary color
var secColor = 3;
String secondaryColor = column[firstIndex, secColor];
var secondary = ralcode(secondaryColor, out ralnr);
secondaryRAL.Text = secondaryColor + " " + "RAL" + " " + ralnr; ;
PictureBox gadget2 = secondaryColorBox2;
string ral2 = ralnr.ToString();
backgroundcolorchange(gadget2, ral2);
hi I'm just new in programming. I was trying to pass the gadget's name
for the first gadget and it worked using the Method that I have
created but for the second gadget it did not worked. How is that?
private void backgroundcolorchange(PictureBox gadget, string ralcode)
{
string strPath = Application.StartupPath + "\\images\\";
gadget.BackgroundImage = Image.FromFile(strPath + ralcode + ".jpg");
gadget.BackgroundImageLayout = ImageLayout.Stretch;
}
I am guessing that primaryColorBox1 is a textbox?
Based on that guess, you would need to pass the whole object to backgroundcolorchange.
This is because you are trying to alter properties off of the textbox.
so your backgroundcolorchange method would be more like
private void backgroundcolorchange(TextBox gadget, string ralcode){ ...
But this is all I can guess based on the information supplied.

Categories