Printing PCX image

P

Peter Morris

Hi all

I am trying to print a B&W PCX image to a Zebra RW420 file. The printer
uses the CPCL language, the help file says....

Input 1 (STARTPCX.LBL):
! 0 200 200 500 1
PCX 0 30
Input 2 (IMAGE.PCX)
Input 3 (ENDPCX.LBL)
FORM
PRINT




What I interpret as this

! 0 200 200 500 1
PCX 0 30 {binary data}
FORM
PRINT

or

! 0 200 200 500 1
PCX 0 30
{binary data}
FORM
PRINT


Neither of these are working. I have tried sending the binary data directly
as ASCII.GetBytes, and also tried reading each byte and converting it to an
ASCII HEX format 00-FF.

Does anyone have any experience with this? The guy on the support desk
seems to think this is enough, but it is just doing nothing at all! Any
help appreciated.

PS: I cannot use a file reference in the PCX, I must embed the file data
into the string because I am storing it away in a DB and printing it later
so I only have access to a string.


private void button1_Click(object sender, EventArgs e)
{
StringBuilder data = new StringBuilder();
data.Append("! 0 200 200 500 1\r\n");
data.Append("PCX 0 30 ");
data.Append(HexEncodedPCXData("/SDMMC DISK/x.pcx") + "\r\n");
data.Append("FORM\r\n");
data.Append("PRINT\r\n");
byte[] binary =
System.Text.ASCIIEncoding.ASCII.GetBytes(data.ToString());

//Output the file just so I can see what it is sending
FileStream fs = new FileStream("/SDMMC Disk/output.bin",
FileMode.Create);
fs.Write(binary, 0, binary.Length);
fs.Close();

ZebraPrintCtlClass zebraPrinter = new ZebraPrintCtlClass();
try
{
zebraPrinter.SerialConnection(string.Format("COM{0}:", 6), 19200);
zebraPrinter.Open();
zebraPrinter.Print(data.ToString());
}
finally
{
zebraPrinter.Close();
}
}


private string HexEncodedPCXData(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read,
FileShare.None);
byte[] buffer = new byte[fs.Length];
BinaryReader reader = new BinaryReader(fs);
using (reader)
reader.Read(buffer, 0, (int)fs.Length);
string result = System.Text.ASCIIEncoding.ASCII.GetString(buffer, 0,
buffer.Length);
return result;
}
 
G

Ginny Caughey [MVP]

Peter,

I haven't tried printing an image although I have worked with Zebra
printers. My *guess* is that you will need to create a temp file for the
image and pass that to the printer, then delete it. I think those printers
expect a carriage return and line feed after each line, and you may need to
Sleep() some milliseconds after each line of data sent to the printer. For
this reason, I'd suggest writing each line to the serial port separately
rather than all at once. You may also need to delay closing the serial port
to the printer for some little bit to ensure that all the data is sent. One
last suggestion - for testing also print some normal Hello world text before
and after the image to make sure you're getting anything printed.

HTH,

--
Ginny Caughey
Device Application Development MVP


Peter Morris said:
Hi all

I am trying to print a B&W PCX image to a Zebra RW420 file. The printer
uses the CPCL language, the help file says....

Input 1 (STARTPCX.LBL):
! 0 200 200 500 1
PCX 0 30
Input 2 (IMAGE.PCX)
Input 3 (ENDPCX.LBL)
FORM
PRINT




What I interpret as this

! 0 200 200 500 1
PCX 0 30 {binary data}
FORM
PRINT

or

! 0 200 200 500 1
PCX 0 30
{binary data}
FORM
PRINT


Neither of these are working. I have tried sending the binary data
directly as ASCII.GetBytes, and also tried reading each byte and
converting it to an ASCII HEX format 00-FF.

Does anyone have any experience with this? The guy on the support desk
seems to think this is enough, but it is just doing nothing at all! Any
help appreciated.

PS: I cannot use a file reference in the PCX, I must embed the file data
into the string because I am storing it away in a DB and printing it later
so I only have access to a string.


private void button1_Click(object sender, EventArgs e)
{
StringBuilder data = new StringBuilder();
data.Append("! 0 200 200 500 1\r\n");
data.Append("PCX 0 30 ");
data.Append(HexEncodedPCXData("/SDMMC DISK/x.pcx") + "\r\n");
data.Append("FORM\r\n");
data.Append("PRINT\r\n");
byte[] binary =
System.Text.ASCIIEncoding.ASCII.GetBytes(data.ToString());

//Output the file just so I can see what it is sending
FileStream fs = new FileStream("/SDMMC Disk/output.bin",
FileMode.Create);
fs.Write(binary, 0, binary.Length);
fs.Close();

ZebraPrintCtlClass zebraPrinter = new ZebraPrintCtlClass();
try
{
zebraPrinter.SerialConnection(string.Format("COM{0}:", 6), 19200);
zebraPrinter.Open();
zebraPrinter.Print(data.ToString());
}
finally
{
zebraPrinter.Close();
}
}


private string HexEncodedPCXData(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read,
FileShare.None);
byte[] buffer = new byte[fs.Length];
BinaryReader reader = new BinaryReader(fs);
using (reader)
reader.Read(buffer, 0, (int)fs.Length);
string result = System.Text.ASCIIEncoding.ASCII.GetString(buffer, 0,
buffer.Length);
return result;
}
 
P

Peter Morris

Hi Ginny

I haven't tried printing an image although I have worked with Zebra
printers. My *guess* is that you will need to create a temp file for the
image and pass that to the printer, then delete it.

Do you mean for the whole print job, or just the image? The problem is that
a business class uses an abstract PrintDoc class to do things like
OutputText("Your signature");
OutputLine();
OutputImage(SomeImage);

The PrintDoc class descendant then generates the bytes required to perform
this print job (in this case a string) and this data is saved to a database.
Later in the day the data is retrieved from the DB and printed in bulk. So
unfortunately I can't reference a file on disk or anything, it only exists
as encoded data within the print job (like a spooler).

Pete
 
G

Ginny Caughey [MVP]

Peter,

I mean just the image. Once you have the encoded data, you can convert it to
a temp file and reference that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top