1

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 don't have to leave my home page to make downloadable PDF file. I found an example online but I can't seem to make it work. Any help with this project would be appreciated greatly. Here's the code I found.

[CODE]
<!DOCTYPE>
<html>
<head>
<title>Nations and Flags</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script src="js/jquery-1.9.1.min.js" 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: "test.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="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 id="exportentry" method="post" action="home.php">
<input type="submit" value="Create PDF">
</form>
</body>
</html>
[/CODE]

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, "Entry Report");
$pdf->SetFont('Arial', '', 12);
$pdf->Cell(90,12,'- '. $currdate);
$contents = strip_tags($contents, '<html><body><meta><img><h2><h4><br><div><ul><li><span>');
$pdf->SetY(20);
$pdf->WriteHTML($contents );
$content = $pdf->Output('', true);
$file = fopen($filename, "w");
fwrite($file, $content);
fclose($file);
}
?>
[/CODE]

2

ajax call cannot download the file directly

on ajax end, append body with an iframe, and set the iframe src as the file url
et la le mec il le pécho par le bras et il lui dit '

3

let me explain what I want to do. I want to use a div tag to create an invoice. I what to send this div tag content to the pdf convertions page to create a download pdf file. I would like for this to run in the background if possible.

4

$("#generatePdf").click(function(){ var html = $("#mydiv").html(); var name = "hello.pdf"; $.post("generatePdf.php",{data:html,filename:name},function(){ var $iframe = $("<iframe/>").attr("src","/path/to/pdf/folder/"+name).width(0).height(0); $("body").append($iframe); }); }); ?
et la le mec il le pécho par le bras et il lui dit '

5

OK I get my page to work but now I can't get images to show. here's my code

test_home.asp

[code]
<!doctype html>

<!--[if IE 7 ]> <html lang="en" class="ie7 lte8"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="ie8 lte8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="ie9"> <![endif]-->
<!--[if gt IE 9]> <html lang="en"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->

<head>

<meta charset="utf-8">

<title></title>

<!--[if lte IE 9 ]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->

<script src="app_theme/ip_theme/js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/app_applications/plugins/tinymce/jquery.tinymce.js"></script>
<script type="text/javascript">
$().ready(function() {
$('textarea.invoice').tinymce({
// Location of TinyMCE script
script_url : '/app_applications/plugins/tinymce/tiny_mce.js',

// General options
theme : "simple",
convert_urls : false,
plugins : "tabfocus",
width : "300",
height : "150",
force_br_newlines : true,
force_p_newlines : false,
forced_root_block : '',
tab_focus : 'tonguerev,:next'
});
});

$("#pdf").validator();
</script>

</head>
<body>
<form id="pdf" method="post" action="app_applications/plugins/html2pdf/convert.php">
<textarea name="invoice" class="invoice" id="invoice" cols="35" rows="4" tabindex="1">
<div id="container">
<h3>Nations and Flags</h3>
<table border="1" width="500" cellspacing="0" cellpadding="2" align="center">
<tr><td><%=Request.QueryString("v")%> India</td><td width="200"><img src="app_theme/ip_theme/img/logo_2.png"></td></tr>
<tr><td><%=Request.QueryString("v2")%>Australia</td><td width="200"></td></tr>
<tr><td>Canada</td><td width="200"></td></tr>
<tr><td>China</td><td width="200"></td></tr>
<tr><td>Germany</td><td width="200"></td></tr>
<tr><td>France</td><td width="200"></td></tr>
<tr><td>United Kingdom</td><td width="200"></td></tr>
<tr><td>United States of America</td><td width="200"></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>
</textarea>
<input type="text" name="filename" value="" size="20" tabindex="2">
<input type="submit" value="Create PDF" tabindex="3">
</form>
</body>
</html>
[/code]

convert.php

[code]
<?php

$html = $_POST['invoice'];
$filename = $_POST['filename'];

require_once('html2pdf.class.php');
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->writeHTML($html);
$html2pdf->Output("$filename", 'D');
?>
[/code]

I get this error.

Fatal error: Uncaught <span style="color: #AA0000; font-weight: bold;">ERROR n°6</span><br>File : C:\Inetpub\vhosts\invoicingpros.com\httpdocs\app_applications\plugins\html2pdf\html2pdf.class.php<br>Line : 1319<br><br>Impossible to load the image <b>\</b> thrown in C:\Inetpub\vhosts\invoicingpros.com\httpdocs\app_applications\plugins\html2pdf\html2pdf.class.php on line 1319

here's the deduge view script

[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>View HTML</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
</head>
<body style="padding: 10px; font-size: 10pt;font-family: Verdana;">
<div id=\"container\">
<h3>Nations and Flags</h3>
<table width=\"500\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">
<tbody>
<tr>
<td>India</td>
<td width=\"200\"><img src=\"app_theme/ip_theme/img/logo_2.png\" alt=\"\" /></td>
</tr>
<tr>
<td>Australia</td>
<td width=\"200\">&nbsp;</td>
</tr>
<tr>
<td>Canada</td>
<td width=\"200\">&nbsp;</td>
</tr>
<tr>
<td>China</td>
<td width=\"200\">&nbsp;</td>
</tr>
<tr>
<td>Germany</td>
<td width=\"200\">&nbsp;</td>
</tr>
<tr>
<td>France</td>
<td width=\"200\">&nbsp;</td>
</tr>
<tr>
<td>United Kingdom</td>
<td width=\"200\">&nbsp;</td>
</tr>
<tr>
<td>United States of America</td>
<td width=\"200\">&nbsp;</td>
</tr>
</tbody>
</table>
<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">
<tbody>
<tr>
<td align=\"center\"><a href=\"http://www.scriptarticle.com\" target=\"_blank\">http://www.scriptarticle.com</a></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
[/code]

6

if your view string is in ' ' instead of " " php parsing will be faster and you will not nead escape the \"

you are on a windows system, maybe try with \ instead of /

also take care about how the lib search path in relative way, that is from html2pdf class file or from your main file ? just try do some test

if it's not work use absolute path c:\...\...\hello.jpg
et la le mec il le pécho par le bras et il lui dit '

7

can you pass parameters in the include(dirname(__FILE__).'/res/exemple10.php'); say like this include(dirname(__FILE__).'/res/exemple10.php?v=1'); or how can I do this. so I load say invoice.asp?id=0001 which loads the invoice with the correct database info.

8

no, it's a classic php include, it will not execute the script, just include him

but you can do
ob_start(); $_GET['id']=1; include('invoice.php'); $data = ob_end_clean();
et la le mec il le pécho par le bras et il lui dit '

9

is there anyway I can pass this info to an asp page?

ob_start();
$_GET['id']=1;
include('invoice.asp');
$data = ob_end_clean();

10

it's more general php question than html2pdf specific one, how to get data from various source ?

for the asp, without done the http request it's impossible
/?hello=world');simpliest way is$data = file_get_contents('http://ip:port
if it's not work try with contextt); : $context = stream_context_create(array('http'=>array('protocol_version'=>'1.1'))); $data = file_get_contents('http://ip:port/?hello=world', false, $contex
or use cURL
et la le mec il le pécho par le bras et il lui dit '

11

That work. Many Thanks!!!!