Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working for print an html page using div id. Now I can print and export a html page as .xps format using div id.

When I click the button the page come and I need to give a name then I can save it. So I need two click to save or print this page.

My question is that ...

I want to save this page in any specific location by only one click. Keep in mind that I can use only one click for this button.
Then the page will export as pdf and save in given location of local PC.

Can anyone provide any solution to export html page by one click and save it in a specific location by only one click ?

Here is my sample code:
HTML
<html>
<head>
    <title>Print Test Page</title>
    <link rel="stylesheet" href="PdfPrintingStyleSheet.css" type="text/css" />
    <script>
        printDivCSS = new String('<link href="PdfPrintingStyleSheet.css" rel="stylesheet" type="text/css">')
        function printDiv(divId) {

            window.frames["print_frame"].document.body.innerHTML = printDivCSS + document.getElementById(divId).innerHTML;
            window.frames["print_frame"].window.focus();
            window.frames["print_frame"].window.print();
        }
    </script>
</head>
<body>
    <h1 style="color:red">This is a test page for printing</h1>
    Div 1: <a href="java<!-- no -->script:printDiv('div1')">Print</a><br>
    <div id="div1">This is the div1's print output</div>
    <br><br>
    Div 2: <a href="java<!-- no -->script:printDiv('div2')">Print</a><br>
    <div id="div2" style="color:red">This is the div2's print output</div>
    <br><br>
    Div 3: <a href="java<!-- no -->script:printDiv('div3')">Print</a><br>
    <div id="div3">This is the div3's print output</div>
    <iframe name="print_frame" width="0" height="0" frameborder="0" src="about:blank"></iframe>
</body>
</html>
Posted
Updated 11-Aug-14 22:25pm
v2

1 solution

Here is the link which is already answered in one of CodeProject's Q&A.

Save HTML as PDF

Refer those links and I think it will resolve your problem.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900