[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Generate PDF From FPDF PHP

Posted on 2009-12-18
14
Medium Priority
?
618 Views
Last Modified: 2013-12-12
here is my code i need to input my details how can i insert data from database values in heading and content..
<?php
session_start();
if(!isset($_SESSION['user_id'])) {
header("Location: index.php");
exit();
}

include ('../../includes/dbc.php');
$query="select * from contents where state='1' and (publish_down >= '".date('Y-m-d')."' and publish_up <= '".date('Y-m-d')."') and id='".$_GET['id']."'";
$dataset=mysql_query($query)or die(mysql_error());
$dsRow=mysql_fetch_array($dataset);
?>
<?
require('../fpdf.php');
class PDF extends FPDF
{
//Page header
function Header()
{
      //Logo
      $this->Image('logo.gif',10,8,20);
      //Arial bold 15
      $this->SetFont('Arial','B',15);
      //Move to the right
      $this->Cell(80);
      //Title
      $this->Cell(30,10,Put the title from database?'',0,0,'C');
      //Line break
      $this->Ln(20);
}

//Page footer
function Footer()
{
      //Position at 1.5 cm from bottom
      $this->SetY(-15);
      //Arial italic 8
      $this->SetFont('Arial','I',8);
      //Page number
      $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

//Instanciation of inherited class
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
$pdf->Cell(0,10,'Put the code from database?',0,1);
$pdf->Output();
?>
0
Comment
Question by:anilpotter
  • 6
  • 5
  • 2
13 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 26079493
Hi,

just use the values from database in :

$pdf->Cell(0,10,$dsRow->value,0,1);

0
 
LVL 14

Expert Comment

by:shobinsun
ID: 26079499
$pdf->Cell(0,10,$dsRow['value'],0,1);

Use this.
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 26079558
hi,

<?php
      class InvoicePDF extends FPDF
      {
            var $arrContent;
   
     function print()
{
            $this->Cell(30,5,$this-> arrContent,1,0,'L');
}


       }


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:Insoftservice
ID: 26079566
hi,

srry,

hi,

<?php
      class InvoicePDF extends FPDF
      {
            var $arrContent;
   
     function print()
{
            $this->Cell(30,5,$this-> arrContent,1,0,'L');
}

function set($arrContent)
{
 $this-> arrContent = $arrContent;
}

       }

I am providing you such complex because u can use this a general class for any part of ur any code

0
 

Author Comment

by:anilpotter
ID: 26079640
$pdf->Cell(0,10,$dsRow['value'],0,1); this code prints the text but my text goes out of scope
value contains html formatted output
like
<p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam nibh. Nunc varius facilisis eros. Sed erat. In in velit <br />
      <br />
      quis arcu ornare laoreet. Curabitur adipiscing luctus massa. Integer ut purus ac augue commodo commodo. Nunc nec mi eu <br />
      <br />
      justo tempor consectetuer. Etiam vitae nisl. In dignissim lacus ut ante. Cras elit lectus, bibendum a, adipiscing <br />
      <br />
      vitae, commodo et, dui. Ut tincidunt tortor. Donec nonummy, enim in lacinia pulvinar, velit tellus scelerisque augue, <br />
      <br />
      ac posuere libero urna eget neque. Cras ipsum. Vestibulum pretium, lectus nec venenatis volutpat, purus lectus <br />
      <br />
      ultrices risus, a condimentum risus mi et quam. Pellentesque auctor fringilla neque. Duis eu massa ut lorem iaculis <br />
      <br />
      vestibulum. Maecenas facilisis elit sed justo. Quisque volutpat malesuada velit. <br />
      <br />
      Nunc at velit quis lectus nonummy eleifend. Curabitur eros. Aenean ligula dolor, gravida auctor, auctor et, suscipit <br />
      <br />
      in, erat. Sed malesuada, enim ut congue pharetra, massa elit convallis pede, ornare scelerisque libero neque ut neque. <br />
      <br />
      In at libero. Curabitur molestie. Sed vel neque. Proin et dolor ac ipsum elementum malesuada. Praesent id orci. Donec <br />
      <br />
      hendrerit. In hac habitasse platea dictumst. Aenean sit amet arcu a turpis posuere pretium. </p>
0
 

Author Comment

by:anilpotter
ID: 26079783
i have html formated output how can i manage these things
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 26079858
hi,

fpdf depends on cell .
So you have to do it cell wise and not like html. if u want to display such o/p use "r&os " for it.

for each line u have to use different code given above
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 26079878
hi,

$this->SetFont('Times','B',10);
                        $this->Cell(0,6,"ONunc at velit quis lectus nonummy eleifend. Curabitur eros. Aenean ligula dolor, gravida auctor, auctor et, suscipit  ",0,0,'L');
                        $this->Ln(5);
                        $this->Cell(0,6,"tIn at libero. Curabitur molestie. Sed vel neque. Proin et dolor ac ipsum elementum malesuada. Praesent id orci. Donec,",0,0,'L');
                        $this->Ln(5);
                        $this->Cell(0,6,"Curabitur molestie. Sed vel neque. Proin et dolor ac ipsum elementum malesuada. Praesent id orci. Donec .",0,0,'L');

nearly similar code
0
 

Author Comment

by:anilpotter
ID: 26079994
sorry i can't understand how to loop the text because the text is formated output like html tags.. li,ul,p
$html=$dsRow->fulltext;

$pdf->Cell(0,10,$html,0,1); how can i process...
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 26080227
hi,
 its very tedious job. if u have only html to be publish . i will suggest  "R&OS"
0
 

Author Comment

by:anilpotter
ID: 26080319
i use this script
http://www.fpdf.org/en/tutorial/tuto4.htm
i write the wholeout put in the txt file and this works fine except from tags please send me the link that convert this into html
this is the main code
$f=fopen($file,'r');
    $txt=fread($f,filesize($file));
    fclose($f);
    //Times 12
    $this->SetFont('Times','',12);
    //Output justified text
    $this->MultiCell(0,5,$txt);
    //Line break
    $this->Ln();
    //Mention in italics
    $this->SetFont('','I');
    $this->Cell(0,5,'(end of excerpt)');
but is there any way and tell me what is R&OS
0
 

Author Comment

by:anilpotter
ID: 26080471
http://www.ros.co.nz/pdf/

if i type </p>Hello</p> it gives me the same output
0
 

Accepted Solution

by:
anilpotter earned 0 total points
ID: 26080883
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month18 days, 4 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question