Hi !
I'm working with a lot of different labelprinters. Some of them are quite picky about how they
receive data. Especially one of them needs to receive one graphic file at a time.
In this case, I've made special files for each graphic containing instruction for the labelprinter
along with the graphic in binary format. These files are stored as embedded resources in a library
that I made (DLL). It works well, but I suspect that there must be smarter ways to do this in order
to speed up the transfer.
Part of the code follows below. Any suggestions are greatly appreciated !
TIA
Kai Bohli
Norway
<snip>
public void TransferGraphicsToLabelPrinter(string NameOfPrinter)
{
using (Stream input = Assembly.GetExecutingAssembly().GetManifestResourc eStream(
"ProTeria.Transport.LabelPrintLib.Grafikk.Zebra284 4.betalning.txt") )
{
long length = input.Length;
WriteMemoryStreamToPort(input,length,NameOfPrinter );
}
using (Stream input = Assembly.GetExecutingAssembly().GetManifestResourc eStream(
"ProTeria.Transport.LabelPrintLib.Grafikk.Zebra284 4.vekt1.txt") )
{
long length = input.Length;
WriteMemoryStreamToPort(input,length,NameOfPrinter );
}
....
....
and so on
....
....
/// <summary>
/// WriteMemoryStreamToPort
/// Purpose: Writes the stream directly to the printerport. Use for Graphics only
/// </summary>
/// <param name="input"></param>
/// <param name="length"></param>
private void WriteMemoryStreamToPort(Stream input, long length, string nameOfPrinter)
{
using (MemoryStream output = new MemoryStream())
{
byte[] buffer = new byte[length];
int read;
while ( (read=input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
output.Flush();
output.Position = 0;
LabelPrintHelper.SendDocToPrinter(nameOfPrinter,ou tput);
}
}
</snip>
Best wishes
Kai Bohli
ka***********@online.no
Norway