#include
<iostream>// printer print on paper
using
namespace std;
#include
<fstream>
#using
<System.dll>
#using
<System.Windows.Forms.dll>
#using
<System.Drawing.dll>
using
namespace System;
using
namespace System::IO;
using
namespace System::Drawing;
using
namespace System::Drawing::Printing;
using
namespace System::Windows::Forms;
public
refclass PTM{
private
: Font^ printFont; StreamReader^ streamToPrint;
static
String^ filePath;
public
: PTM() { Printing(); }
private
: // The PrintPage event is raised for each page to be printed.
void pd_PrintPage( Object^/*sender*/, PrintPageEventArgs^ ev ) {
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = (float)ev->MarginBounds.Left;
float topMargin = (float)ev->MarginBounds.Top;
String^ line =
nullptr;
// Calculate the number of lines per page.
linesPerPage = ev->MarginBounds.Height /
printFont->GetHeight( ev->Graphics );
// Iterate over the file, printing each line.
while
(count<linesPerPage && ((line=streamToPrint->ReadLine()) !=nullptr)){
yPos = topMargin + (count * printFont->GetHeight( ev->Graphics ));
ev->Graphics->DrawString(line,printFont,Brushes::Black,leftMargin,yPos,
gcnew
StringFormat ); count++; }
// If more lines exist, print another page.
if
(line != nullptr) ev->HasMorePages =true;else
ev->HasMorePages = false;}
public
: // Print the file.
void
Printing() {
try
{ streamToPrint = gcnew StreamReader("Pcs" );
try
{ printFont = gcnew System::Drawing::Font("Times New Roman",12 );
PrintDocument^ pd =
gcnew PrintDocument;
pd->PrintPage +=
gcnew
PrintPageEventHandler(
this, & PTM::pd_PrintPage );
pd-> DefaultPageSettings->Margins->Left = 5 ;
pd-> DefaultPageSettings->Margins->Right = 5 ;
pd-> DefaultPageSettings->Margins->Top = 10 ;
pd-> DefaultPageSettings->Margins->Bottom = 10 ;
pd->Print(); }
// Print the document.
finally
{ streamToPrint->Close(); }
String ^ c =
gcnew String("Pcs");
File::Delete(c); }
catch
( Exception^ ex ) { MessageBox::Show( ex->Message ); }}
static
void Main() {
array<String^>^args = Environment::GetCommandLineArgs();
String^ sampleName = args[ 0 ];
if
( args->Length != 2 ) {
Console::WriteLine(
"Usage: {0} <file path>", sampleName );return; }
filePath = args[ 1 ];
gcnew PTM; }};
int
main(){
ofstream out(
"Pcs");//
printer print on paper, why and how to fix it ?
out<<
""<<""<< ''<<""<< "\233"<<""<< '\233'<<endl;
out.close(); PTM();
cout<<
"\n\n do it a diferent way";
//fstream diferent;
fstream diferent(
"PCS", ios::out | ios::binary);__int8 A2='\233',
A3='';
diferent.write((
char *)&"",sizeof"");
diferent.write((
char *)&A2,sizeof A2);
diferent.write((
char *)&A3,sizeof A3);
diferent.write((
char *)&"\233",sizeof"\233");
diferent.close(); PTM();
cout<<
"Printer print \233 on paper ?";
cout<<
"\n\n"; system("pause");return 0; }