I've developed a system for generating an HTML tag and then converting it to a .PNG image.
I need to print this image on the Zebra printer, but I still don't have a printer, I'm testing with the Zpl Printer application and with the online ZPL Viewer at http://labelary.com/viewer.html.
My code is as follows: (C#)
var ipAddress = "127.0.0.1";
var port = 9100;
var bitmapImagePath = #"C:\Users\super\Desktop\Capturar.png";
var bitmapDataFileSize = new FileInfo(bitmapImagePath).Length;
var bitmapData = File.ReadAllBytes(bitmapImagePath);
var hexadecimalString = BitConverter.ToString(bitmapData).Replace("-", string.Empty);
var widthInBytes = Math.Ceiling(bitmapDataFileSize/8.0);
var etiqueta = "^XA^FO0,0^GFA," +
bitmapDataFileSize + "," +
bitmapDataFileSize + "," +
widthInBytes + "," +
hexadecimalString + "^XZ";
// Open connection
var client = new System.Net.Sockets.TcpClient();
client.Connect(ipAddress, port);
// Write ZPL String to connection
var writer = new StreamWriter(client.GetStream(), Encoding.UTF8);
writer.Write(etiqueta);
// Close Connection
writer.Close();
client.Close();
return etiqueta;
The Zpl Printer displays the message that received a few bytes from the client, but doesn't display anything.
I'm getting the ZPL return from my code and testing on the Labelary website and there it shows the label but in the wrong format.
I would like to know what I'm doing wrong, how to fix the label size and why not show up in the ZPL Printer app.
Note: the correct size is 3 x 14 cm.
Here is an example image:
Related
I'm using vs2017, C#, asp.net 4.6.1, and Rdlc 14.2 in a web.forms site
I have an one page report when I sent directly it to pdf, is in one page
ReportViewer1.DataBind();
Microsoft.Reporting.WebForms.Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
string deviceInfo = "<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>0.25in</MarginLeft>" +
" <MarginRight>0.25in</MarginRight>" +
" <MarginBottom>1in</MarginBottom>" +
"</DeviceInfo>";
byte[] writeBinaryBytes = new byte[0];
writeBinaryBytes = ReportViewer1.LocalReport.Render
("Pdf", deviceInfo, out mimeType, out encoding, out extension,
out streamids, out warnings);
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader
("content-disposition", "attachment; filename=" + nombreReporte+".pdf");
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.BinaryWrite(writeBinaryBytes);
HttpContext.Current.Response.Flush();
When I view it in ReportViewer is in one page, but if I export it to pdf or print it, is in two pages… This is my code behind before printing
System.Drawing.Printing.PageSettings pg = new System.Drawing.Printing.PageSettings();
pg.Margins.Top = 50; //hundredths of an inch 0.5" * 100
pg.Margins.Left = 25; //hundredths of an inch 0.25" * 100
pg.Margins.Right = 25; //hundredths of an inch 0.25" * 100
pg.Margins.Bottom = 100; //hundredths of an inch 1" * 100
System.Drawing.Printing.PaperSize size = new PaperSize
{
RawKind = (int)PaperKind.Letter
//hundredths of an inch
, Width = 850 //hundredths of an inch 8.5" * 100
, Height = 1100 //hundredths of an inch 11" * 100
};
pg.PaperSize = size;
pg.Landscape = false;
//pg.PaperSource.RawKind = (int)PaperKind.A5;
ReportViewer1.SetPageSettings(pg);
ReportViewer1.LocalReport.Refresh();
This is the ReportViewer control in aspx page:
<rsweb:ReportViewer ID="ReportViewer1" runat="server"
ShowToolBar="true"
ShowFindControls ="false"
ShowCredentialPrompts="true"
ShowDocumentMapButton="true"
EnableEventValidation="fase"
AsyncRendering = "false"
width="100%" />
Any suggestions?
Thanks
rubenc
Well it turned out that the problem was that I had margins set inside the RDLC report, I just changed them to 0 and now its working.
public void TagText() {
var jarRoot = "C:/Users/vi005/Documents/Visual Studio 2010/WebSites/mongodb/stanford-postagger-full-2015-12-09/stanford-postagger-full-2015-12-09";
var modelsDirectory = jarRoot + "/models";
// Loading POS Tagger
var tagger = new MaxentTagger(modelsDirectory + "/wsj-0-18-bidirectional-nodistsim.tagger");
// Text for tagging
var text = "A Part-Of-Speech Tagger (POS Tagger) is a piece of software that reads text" + "in some language and assigns parts of speech to each word (and other token)," +
" such as noun, verb, adjective, etc., although generally computational " + "applications use more fine-grained POS tags like 'noun-plural'.";
var sentences = MaxentTagger.tokenizeText(new StringReader(text)).toArray();
foreach(ArrayList sentence in sentences){
var taggedSentence = tagger.tagSentence(sentence);
Response.Write(Sentence.listToString(taggedSentence, false));
}
}
I need to Convert a xamarin forms image into a base64 format, Can anyone help me with this?
This is how i've being trying to do it, but it doesent work.
var inputStream = signatureImage.Source.GetValue(UriImageSource.UriProperty);
//Getting Stream as a Memorystream
var signatureMemoryStream = inputStream as MemoryStream;
if (signatureMemoryStream == null)
{
signatureMemoryStream = new MemoryStream();
inputStream.CopyTo(signatureMemoryStream);
}
//Adding memorystream into a byte array
var byteArray = signatureMemoryStream.ToArray();
//Converting byte array into Base64 string
base64String = Convert.ToBase64String(byteArray);
"signatureImage" is the image name.
Once you get your file path , you can use the following code that worked for me.
var stream = file.GetStream();
var bytes = new byte [stream.Length];
await stream.ReadAsync(bytes, 0, (int)stream.Length);
string base64 = System.Convert.ToBase64String(bytes);
I found it here
Image is just a control in Xamarin forms to display the image.
It is not something from which you can get your image byte array out.
You will be better of using the Media Plugin and save it to disk. Then load it via memory stream and convert.
You can also use FFImageLoading. It has 2 methods which can be of use for you :
GetImageAsJpgAsync(int quality = 90, int desiredWidth = 0, int desiredHeight = 0)
GetImageAsPngAsync(int desiredWidth = 0, int desiredHeight = 0)
The SO question - Convert Image into byte array in Xamarin.Forms shows how to do it in Platform specific code here.
The forum thread (Convert Image to byte[]) has a good discussion on why you can't get it from the control.
You can do this as below as well
var base64String = Convert.ToBase64String(File.ReadAllBytes(file.Path))
I'm trying to create a script for Photoshop, but all my text gets the same size. I've created a small test script that shows my problem. Both layers get the same text size, and the size doesn't make sense.
var DPI = 300
$.writeln(DPI + " DPI **********************************");
//UnitValue.baseUnit = UnitValue(1/DPI, "in");
//$.writeln("baseUnit: " + UnitValue.baseUnit);
doc = app.documents.add(
200,
287,
DPI,
"Test");
var layer = doc.artLayers.add();
layer.kind = LayerKind.TEXT;
layer.textItem.font = "PalatinoLinotype-Roman";
layer.textItem.size = new UnitValue(3, "mm");
$.writeln("textItem.size: " + layer.textItem.size + " (" + layer.textItem.size.baseUnit + ")");
var layer2 = doc.artLayers.add();
layer2.kind = LayerKind.TEXT;
layer2.textItem.font = "PalatinoLinotype-Roman";
layer2.textItem.size = new UnitValue(120, "px");
$.writeln("textItem.size: " + layer2.textItem.size + " (" + layer2.textItem.size.baseUnit + ")");
This is what it looks like when I run it in the ExtendScript Toolkit:
I'm new to this, so am I missing something obvious?
I'm using Fingerprint to upload and then print image with pcx format.
Step1 Upload image to printer using TCP port, I use command :
IMAGE LOAD "bigfoot.1",1746,""\r\n
The printer returns with message "OK".
And then I send bytes data of bigfoot.1 to printer using socket.
Step 2 Print the image "bigfoot.1":
PRPOS 200,200
DIR 3
ALIGN 5
PRIMAGE "bigfoot.1"
PRINTFEED
RUN
The problem comes, the printer returns with message "Image not found". So I come up with the possibility of failure of upload. So I open the software PrintSet4 to check the image, the image already exists in TMP.Odd!!!
At last, I used PrintSet4 to substitute my socket application to upload image, After add file and apply, I use the step2 print command to print image, It works fine!
Here is the C# code to upload Image:
public void SendFile(string filePath, string CR_LF)
{
FileInfo fi = new FileInfo(filePath);
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
byte[] byteFile = new byte[fs.Length];
string cmd = "IMAGE LOAD \"" + fi.Name + "\"," + byteFile.Length.ToString() + ",\" \"" + CR_LF;
ClientSocket.Send(encode.GetBytes(cmd));
fs.Read(byteFile, 0, byteFile.Length);
Thread.Sleep(1000);
ClientSocket.Send(byteFile);
}
}
I have modified your code and used serial port.
public void SendFile(string filePath)
{
SerialPort port = new SerialPort("COM3", 38400, Parity.None, 8, StopBits.One);
port.Open();
FileInfo fi = new FileInfo(filePath);
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
byte[] byteFile = new byte[fs.Length];
// string cmd = "IMAGE LOAD \"" + fi.Name + "\"," + teFile.Length.ToString()+ ",\"\"" + CR_LF;
string cmd = "IMAGE LOAD " + "\"" + fi.Name + "\"" + "," + byteFile.Length.ToString() + "," + "\"S\"";
port.WriteLine(cmd);
fs.Read(byteFile, 0, byteFile.Length);
port.Write(byteFile,0,byteFile.Count());
int count = byteFile.Count();
int length = byteFile.Length;
}
}
So I noticed the problem was using CR_LF. Instead, I used port.WriteLine(cmd), which acts the same as adding a line separator. And it worked fine.