Results 1 to 6 of 6

Thread: submit div content to html2pdf page

  1. #1
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default submit div content to html2pdf page

    I'm Needing to submit div content from one page to my html2pdf conversions page. I was wanting to do this using jquery so I do not have to leave my home page to make downloadable PDF file. I found an online example but I can not seem to make it work right. Any help with this project would be appreciated greatly. Here's the code I found. I just want to pass my div content so I can create a downloadable PDF file. I don't need any error message return link this script contains. Thanks



    home.php

    Code:
    <! DOCTYPE>
    <html>
    <head>
    <title></ title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    src="js/jquery-1.9.1.min.js" <script type="text/javascript"> </ script>
    <script type="text/javascript">
    $ (Document). Ready (function () {
    $ ("#exportentry"). Click (function (e) {
    e.preventDefault ();
    if (submitted) {
    var data = $ ("#container"). html ();
    var filename = "Entry_Report.pdf";
    $. Ajax ({
    type: "POST",
    url: "convert.php",
    data: {data: data, filename: filename}
    dataType: "json",
    success: function (data) {
    alert ('success');
    }
    })
    Else {}
    alert ("No Report To Export");
    }
    });
    });
    </ Script>
    
    </ Head>
    <body>
    <div id="container">
    <center> <h3> Nations and Flags </ h3> </ center>
    <table border="1" width="500" cellspacing="0" cellpadding="2" align="center">
    <tr> <td> <% = Request.QueryString ("v")%> India </ td> <td width="200"> <img src = "imag / in-t.jpg" width = "48" height = "32"> </ td> </ tr>
    <tr> <td> <% = Request.QueryString ("v2")%> Australia </ td> <td width="200"> <img src = "imag / as-t.jpg" width = "48" height = "32"> </ td> </ tr>
    <tr> <td> Canada </ td> <td width="200"> <img src="imag/ca-t.jpg" width="48" height="32px" </ td> </ tr >
    <tr> <td> China </ td> <td width="200"> <img src="imag/ch-t.jpg" width="48" height="32px" </ td> </ tr >
    <tr> <td> Germany </ td> <td width="200"> <img src="imag/de-t.jpg" width="48" height="32px" </ td> </ tr >
    <tr> <td> France </ td> <td width="200"> <img src="imag/fr-t.jpg" width="48" height="32px" </ td> </ tr >
    <tr> <td> United Kingdom </ td> <td width="200"> <img src="imag/uk-t.jpg" width="48" height="32px" </ td> </ tr>
    <tr> <td> United States of America </ td> <td width="200"> <img src="imag/us-t.jpg" width="48" height="32px" </ td> </ tr>
    </ Table>
    
    <table border="0" width="500" cellspacing="0" cellpadding="2" align="center">
    <tr> <td align="center"> <a href = " http://www.scriptarticle.com "target =" _blank "> http://www.scriptarticle.com </ a> </ td> < / tr>
    </ Table>
    </ Div>
    <form method="post" id="exportentry" action="home.php">
    <input type="submit" value="Create PDF">
    </ Form>
    </ Body>
    </ Html>


    convert.php

    Code:
    <? Php
    
    require ('html2fpdf.php');
    
    if (isset ($ _POST ['data'])) {
    Urlcontents $ = $ _POST ['data'];
    $ Filename = $ _POST ['filename'];
    $ Date = $ _POST ['date'];
    convert ($ urlcontents, $ filename, $ date);
    }
    
    function convert ($ contents, $ name, $ currdate) {
    $ Pdf = new HTML2FPDF ();
    $ Pdf-> AddPage ();
    $ Pdf-> SetFont ('Arial', 'B', 16);
    $ Pdf-> Cell (40.10, "Report Entry");
    $ Pdf-> SetFont ('Arial','', 12);
    $ Pdf-> Cell (90.12, '-'. $ Currdate);
    $ Content = strip_tags ($ contents, '<html> <body> <meta> <img> <h2> <h4> <div> <ul> <li> <span>');
    $ Pdf-> Sety (20);
    $ Pdf-> WriteHTML ($ contents);
    $ Content = $ pdf-> Output ('', true);
    $ File = fopen ($ filename, "D");
    fwrite ($ file, $ content);
    fclose ($ file);
    }
    ?>
    Last edited by djr33; 03-30-2013 at 01:27 AM. Reason: fix [/code] tags

  2. #2
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    your website is on what script ? maybe you can use any ready plugin

    look for something like ready html2pdf api

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    The jQuery code you have in your post has capital letters in a number of places where lower case must be used, and the external script tag for jquery is wrong. The src attribute needs to be in the opening <script . . . part of the tag. Using jQuery 1.9+ could present problems as it dropped a number of commonly supported commands from previous versions.

    There are also some unnecessary spaces and other capital letters in the script code and in HTML, some or none of which might be a problem. And I question the need for json as a data type (might be good, but could be a problem). The submitted variable is undefined, so the ajax code would never fire. The form should execute on submit, not on click. The DOCTYPE is invalid as is some of the HTML, even for quirks mode.

    Taking all of that together, and correcting two syntax errors in the jQuery code, I've updated the code and HTML for your sending page:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
    <script type="text/javascript">
    jQuery(function($){ //document ready
    	$("#exportentry").submit(function(e){
    		e.preventDefault();
    		var data = $("#container").html();
    		var filename = "Entry_Report.pdf";
    		if(data){
    			$.ajax({
    				type: "POST",
    				url: "convert.php",
    				data: {data: data, filename: filename, date: document.lastModified},
    				dataType: "json", //try it without this if there's still a problem
    				success: function(data){
    					alert('success'); //to stop the success alert, remove or comment out this line
    				}
    			});
    		}
    		else {alert("No Report To Export");}
    	});
    });
    </script>
    
    </head>
    <body>
    <div id="container">
    <center> <h3> Nations and Flags </h3> </center>
    <table border="1" width="500" cellspacing="0" cellpadding="2" align="center">
    <tr> <td> <?php echo isset($_GET['v'])? $_GET['v'] : ''; ?> India </td> <td width="200"> <img src="images/in-t.png" width="48" height="32"> </td> </tr>
    <tr> <td> <?php echo isset($_GET['v2'])? $_GET['v2'] : ''; ?> Australia </td> <td width="200"> <img src="imag/as-t.jpg" width="48" height="32"> </td> </tr>
    <tr> <td> Canada </td> <td width="200"> <img src="imag/ca-t.jpg" width="48" height="32"> </td> </tr>
    <tr> <td> China </td> <td width="200"> <img src="imag/ch-t.jpg" width="48" height="32"> </td> </tr>
    <tr> <td> Germany </td> <td width="200"> <img src="imag/de-t.jpg" width="48" height="32"> </td> </tr>
    <tr> <td> France </td> <td width="200"> <img src="imag/fr-t.jpg" width="48" height="32"> </td> </tr>
    <tr> <td> United Kingdom </td> <td width="200"> <img src="imag/uk-t.jpg" width="48" height="32"> </td> </tr>
    <tr> <td> United States of America </td> <td width="200"> <img src="imag/us-t.jpg" width="48" height="32"> </td> </tr>
    </table>
    
    <table border="0" width="500" cellspacing="0" cellpadding="2" align="center">
    <tr> <td align="center"> <a href="http://www.scriptarticle.com" target="_blank"> http://www.scriptarticle.com </a> </td> </tr>
    </table>
    </div>
    <form method="post" id="exportentry" action="home.php">
    <input type="submit" value="Create PDF">
    </form>
    </body>
    </html>
    It looks like you have similar problems, at least as far as unnecessary spaces and possibly upper and lower case usage issues as well in the PHP code of the receiving page. But I'm not as well versed in that. Perhaps someone else can clean it up. It could also have syntax errors.

    I will try testing it out though and let you know if I come up with anything.

    I did test it and the convert.php file is a mess. Once fixed, I found that on PHP 5.3+ there were problems with the html2fpdf.php file and its helper file, fpdf.php. These would not be an issue if you are running PHP 4 or PHP < 5.3.

    Here's the updated convert.php file:

    PHP Code:
    <?php

    require ('html2fpdf.php');

    if (isset (
    $_POST['data'])) {
        
    $urlcontents $_POST ['data'];
        
    $filename $_POST ['filename'];
        
    $date = isset ($_POST ['date'])? $_POST ['date']: '5/25/92';
        
    convert ($urlcontents$filename$date);
    }

    function 
    convert ($contents$name$currdate) {
        
    $pdf = new HTML2FPDF ();
        
    $pdf-> AddPage ();
        
    $pdf-> SetFont ('Arial''B'14);
        
    $pdf-> Cell (12010"Report Entry - $currdate");
        
    $pdf-> SetFont ('Arial',''12);
        
    $pdf-> Sety (20);
        
    $pdf-> WriteHTML ($contents);
        
    $pdf-> Output ($name'F');
    }
    ?>
    I used the html2fpdf.php file and its helper files from here:

    http://sourceforge.net/projects/html2fpdf/

    That's version 3.0.2b (listed on the download page, version 3.0(beta) listed in the file itself) - If you have another version, results could vary. And like I say, if you have PHP 5.3 or greater, the html2fpdf.php file and its helper file, fpdf.php need a little editing - let me know.
    Last edited by jscheuer1; 04-06-2013 at 02:57 AM. Reason: ran code, found other issues, fine tuned things
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Wait a minute - Do you even have PHP? These:

    Quote Originally Posted by keithboesker View Post
    Code:
    <tr> <td> <% = Request.QueryString ("v")%> India </ td> <td width="200"> <img src = "imag / in-t.jpg" width = "48" height = "32"> </ td> </ tr>
    <tr> <td> <% = Request.QueryString ("v2")%> Australia </ td> <td width="200"> <img src = "imag / as-t.jpg" width = "48" height = "32"> </ td> </ tr>
    imply that your server is asp based. Is it?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Apr 2012
    Posts
    81
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Instade of using html2PDF use mPDF.
    mPDF provide large variety of functions like background image, borders, fonts, etc..
    Check the demo examples at http://www.olivettorestaurante.com.br/mpdf/examples. It might be helpful to you.

  6. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    2,011
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    13

    Default

    round, the website link you provided does not appear to be the source website and its inclusion is very confusing out of context.

    mPDF may indeed prove to be useful but it would be more beneficial to people reading his thread, and more courteous to the developer, to link to the source/developer's website, which is here: http://www.mpdf1.com/mpdf/index.php

    Official documentation is here: http://mpdf1.com/manual/

    And official usage examples are here: http://www.mpdf1.com/mpdf/examples
    Last edited by Beverleyh; 04-11-2013 at 05:33 AM.
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

Similar Threads

  1. hide content on page after form submit
    By shoapin_bajan in forum PHP
    Replies: 1
    Last Post: 12-16-2012, 09:49 PM
  2. Form action Mailto need to open new page on submit and submit email
    By lstammer in forum Looking for such a script or service
    Replies: 0
    Last Post: 12-06-2007, 04:41 PM
  3. Ajax Nested Tabs Content submit page problem
    By SunnyVu in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 10-26-2007, 04:22 PM
  4. Submit to write on a page
    By Demonicman in forum PHP
    Replies: 5
    Last Post: 03-04-2007, 05:39 PM
  5. new reference page on submit
    By micktissue in forum Looking for such a script or service
    Replies: 1
    Last Post: 12-07-2006, 07:32 AM

Bookmarks

Posting Permissions

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