Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I need to stop ejecting paper till dotted line after printing the data using dot matrix printer LX300+ II.
I have used below code.

C++
CPrintDialog dlgPrint(FALSE,PD_ALLPAGES,this);
dlgPrint.GetDefaults();
CDC dcPrint;
dcPrint.Attach(dlgPrint.GetPrinterDC());

//** Create and fill a DOCINFO structure
DOCINFO myPrintJob;
myPrintJob.cbSize=sizeof(myPrintJob);
myPrintJob.fwType=NULL;
myPrintJob.lpszDatatype=NULL;
myPrintJob.lpszDocName="MyPrintJob";
myPrintJob.lpszOutput=NULL;

//** Start the Printing document
if (dcPrint.StartDoc(&myPrintJob)>=0)
{
//**Start a page
dcPrint.StartPage();

    dcPrint.TextOut(250,150,"Weighment - Slip");
    dcPrint.TextOut(250,200,"Test data");


//** Throw the page
dcPrint.EndPage();

//** Close the document
dcPrint.EndDoc();
}
//** Delete the printer device context
dcPrint.DeleteDC();


I have tried using page setup.but no success....Kindly suggest.

Regards,

Dipti
P.S: I have searched in the forum but could not find the solution.
Posted
Updated 21-Dec-14 21:50pm
v2

When you call dcPrint.EndPage it sends an end-of-page message to the printer.

If you have other things you want on the same page you need to include the code to print those things before the EndPage is called.
 
Share this answer
 
If you only want to print text using the printer built-in character sets, you can directly write to the printer by opening LPTx with CreateFile and using WriteFile.

This requires that you setup and control the printer using the Epson ESC/P[^] command set.


Then print your text and apply line or page feeds according to your requirements and the paper size.

[UPDATE: Example code]
I have not used ESC/P printing since DOS times. This is untested.
HANDLE hPort = CreateFile(_T("LPT1:"), GENERIC_WRITE, FILE_SHARE_READ, NULL,
     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hPort != INVALID_HANDLE_VALUE) 
{
    char lpszCmd[] = "Test\r\n";
    DWORD dwWritten;
    WriteFile(hPort, lpszCmd, strlen(lpszCmd), &dwWritten, NULL);
    CloseHandle(hPort);
}


[UPDATE 2]
The Windows API provides functions to perform direct printing by opening with the printer's name:
OpenPrinter, WritePrinter, and ClosePrinter.
Just use these instead of the above I/O functions.
 
Share this answer
 
v4
Comments
diptipanchal 22-Dec-14 4:33am    
Kindly share the sample code for opening LTP1 port and send commands.
Jochen Arndt 22-Dec-14 4:44am    
See the updated solution.
diptipanchal 22-Dec-14 5:13am    
Now printer does not eject paper after data is printed.Thanks a lot for the help.
diptipanchal 22-Dec-14 22:47pm    
I could write data in a single line using above code and its working fine without ejecting paper. However, I need to write data in a table format(6 rows and 4 columns). Is it possible with WriteFile?
Jochen Arndt 23-Dec-14 5:44am    
It is possible by printing spaces between the cells and CR-LF (\r\n) pairs between the lines.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900