Click here to Skip to main content
15,884,099 members
Articles / Desktop Programming / MFC
Alternative
Article

PDF Writer

Rate me:
Please Sign up or sign in to vote.
2.81/5 (5 votes)
26 Apr 2012CPOL 22.6K   16   5
This is an alternative for "PDF Writer"

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.

C++
bool AddVirtualPrinter()
{
    bool resultstep1= AddMonitor();
    if(resultstep1==false)
    {
        std::cout<<"Addition of monitor process failed.\n";
    //    return false;
    }
    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.

License

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


Written By
Unknown
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 2 Pin
enhzflep12-Oct-13 13:24
enhzflep12-Oct-13 13:24 
GeneralMy vote of 2 Pin
xComaWhitex26-Apr-12 12:30
xComaWhitex26-Apr-12 12:30 
GeneralRe: My vote of 2 Pin
xComaWhitex27-Apr-12 13:02
xComaWhitex27-Apr-12 13:02 
GeneralRe: My vote of 2 Pin
carpe diem12-Jun-12 0:12
carpe diem12-Jun-12 0:12 
GeneralRe: My vote of 2 Pin
xComaWhitex12-Jun-12 0:13
xComaWhitex12-Jun-12 0:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.