Board index » cppbuilder » Re: Printing - Escape Sequence

Re: Printing - Escape Sequence


2005-02-16 09:20:19 PM
cppbuilder77
Thomas J. wrote:
Quote
I tried to send escape sequences to the printer,
With wich intention ? To control the printer ?
Quote
but obviously it is not
possible to put a esacpe sequnce into the method Canvas->TextOut(.,...,
"Line1\nLine2");
Prntr->Canvas->TextOut(200, 600, "Hallo 1 \n and");
You can put it in and will get a nice graphic for it.
Ahh... you just want to start a new line. Well that is
done by a new call to TextOut with the right X,Y parameter.
Hans.
 
 

Re:Re: Printing - Escape Sequence

The intention is the following:
I want to print labels on a label printer. And the aim should be to print a
Label A and a Label B. After each second Label the cutter should cut. I
assumes taht each label is a page. So I called NewPage(). But the printer
will create a new job for each call of NewPage and for each new job the
cutter willl work. So Label A and Label B are not together anymore. (I want
to print 300 labels).
The label printer company told me to send the esacep sequence F which is
0x00c a form feed. And thats what I try to do for hours and hours.
I found out that another way it is possible to send escape sequnces. But
this is workig without Canvas and acomponent which I'm using fpr printing
Barcode needs a Canvas.
So with the first snippet it is possible to send escape sequence but I
cannot use because of the barcode.
The second snippet force no form feed
----------------------------------------------------------------------------
------------------
1.
OpenPrinter(printername, &PrnHandle, NULL);
if (PrnHandle != NULL) {
DOC_INFO_1 DocInfo;
DocInfo.pDocName = "SessionName";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = "RAW";
if (StartDocPrinter(PrnHandle,1,(LPSTR)&DocInfo) <= 0)
Application->MessageBox("StartDocPrinter", "Error", MB_OK);
else if (StartPagePrinter(PrnHandle) <= 0)
Application->MessageBox("StartPagePrinter", "Error", MB_OK);
else if (!WritePrinter(PrnHandle,Help,strlen(Help),&size))
Application->MessageBox("WritePrinter", "Error", MB_OK);
if (!EndPagePrinter(PrnHandle))
Application->MessageBox("EndpagePrinter", "Error", MB_OK);
else if(!EndDocPrinter(PrnHandle))
Application->MessageBox("EndDoc", "Error", MB_OK);
printer->EndDoc();
ClosePrinter(PrnHandle);
} else {
Application->MessageBox("Cannot find printer", "Error", MB_OK);
}
----------------------------------------------------------------------------
------------------
2.
char Help[1024];
sprintf(Help, "\x00c");
TPrinter* printer = Printer();
printer->BeginDoc();
printer->Canvas->TextOut(300, 300, "First page");
Escape(printer->Canvas->Handle,
PASSTHROUGH,
sizeof(Help),
Help,
NULL);
printer->Canvas->TextOut(400, 400, "Next page");
printer->EndDoc();
Thanks fr your help
"Hans Galema" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Thomas J. wrote:

>I tried to send escape sequences to the printer,

With wich intention ? To control the printer ?

>but obviously it is not
>possible to put a esacpe sequnce into the method Canvas->TextOut(.,...,
>"Line1\nLine2");

>Prntr->Canvas->TextOut(200, 600, "Hallo 1 \n and");

You can put it in and will get a nice graphic for it.

Ahh... you just want to start a new line. Well that is
done by a new call to TextOut with the right X,Y parameter.

Hans.
 

Re:Re: Printing - Escape Sequence

