0

I have following code.In which when I click on 'print map' button then popup window gets open on which there are two buttons 'save' and 'print'. when I click on 'save' button it opens window to save file.

What I want is when I click on 'print map' button then window after clicking save button should open.

function PrintElem(elem)
{
    Popup($(elem).html());
}
function Popup(data) 
{
    var mywindow = window.open('', 'parent', 'height=400,width=600');
    mywindow.document.write('<html><head><title>my div</title>');
    /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);
    mywindow.document.write('</body></html>');
    mywindow.document.close(); // necessary for IE >= 10
    mywindow.focus(); // necessary for IE >= 10
    mywindow.print();
    mywindow.close();
    return true;
}
<script src="http://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://html2canvas.hertzen.com/build/html2canvas.js"></script>
<body>
    <section>
        <div class="main_div">
            <div>
                <div class="nav_div">
                    <input type="button" value="Print Map"  onclick="PrintElem('.parent')" />
                </div>          
            </div>  
            <div class="parent">    
                    <h1>Hello All</h1>  
            </div>
        </div>
    </section>
</body>
             
Mohit Tanwani
  • 6,608
  • 2
  • 14
  • 32
Roma
  • 272
  • 1
  • 12
  • What did you try so far ? The only thing I see here is a copy/ paste from http://stackoverflow.com/a/2255438/5703316 – Quentin Roger Aug 24 '16 at 06:55
  • Please read my question...code is jst for demo..I dont want preview window coming on click of button but want to save the pdf – Roma Aug 24 '16 at 06:58

1 Answers1

0

Could you not just add the download link as html on your save button - Can't really see the save button here - but if you have the directory, and it is always the same file - you can anchor the save button like this.

<a href="./directory/yourfile.pdf" download="newfilename">Save</a>

This will save the file with suggested name "newfilename" you can also emit that though, and have the sever name of the pdf be used:

<a href="./directory/yourfile.pdf" download>Save</a>

It is a HTML5 feature, and is not supported in old IE, but it could be a suggestion.

Hope that it solves what you are looking to do, but i might have misunderstood.

Stender
  • 2,446
  • 1
  • 14
  • 22