Code: Select all
<?php
session_start();
$nick=$_SESSION['username'];
$cat=$_GET['cat'];
$news=$_GET['news'];
$aid=$_GET['aid'];
$time=date("d-m-Y");
if(isset($cat) || isset($news) || isset($aid))
{
if(isset($cat))
{
$xquery="select * from news where status='ON' and category_id='$cat'";
}
elseif(isset($news))
{
$xquery="select * from news where status='ON' and id='$news'";
}
elseif(isset($aid))
{
$xquery="select * from news where status='ON' and writer='$aid'";
}
require 'PDF.php'; // Require the class.
$pdf = &PDF::factory('p', 'a4'); // Set up the pdf object.
$pdf->open(); // Start the document.
$pdf->setCompression(true); // Activate compression.
$pdf->addPage(); // Start a page.
$pdf->setFont('Courier', 'B', 22); // Set font to courier 12 pt.
$pdf->text(200, 100, 'ZeusCMS News PDF'); // Text at x=100 and y=100.
$pdf->setFontSize(20); // Set font size to 20 pt.
$pdf->image('zeuspdf.jpg', 1, 300); // Image at x=100 and y=300.
//$pdf->setFillColor('rgb', 1, 0, 0); // Set text color to red.
$pdf->text(100, 200, "You are reading the News of $time"); // Text at x=100 and y=200.
$pdf->setFont('Arial', 'I', 12);
$pdf->text(100, 250, "This file downloaded by $nick"); // Personalize the PDF
//$pdf->setDrawColor('rgb', 0, 0, 1); // Set draw color to blue.
//$pdf->line(100, 202, 240, 202); // Draw a line.
//$pdf->setFillColor('rgb', 1, 1, 0); // Set fill/text to yellow.
//$pdf->rect(200, 300, 100, 100, 'fd'); // Draw a filled rectangle.
include "db.php";
$pages=1;
$query=mysql_query($xquery);
while($row=mysql_fetch_array($query))
{
$headline=$row['headline']; //get the headline
$intro=$row['intro']; //get the intro
$story=$row['story']; //get the story
$category=$row['category_name'];
$story=wordwrap($story,125,"\n"); //here we wrap the story by 130 chars
$story=explode("\n",$story); //break it into an array
$intro=wordwrap($intro,125,"\n"); //the same as above
$intro=explode("\n",$intro); //break this too
$writer=$row['writer']; //get the author
$pdf->addPage(); // Add a new page.
$pdf->setFont('Arial', 'BI', 9); // Set font to arial bold
// italic 12 pt.
$pdf->text(520, 20, "Page: $pages");
$pages++; //up one page
$pdf->rect(10, 10, 580, 815, 'd'); //draw the borders
$pdf->setFont('Arial', 'BI', 16);
$pdf->setFillColor('rgb', 1, 0, 0); //set color to red
$pdf->text(60, 100, $headline); // Text at x=100 and y=100.
$pdf->setFillColor('rgb', 0, 0, 0); //back to black
$pdf->setFont('Arial', 'BI', 9);
$pdf->text(100, 130, "by $writer");
$pdf->text(50, 170, $intro['0']);
$p=count($intro);
$height=170;
for($a=0;$a<$p;$a++)
{
$pdf->text(50, $height, $intro[$a]);
$height=$height+10;
}
$i=count($story);
$pdf->text(50, 200, $story['0']);
$height=$height+20;
for($j=0;$j<$i;$j++)
{
$pdf->setFont('Arial', 'BI', 9);
$pdf->setFillColor('rgb', 0, 0, 0);
$pdf->text(50, $height, $story[$j]);
$height=$height+10;
if($height==800) //if the end of the page
{
$pdf->addPage(); // Start a new page.
$pdf->setFont('Courier', 'B', 22);
$pdf->setFont('Arial', 'BI', 9);
$pdf->text(520, 20, "Page: $pages"); //type the page number
$pdf->rect(10, 10, 580, 815, 'd');
$height=90;
$pages++; //up one page
}
}
$height=170;
//$pdf->setLineWidth(4); // Set line width to 4 pt.
//$pdf->line(100, 202, 240, 202); // Draw a line.
//$pdf->circle(200, 300, 150, 'd'); // Draw a non-filled
// circle.
}
?>