Thomas J. wrote:
Quote
I want to print labels on a label printer.
On what kind of paper ?
Quote
And the aim should be to print a
Label A and a Label B. After each second Label the cutter should cut.
So not endless with labels glued on it ?
Quote
I
assumes taht each label is a page. So I called NewPage().
But then I would assume that every two labels constitute a page.
Quote
But the printer
will create a new job for each call of NewPage
No it will not make a new job. Just start on a new page.
Quote
and for each new job the
cutter willl work. So Label A and Label B are not together anymore. (I want
to print 300 labels).
The label printer company told me to send the esacep sequence F which is
0x00c a form feed. And thats what I try to do for hours and hours.
If you want to send an escape sequence than you have to use
the printer in raw mode. As far as I know you cannot use TPrinter()
for that. A formfeed for TPrinter() is NewPage().
Quote
I found out that another way it is possible to send escape sequnces.
Forget about escape sequences. Use TextOut(X,Y, ...) to make new lines
and use NewPage() as formfeed.
Quote
OpenPrinter(printername, &PrnHandle, NULL);
if (PrnHandle != NULL) {
if (StartDocPrinter(PrnHandle,1,(LPSTR)&DocInfo) <= 0)
Application->MessageBox("StartDocPrinter", "Error", MB_OK);
printer->EndDoc();
Here you mixed the raw printer with TPrinter(). That seems a
bad idea to me.
Quote
TPrinter* printer = Printer();
printer->BeginDoc();
printer->Canvas->TextOut(300, 300, "First page");
Escape(printer->Canvas->Handle,
You did not show what function Escape() does.
Hans.
 

{smallsort}

Re:Re: Printing - Escape Sequence

Hans Galema wrote:
Quote
Forget about escape sequences. Use TextOut(X,Y, ...) to make new lines
and use NewPage() as formfeed.
For NewPage() to work correctly you need to assign the right paperformat
for the printer. (Under windows itself).
Hans.
 

Re:Re: Printing - Escape Sequence

The paperformat is 9cm to 7,5cm. The labels are "endless". On one role are
1000 labels.
The size of the paper (label) is set correct and I if I debug I get the
correct dimension of the labe in pixel.
One customer wants to have 2 lables together the next customers needs 4
label together. So each label represnets a page.
Unfortunately NewPage force the printer to create a new job. This I can see
on the display of the printer. But of course only one job you can see in
"windows printer job window". I'm sure that is a bug in the driver of the
printern and I will again the company why the hell NewPage force a new
job ->cutter will cut.
Quote
A formfeed for TPrinter() is NewPage().
Thats what I think too. But then the escape sequence will also not the
solution and the answer form the printer support team is wrong.
Quote
Forget about escape sequences. Use TextOut(X,Y, ...) to make new lines
and use NewPage() as formfeed.
That would great if that will not force the cutter. The problem that in one
process you have to print 100 item each item with 2 or 3 label.
One solution is to destroy the cutter and cut by self - but 300 labels -
forget it.
The next solution will be that the stupid cutter cut EACH label and someone
has to tabe up each pair.
Quote
Here you mixed the raw printer with TPrinter(). That seems a
bad idea to me.
That bad idea is also not working ;)
"Hans Galema" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Thomas J. wrote:

>I want to print labels on a label printer.

On what kind of paper ?

>And the aim should be to print a
>Label A and a Label B. After each second Label the cutter should cut.

So not endless with labels glued on it ?

>I
>assumes taht each label is a page. So I called NewPage().

But then I would assume that every two labels constitute a page.

>But the printer
>will create a new job for each call of NewPage

No it will not make a new job. Just start on a new page.

>and for each new job the
>cutter willl work. So Label A and Label B are not together anymore. (I
want
>to print 300 labels).
>The label printer company told me to send the esacep sequence F which is
>0x00c a form feed. And thats what I try to do for hours and hours.

If you want to send an escape sequence than you have to use
the printer in raw mode. As far as I know you cannot use TPrinter()
for that. A formfeed for TPrinter() is NewPage().

>I found out that another way it is possible to send escape sequnces.

Forget about escape sequences. Use TextOut(X,Y, ...) to make new lines
and use NewPage() as formfeed.


>OpenPrinter(printername, &PrnHandle, NULL);
>if (PrnHandle != NULL) {

>if (StartDocPrinter(PrnHandle,1,(LPSTR)&DocInfo) <= 0)
>Application->MessageBox("StartDocPrinter", "Error", MB_OK);

>printer->EndDoc();


Here you mixed the raw printer with TPrinter(). That seems a
bad idea to me.


>TPrinter* printer = Printer();
>printer->BeginDoc();
>printer->Canvas->TextOut(300, 300, "First page");
>Escape(printer->Canvas->Handle,

You did not show what function Escape() does.

Hans.
 

Re:Re: Printing - Escape Sequence

Thomas J. wrote:
Quote
The paperformat is 9cm to 7,5cm. The labels are "endless". On one role are
1000 labels.
Sorry but my imagination fails to see what kind of paper that
is. It is a pitty that you did not answer my specific questions
concernig the type of paper used. Now I still don't know
how that paper looks like. I'm used to paper that is endless
with labels glued on them. Then the labels have dimensions
like X cm x Y cm.
Quote
Unfortunately NewPage force the printer to create a new job. This I can see
on the display of the printer. But of course only one job you can see in
"windows printer job window". I'm sure that is a bug in the driver of the
printern and I will again the company why the hell NewPage force a new
job ->cutter will cut.
Then what is the problem ? I would not care for a new job. If NewPage()
forces a cut then it be so. Just print two or three or for
labels and then do a NewPage().
Or are there others drawbacks from 'a new job' which you did not mention?
Please trim quotes when replying.
Hans.
 

Re:Re: Printing - Escape Sequence

I tested this. In the first case the windows printer job queue shows a
document with two pages, but in the second case only one page is shown in
the queue. The result is the same. Two pages were printed.
These means that Form Feed ist not the same as NewPage at least not for the
Windows printer queue and maybe also not for the label printer.
TPrinter* printer = Printer();
printer->BeginDoc();
printer->Canvas->TextOut(300, 300, "First page");
printer->NewPage();
printer->Canvas->TextOut(400, 400, "Second page");
printer->EndDoc();
and with escape sequence
if (PrnHandle != NULL) {
DOC_INFO_1 DocInfo;
DocInfo.pDocName = "SessionName";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = "RAW";
if (StartDocPrinter(PrnHandle,1,(LPSTR)&DocInfo) <= 0)
Application->MessageBox("StartDocPrinter", "Error", MB_OK);
else if (StartPagePrinter(PrnHandle) <= 0)
Application->MessageBox("StartPagePrinter", "Error", MB_OK);
else {
char page1[100];
sprintf(page1, "First page\n");
if (!WritePrinter(PrnHandle,page1,strlen(page1),&size)) {
Application->MessageBox("WritePrinter", "Error", MB_OK);
} else {
WritePrinter(PrnHandle,Help,strlen(Help),&size);
sprintf(page1, "Second page\n");
WritePrinter(PrnHandle,page1,strlen(page1),&size);
}
}
if (!EndPagePrinter(PrnHandle))
Application->MessageBox("EndpagePrinter", "Error", MB_OK);
else if(!EndDocPrinter(PrnHandle))
Application->MessageBox("EndDoc", "Error", MB_OK);
ClosePrinter(PrnHandle);
} else {
Application->MessageBox("Drucker nicht gefunden", "Error", MB_OK);
}
"Thomas J." < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
The paperformat is 9cm to 7,5cm. The labels are "endless". On one role are
1000 labels.
The size of the paper (label) is set correct and I if I debug I get the
correct dimension of the labe in pixel.

One customer wants to have 2 lables together the next customers needs 4
label together. So each label represnets a page.

Unfortunately NewPage force the printer to create a new job. This I can
see
on the display of the printer. But of course only one job you can see in
"windows printer job window". I'm sure that is a bug in the driver of the
printern and I will again the company why the hell NewPage force a new
job ->cutter will cut.

>A formfeed for TPrinter() is NewPage().

Thats what I think too. But then the escape sequence will also not the
solution and the answer form the printer support team is wrong.

>Forget about escape sequences. Use TextOut(X,Y, ...) to make new lines
>and use NewPage() as formfeed.

That would great if that will not force the cutter. The problem that in
one
process you have to print 100 item each item with 2 or 3 label.
One solution is to destroy the cutter and cut by self - but 300 labels -
forget it.
The next solution will be that the stupid cutter cut EACH label and
someone
has to tabe up each pair.

>Here you mixed the raw printer with TPrinter(). That seems a
>bad idea to me.

That bad idea is also not working ;)

"Hans Galema" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
news:421357d5$ XXXX@XXXXX.COM ...
>Thomas J. wrote:
>
>>I want to print labels on a label printer.
>
>On what kind of paper ?
>
>>And the aim should be to print a
>>Label A and a Label B. After each second Label the cutter should cut.
>
>So not endless with labels glued on it ?
>
>>I
>>assumes taht each label is a page. So I called NewPage().
>
>But then I would assume that every two labels constitute a page.
>
>>But the printer
>>will create a new job for each call of NewPage
>
>No it will not make a new job. Just start on a new page.
>
>>and for each new job the
>>cutter willl work. So Label A and Label B are not together anymore. (I
want
>>to print 300 labels).
>>The label printer company told me to send the esacep sequence F which
is
>>0x00c a form feed. And thats what I try to do for hours and hours.
>
>If you want to send an escape sequence than you have to use
>the printer in raw mode. As far as I know you cannot use TPrinter()
>for that. A formfeed for TPrinter() is NewPage().
>
>>I found out that another way it is possible to send escape sequnces.
>
>Forget about escape sequences. Use TextOut(X,Y, ...) to make new lines
>and use NewPage() as formfeed.
>
>
>>OpenPrinter(printername, &PrnHandle, NULL);
>>if (PrnHandle != NULL) {
>
>>if (StartDocPrinter(PrnHandle,1,(LPSTR)&DocInfo) <= 0)
>>Application->MessageBox("StartDocPrinter", "Error", MB_OK);
>
>>printer->EndDoc();
>
>
>Here you mixed the raw printer with TPrinter(). That seems a
>bad idea to me.
>
>
>>TPrinter* printer = Printer();
>>printer->BeginDoc();
>>printer->Canvas->TextOut(300, 300, "First page");
>>Escape(printer->Canvas->Handle,
>
>You did not show what function Escape() does.
>
>Hans.


 

Re:Re: Printing - Escape Sequence

Yes this kind of labels I use too. Endless paper ad labels glued on this
endless paper., sorry.
"Hans Galema" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Thomas J. wrote:
>The paperformat is 9cm to 7,5cm. The labels are "endless". On one role
are
>1000 labels.

Sorry but my imagination fails to see what kind of paper that
is. It is a pitty that you did not answer my specific questions
concernig the type of paper used. Now I still don't know
how that paper looks like. I'm used to paper that is endless
with labels glued on them. Then the labels have dimensions
like X cm x Y cm.

>Unfortunately NewPage force the printer to create a new job. This I can
see
>on the display of the printer. But of course only one job you can see in
>"windows printer job window". I'm sure that is a bug in the driver of
the
>printern and I will again the company why the hell NewPage force a new
>job ->cutter will cut.

Then what is the problem ? I would not care for a new job. If NewPage()
forces a cut then it be so. Just print two or three or for
labels and then do a NewPage().

Or are there others drawbacks from 'a new job' which you did not mention?

Please trim quotes when replying.

Hans.
 

Re:Re: Printing - Escape Sequence

Thomas J. wrote:
Quote
The result is the same. Two pages were printed.
What do you consider /two pages/ using endless paper ?
Quote
These means that Form Feed ist not the same as NewPage at least not for the
Windows printer queue and maybe also not for the label printer.
But what is your problem then when the result is the same ?
Please trim quotes. (this means: dont send back all text that
is written here. Just some specific sentences.).
Hans.
 

Re:Re: Printing - Escape Sequence

Quote
What do you consider /two pages/ using endless paper ?
I considered that in both cases is written in the printer job queue 2 pages.
Because we assumed that Form Feed is the same like NewPage and this is not
the same. That means that I have to send a escape sequence to the printer.
(I will test in the evening)
FYI I'm testing now not with a label printer. (This one is located home)
But the problem is not linked to a label printer. Because I'm also not able
to send text, form feed sequence and again text to a printer using TPrinter.
And that's my problem.
Quote
But what is your problem then when the result is the same ?
I can only use the TPrinter due to the Barcode which needs a Canvas but this
soultion works right now only with NewPage which will force the cutter to
cut what is wrong.
The last test was only to find out if NewPage and sending a Escape Sequnce
(Form Feed) is the same.
So my only solution can be to find a way to send a Escape Sequence which is
working in the context of TPrinter.
 

Re:Re: Printing - Escape Sequence

Thomas J. wrote:
Quote
>What do you consider /two pages/ using endless paper ?

I considered that in both cases is written in the printer job queue 2 pages.
Sorry but I'm not asking for a printer job queue but interested
in the actual dimensions of where the endless paper is cut or
how many cm's the paper is forwarded with every NewPage().
You should configure -under windows- the printerdriver
in such a way that for every NewPage() the paper is forwarded
2 or 4 labels. Which ever you want.
Realise that using /endless paper/ you have to define yourself
what should be taken as /a page/.
Hans.
 

Re:Re: Printing - Escape Sequence

Thomas, please take a look at this again.
It is probably the way you need to do it.
Hans might not have made himself clear to you.
Quote
Hans Galema wrote:

>Forget about escape sequences. Use TextOut(X,Y, ...) to make new lines
>and use NewPage() as formfeed.
This is just off the top of my head, and is semi-psudo code, so look
at it and try to understand what Hans was trying to say.
PrintSomeLabels( int LabelsPerPage)
{
int LabelNumber = 0;
do{ PrintLabel( LabelNumber );
}while( ++LabelNumber < LabelsPerPage );
NewPage(); /* cut the paper */
}
PrintLabel( int LabelNumber )
{ TextOut( X , (LabelNumber*LabelHeight)+Y , ... );
}
An alternate method:
int LabelNumber = 0;
GetData();
while( !DataEof )
{ PrintLabel( LabelNumber );
if( ++LabelNumber>= LabelsPerPage )
{ NewPage();
LabelNumber = 0;
};
GetData();
};
 

Re:Re: Printing - Escape Sequence

Thanks a lot but my english is not well enough.
You both are right, but my answer regarding the kind of label was "wrong". I
checked it in the evening the wording of the printer and the the label are
not endless in this context.
This means between each label is gap see "image" below or use the link. And
the cutter has to cut exact between the gap. And the customers are using
different labels with different size of gap and therfor eI cannot your
solution. But anyway - thanks for your help!!
www.avery-zweckform.com/de1/main.jsp
| |
| ______________ |
| | Label1.1 | |
| |______________| |
| ______________ |
| | Label 1.2 | |
| |______________| |
| ______________ |
| | Label 2.1 | |
| |______________| |
| ______________ |
| | Label 2.2 | |
| |______________| |
 

Re:Re: Printing - Escape Sequence

Thomas J. wrote:
Quote
You both are right, but my answer regarding the kind of label was "wrong". I
checked it in the evening the wording of the printer and the the label are
not endless in this context.
This means between each label is gap see "image" below or use the link.
Yes that is exactly the kind of endless label paper that I had in mind.
I use exactly the same. The only difference is that I do not cut the
paper. The customer just takes the labels from the paper.
Quote
And
the cutter has to cut exact between the gap. And the customers are using
different labels with different size of gap and therfor eI cannot your
solution.
Of course you can use my solution. Everything holds.
You should just print 1, 2, 3 or four labels. Position the text
with TextOut. Now when you do a NewPage() and thereby force the
printer to cut, then the customer has to have adjusted the printerdriver
to the /length of paper/. It is the responsability of the customer
to define the pagelength.
Hans.
 

Re:Re: Printing - Escape Sequence

Hans Galema wrote:
Quote
Thomas J. wrote:

>You both are right, but my answer regarding the kind of label was
>"wrong". I
>checked it in the evening the wording of the printer and the the label
>are
>not endless in this context.
>This means between each label is gap see "image" below or use the link.


Yes that is exactly the kind of endless label paper that I had in mind.
I use exactly the same. The only difference is that I do not cut the
paper. The customer just takes the labels from the paper.

>And
>the cutter has to cut exact between the gap. And the customers are using
>different labels with different size of gap and therfor eI cannot your
>solution.


Of course you can use my solution. Everything holds.
You should just print 1, 2, 3 or four labels. Position the text
with TextOut. Now when you do a NewPage() and thereby force the
printer to cut, then the customer has to have adjusted the printerdriver
to the /length of paper/. It is the responsability of the customer
to define the pagelength.

Hans.
What you should do is just execute (your) following code:
TPrinter* printer = Printer();
printer->BeginDoc();
printer->Canvas->TextOut(300, 300, "First page");
printer->NewPage();
printer->Canvas->TextOut(300, 300, "Second page");
printer->NewPage();
printer->Canvas->TextOut(300, 300, "Third page");
printer->EndDoc();
Now adjust the printerdriver -under windows itself- in
such a way that the page has such a length that there
will be cut after 1,2,3 or how many you like, labels.
Or just do a BeginDoc()/EndDoc() for every cut.
Once you have this ready then you can add the code for
printing the labels themself.
Hans.