Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: PDF generator

  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PDF generator

    Dear All,

    I am actually working on an Javascript & ASP project which purpose is to generate letters and print them.The generation and printing part is working well.Now I have to add an other option that which include a save button that also allow to save those letters in PDF format in a specific location.Can anyone please help me,to do it via javascript or any else way.Thank you.
    Below is my code:
    -------------------------------------------------------------------
    <head>
    <script type="text/javascript">
    window.onload =function()
    {
    var content = window.opener.LoadLetterinPreview();
    document.getElementById("print").innerHTML=content;

    var url = window.opener.LoadLetterinPreview_url();
    document.getElementById("url").innerHTML=url;
    }
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    }
    <script type="text/javascript">
    document.oncontextmenu = function() { //disable right click button
    return false;
    }
    }
    function GetFrom(which)
    {

    xmlHttp=GetXmlHttpObject();

    if (CheckxmlHttp(xmlHttp)) return;

    var url = "./app_ajax_getassignment_asp.asp?";

    switch(which) //if script will be used to make asynchronous more than one call
    {
    case 1: //Update mapping(missing and complete apps)
    var str = document.getElementById("url").innerHTML;
    str = str.replace(/&amp;/g, "&");
    url += "a=updatemapping&"+str;

    POP=1;
    break;
    }

    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    }

    function stateChanged()
    {

    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    if(xmlHttp.status == 200){
    Populate(xmlHttp.responseText);
    }
    }
    }

    function Populate(str)
    {
    switch(POP)
    {
    case 1:
    alert("Applications tagged as Printed");
    break;
    }
    }
    function Print(){

    window.print();
    Printed();
    }

    function Printed(){
    if(confirm("Ok - Remove from list.\n\n Cancel - To print again."))
    {
    GetFrom(1);//updatePersonMapping();
    }
    }

    function Close(){
    window.close();
    }
    </script>
    </head>
    <body>
    <div id="div_btn"><p align="center"><input type="button" value="Print" onclick="Print();" />&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" value="Close Window" onclick="Close();"/></p></div>
    <div id="print" style="border:1px red solid; width:650px;"></div>
    <div id="url" style=" display:none;border:1px blue solid;"></div>
    </body>
    </html>
    -----------------------------------------------------------
    Note:
    var content = window.opener.LoadLetterinPreview();
    document.getElementById("print").innerHTML=content;

    The content is the letter which is loaded in the div print (<div id="print" style="border:1px red solid; width:650px;"></div>)

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    JavaScript running in the browser does not have any commands for reading or writing files. JavaScript is a client-side language; modern browsers can read files on the server using an Ajax call, but otherwise JavaScript has no capability to read from, write to or delete a file (except a cookie), communicate with the server, access a database, the client's operating system or the Windows registry, or alter the default behaviour of the browser.

    MSIE can write to files ON THE USER'S COMPUTER (only), but only if the user marks your site as being a "safe" site and only if he/she agrees to let your page run an "unsafe for scripting" ActiveX control.

    So to write data to a file you will need to use server-side scripting.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    deepsan (10-11-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •