Click here to Skip to main content
Click here to Skip to main content
Alternative Article

PDF Writer

, 26 Apr 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

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)

Share

About the Author

Navraj

Unknown
No Biography provided

Comments and Discussions

 
GeneralMy vote of 2 Pinmemberenhzflep12-Oct-13 14:24 
GeneralMy vote of 2 PinmemberxComaWhitex26-Apr-12 13:30 
GeneralRe: My vote of 2 PinmemberxComaWhitex27-Apr-12 14:02 
GeneralRe: My vote of 2 Pinmembercarpe diem12-Jun-12 1:12 
GeneralRe: My vote of 2 PinmemberxComaWhitex12-Jun-12 1:13 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 26 Apr 2012
Article Copyright 2012 by Navraj
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid