FPDF mit JQuery Ajax und Window.open zum Öffnen von PDF auf Klicken auf einen LinkPhp

PHP-Programmierer chatten hier
Anonymous
 FPDF mit JQuery Ajax und Window.open zum Öffnen von PDF auf Klicken auf einen Link

Post by Anonymous »

Ich habe ein Formular, aus diesem Formular verwende ich Jquery Ajax, um die Werte in FPDF zu veröffentlichen, um einen PDF auf dem Server zu speichern. Dann möchte ich, dass der Browser den PDF in einer neuen Registerkarte mit Fenster öffnet. Gibt false zurück .. aber die Datei befindet sich im FTP -Client und ich kann sie herunterladen und lesen.

Code: Select all

jQuery(document).ready(function(){

jQuery('.getPdf').live('click', function(event){

event.preventDefault();

var catId = jQuery(this).attr("id");

jQuery('.removePost').remove();

jQuery.ajax({

type: "POST",

url: "/wp-content/themes/weld-wide/ajax-post-to-pdf.php",

data:jQuery('#form'+catId).serialize(),

success:function(url){

window.open(url, '_blank');

},

});

});
});
< /code>

Unten finden Sie die AJAX -Datei, die die Erstellung des PDF verarbeitet: < /p>

require ('fpdf/fpdf.php');//including the main class

//create FPDF object
$pdf=new FPDF();

//set document properties
$pdf->SetAuthor('Weld Wide');
$pdf->SetTitle('Weld Wide Metal Work');

//set text colour for the entire document
$pdf->SetTextColor(50,60,100);

//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');

//insert an image and make it a link
//$pdf->Image('../images/logo.png',10,20,33,0,' ','http://www.weld-wide.co.uk/');

//display the title with a border around it
$pdf->SetXY(65,20);
//$pdf->SetDrawColor(50,60,100);
//$pdf->Cell(100,10,'FPDF Tutorial',1,0,'C',0);

$pdf->Image('images/logo.png');

//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (10,50);
$pdf->SetFontSize(10);

$pdf->SetFont('Helvetica','B',12);
$pdf->Write(10, "Listed below are your selections for your metal work:\n");

$pdf->SetFont('Helvetica','',10);

foreach($_POST as $k => $v) {

$pdf->Multicell(0,7,str_replace('_',' ',$k)." : ".str_replace('-',' ',$v)."\n");

}

$rand = rand(1,1000000);

//Output the document F means save to server, D for download window popup
$pdf->Output('fpdf/temp_pdf/weld-wide-gate'.$rand.'.pdf','F');

$url = "http://www.".$_SERVER["HTTP_HOST"]."/wp-content/themes/weld-wide/"."fpdf/temp_pdf/weld-wide-gate".$rand.".pdf";

echo $url;

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post