Introduction
The PDF Writer is a great utility. And to realise that such a great application is here lying on CodeProject absolutely free of cost is amazing. The original author has done a great job. But when I tried putting all the pieces together there were a lot of issues. So once I managed to get the PDFWriter working for me I thought of putting all the stuff back here so that other people can get it done in one step.
Using the code
I have basically used the same code for achieving the PDF Writer. The previous application was an MFC based Windows application and contained a lot of MFC code for generating windows and dialogs. I removed all the code and converted it into a Console Application and also migrated it to a Console Application.
bool AddVirtualPrinter()
{
bool resultstep1= AddMonitor();
if(resultstep1==false)
{
std::cout<<"Addition of monitor process failed.\n";
}
else
{
std::cout<<"Addition of monitor Succeeded.\n";
}
bool resultstep2=AddPort();
if(resultstep2==false)
{
std::cout<<"Addition of Port failed.\n";
return false;
}
else
{
std::cout<<"Addition of port Succeeded.\n";
}
bool resultstep3=CopyPrintDriverFiles2System() && AddPrinterDriver();
if(resultstep3==false)
{
std::cout<<"Addition of Printer Driver failed.\n";
return false;
}
else
{
std::cout<<"Addition of Printer Driver Succeeded\n";
}
bool resultstep4=AddPrinter() && UpdateRegInfo();
if(resultstep4==false)
{
std::cout<<"Addition of Printer failed.\n";
return false;
}
else
{
std::cout<<"Addition of Printer Succeeded\n";
}
return true;
}
bool RemoveVirtualPrinter()
{
bool step5result=DeletePrinter() && DeleteRegInfo();
if(step5result==false)
{
std::cout<<"Removal of Printer failed.\n";
return false;
}
else{
std::cout<<"Printer Removed Successfully\n";
}
bool step6result=DeletePrinterDriver();
if(step6result==false)
{
std::cout<<"Removal of Printer Driver failed.\n";
return false;
}
else{
std::cout<<"Printer Driver Removed Successfully\n";
}
HWND hWnd;
bool step7result=DeletePort(hWnd);
if(step7result==false)
{
std::cout<<"Removal of Port failed.\n";
return false;
}
else{
std::cout<<"Port Removed Successfully\n";
}
bool step8result=DeleteMonitor() ;
if(step8result==false)
{
std::cout<<"Removal of Monitor failed.\n";
return false;
}
else{
std::cout<<"Port Monitor Removed Successfully\n";
}
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
std::cout<<" \n1. Press 1 to Install the PDFWriter.\n2. " +
"Press 2 To Uninstall The PDFWriter.\nEnter a Choice";
int i=0;
std::cin>>i;
if(i==1){
bool addresult=AddVirtualPrinter();
if(addresult==true)
{
std::cout<<"PDF Writer Installed Successfully";
}
else{
std::cout<<"There was an error installing PDF Writer, Please Try Again";
}
}
if(i==2)
{
RemoveVirtualPrinter();
}
std::cin>>i;
return 0;
}
I hope you find my contribution useful. This is all the previous author's work so all credit to him. I have just tried to make it simpler.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.