Getting PHP variable value into a PDF file -


using following ajax code im sending variable 'a' php file get_output.php:

var a=""; for($i=0;$i<n;$i=$i+1) {    var = (a+'. '+ (document.getelementbyid((values[$i])).innerhtml)); } if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari     xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5     xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() {     if (xmlhttp.readystate==4 && xmlhttp.status==200)     {         document.getelementbyid("output_container").innerhtml=xmlhttp.responsetext;     } } xmlhttp.open("post","get_output.php?q="+a,true); xmlhttp.send(); 

in get_output.php following code present:

<html> <head> </head> <body>     <?php         $value=$_get["q"];         echo $value;     ?> </body> </html> 

here getting output wanted in variable 'value'. want put variable 'value' content pdf file. when researched in google found solutions getting complete page pdf file using 'url',etc.

all want content present in variable 'value' should come pdf file. thank you.

you can using tcpdf.tcpdf php class generating pdf documents.download it, , modify $html variable in tcpdf/pdfgenerator/examples/example_001.php file as:

// set content print $html = <<<eod <div> $value </div>       eod; 

or create new file(say test.php) in /tcpdf/pdfgenerator/examples/ folder.copy paste following code new file, created:

<?php require_once('../config/lang/eng.php'); require_once('../tcpdf.php'); $pdf = new tcpdf(pdf_page_orientation, pdf_unit, pdf_page_format, true, 'utf-8', false);      $value=$_get["q"];/*the value want print*/  // set document information $pdf->setcreator(pdf_creator); $pdf->setauthor('nicola asuni'); $pdf->settitle('tcpdf example 001'); $pdf->setsubject('tcpdf tutorial'); $pdf->setkeywords('tcpdf, pdf, example, test, guide');  $pdf->setheaderdata(pdf_header_logo, pdf_header_logo_width, '','', array(0,64,255), array(0,64,128)); $pdf->setfooterdata($tc=array(0,64,0), $lc=array(0,64,128));  // set header , footer fonts $pdf->setheaderfont(array(pdf_font_name_main, '', pdf_font_size_main)); $pdf->setfooterfont(array(pdf_font_name_data, '', pdf_font_size_data));  // set default monospaced font $pdf->setdefaultmonospacedfont(pdf_font_monospaced);  //set margins $pdf->setmargins(pdf_margin_left, pdf_margin_top, pdf_margin_right); $pdf->setheadermargin(pdf_margin_header); $pdf->setfootermargin(pdf_margin_footer);  //set auto page breaks $pdf->setautopagebreak(true, pdf_margin_bottom);  //set image scale factor $pdf->setimagescale(pdf_image_scale_ratio);  //set language-dependent strings $pdf->setlanguagearray($l);   // set default font subsetting mode $pdf->setfontsubsetting(true);  // set font // dejavusans utf-8 unicode font, if need // print standard ascii chars, can use core fonts // helvetica or times reduce file size. $pdf->setfont('times', '', 11, '', true);  // add page // method has several options, check source code documentation more information. $pdf->addpage();  // set text shadow effect $pdf->settextshadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'normal'));  // set content print $html = <<<eod <div> $value </div>    eod;  // print text using writehtmlcell() $pdf->writehtmlcell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);  // ---------------------------------------------------------  // close , output pdf document // method has several options, check source code documentation more information. $pdf->output("generatedpdf.pdf", 'f'); //============================================================+ // end of file //============================================================+ ?> 

when run it, new pdf file generated in tcpdf/pdfgenerator/examples/generatedpdf.pdf contains value in $value php variable.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -