How to print image using ESC/POS - c#

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.

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";

Value of a variable is not updating

I am currently working on a project that sweeps a mailbox for attachments and when one is found it is placed in the user's directory. My problem is that when I check if the file exist in the path, I alter the attachment's name and add a counter and time stamp, that way it is not over written. However, when it goes into the condition and changes the file name it never updates the path variable to include the right value of the Clean name variable.
string timeProcessed = DateTime.Now.ToString();
byte[] bytefiles = attachment.ContentBytes;
string cleanName = MakeCleanName(userEmail.Subject, attachment.Name);
string path = employeeStarPath + "\\" + cleanName;
// updated this in order to prevent images with the same name from overwritting eachother.
if (File.Exists(path))
{
cleanName = Path.GetFileNameWithoutExtension(attachment.Name).ToString()+"(" + counter + ")" + "-(Recieved - " + timeProcessed.Replace(":",".").Replace("/",".") + " )"+ Path.GetExtension(attachment.Name); << this value is not updated in the path variable.
}
Now I am aware I can update the path var by calling path = employeeStarPath + "\\" + cleanName; again but I feel that this makes my code a bit confusing.
I might not understood your question but can you just call the line "string path = employeeStarPath + "\" + cleanName;" at the end instead before the if?
string timeProcessed = DateTime.Now.ToString();
byte[] bytefiles = attachment.ContentBytes;
string cleanName = MakeCleanName(userEmail.Subject, attachment.Name);
// updated this in order to prevent images with the same name from overwritting eachother.
if (File.Exists(path))
{
cleanName = Path.GetFileNameWithoutExtension(attachment.Name).ToString()+"(" + counter + ")" + "-(Recieved - " + timeProcessed.Replace(":",".").Replace("/",".") + " )"+ Path.GetExtension(attachment.Name); << this value is not updated in the path variable.
}
string path = employeeStarPath + "\\" + cleanName;

Internal Error !scandr.cpp #1952 in autocad2015

I am trying to export the drawing to save another drawing using "CopyBase" and "PasteClip" command. But it is does not work an error occurred. Can anyone tell how to i solve this..
i am using Copy and Paste command like this..
AcadApplication acadApp;
AcadDocument thisdrawing;
acadApp = Marshal.GetActiveObject("AutoCAD.Application.20") as AcadApplication;
acadApp.Visible = true;
thisdrawing= acadApp.ActiveDocument;
thisdrawing.Activate();
string str = "_CopyBase" + char.ConvertFromUtf32(13) + "0,0,0" + char.ConvertFromUtf32(13) + "M" + char.ConvertFromUtf32(13) + "G" + char.ConvertFromUtf32(13) + "QWERT" + "\n" + char.ConvertFromUtf32(13);
thisdrawing.SendCommand(str);
string dwgTempPath = "acad.dwt";
newThisdrawing = acapp.Documents.Add(dwgTempPath ) ;
newThisdrawing.SaveAs(expDwgName , thisdrawing.Application.Preferences.OpenSave.SaveAsType,null);
newDwgCreatBool = true;
newThisdrawing.Regen(AcRegenType.acActiveViewport);
newthisdrawing.Activate();
comStr = "pasteclip" + "\n" + "0,0" + "\n";
newThisdrawing.SendCommand(comStr);
Thanks in Advance..
With your edit, I'm assuming this is an external exe. With that in mind and some minor modifications to your code, I got this to work with no problems in a Console exe. Before the code a couple things about it:
I compiled using the 4.5 Framework. The COM references for .NET may have been updated with their .NET API counterparts, so make sure this is the case for you too.
Add a COM reference to "AutoCAD 2015 Type Library" there's one for each language package (choose axdb20enu.tlb, but I think in the end VS may select them all after it's added).
Add a COM reference to "AcObjClassImp 1.0 Type Library", choose the one for release 20 (AcObjClassImp20.tlb)
Add the using statement "using AutoCAD;" at the top with the rest.
Here's the code I used:
static void Main(string[] args)
{
IAcadApplication acadApp;
IAcadDocument thisdrawing;
acadApp = Marshal.GetActiveObject("AutoCAD.Application.20") as AcadApplication;
acadApp.Visible = true;
thisdrawing = acadApp.ActiveDocument;
thisdrawing.Activate();
string str = "_CopyBase" + char.ConvertFromUtf32(13) + "0,0,0" + char.ConvertFromUtf32(13) + "M" + char.ConvertFromUtf32(13) + "G" + char.ConvertFromUtf32(13) + "QWERT" + "\n" + char.ConvertFromUtf32(13);
thisdrawing.SendCommand(str);
string dwgTempPath = "acad.dwt";
IAcadDocument newThisdrawing = acadApp.Documents.Add(dwgTempPath);
//Instead of the path below, use your full path, formatted correctly
newThisdrawing.SaveAs(#"C:\Acad\Test.dwg", thisdrawing.Application.Preferences.OpenSave.SaveAsType, null);
newThisdrawing.Regen(AcRegenType.acActiveViewport);
newThisdrawing.Activate();
string comStr = "pasteclip" + "\n" + "0,0" + "\n";
newThisdrawing.SendCommand(comStr);
}

Microsoft.Office.Interop.Word - Overwriting text in current document, how to stop this?

I am trying to add text to a document and format it appropriately.
It works as long as there is no text after the insertion point, but if there is then it overwrites it. Why is that?
Here is my code in which the text is written. Again, this works if there is nothing after it.
// Header
var p = p2.Range.Paragraphs.Add();
var x = p.Range.Paragraphs.Count;
p.Range.Text = String.Format(headerText + "\r\n");
p.Range.set_Style("Req Level " + layerNumber.ToString() + " - Body");
// Description
p2 = p.Range.Paragraphs.Add();
p2.Range.Text = String.Format(bodyText + "\r\n");
p2.Range.set_Style("Req Level " + layerNumber.ToString());
If you want to put the description at the same level as header:
var pp = p2.Range.Paragraphs.Add();
pp.Range.Text = String.Format(bodyText + "\r\n");
pp.Range.set_Style("Req Level " + layerNumber.ToString());

Trouble with barcode rotation using Lesinowsky plugin

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;

Categories