I used to make some very simple PDF with this library, FPDF, and now I'm trying to make a "result page" and it have to show something like this image, but with a border surrounding it all, not every cell.
I already got that in FPDF, made will Cells (don't know if it's the best way for doing it), and code goes like this (for the moment I added the results by hand, just to figure out how it will look like):
//SimpleTable
function SimpleTable() {
$this->Cell(280,15,"Inscription Number: 1",0);
$this->Cell(265,15,"Date: 28/03/2008",0);
$this->Ln();
$this->Cell(265,15,"Name and Surname: Name Surname ",0);
$this->Cell(265,15,"",0);
$this->Ln();
$this->Cell(280,15,"Address: Address",0);
$this->Cell(265,15,"",0);
$this->Ln();
$this->Cell(280,15,"Zip Code: Zip Code",0);
$this->Cell(280,15,"City: City",0);
$this->Ln();
$this->Cell(280,15,"Year of birth: Birthday",0);
$this->Cell(280,15,"Age: Age",0);
$this->Ln();
$this->Cell(280,15,"VIP: No - First Time: Yes",0);
$this->Cell(280,15,"School: My school",0);
}
Hope you can help me how to border all thouse results in one, I'm not beign able to do it, and didn't find anything.
Thanks again for your time, as always!!!
You can use
Rect(StartX, StartY, Width, Height, Options)
Options
D - Draw Line
F - Fill
DF or FD - Draw Line and Fill
Example $pdf->Rect(0, 0, 210, 100, 'D');
//The BorderBox
$actual_position_y = $pdf->GetY();
$pdf->SetFillColor(255, 255, 255);
$pdf->SetDrawColor(0, 0, 0);
$pdf->Cell($your_content_width, $your_content_heigth, "", 1, 1, 'C');
//Your actual content
$pdf->SetXY($yourLeftosition, $actual_position_y);
$pdf->Cell($cellwidth, $cellheigth, "Inscription Number", 0, 1, 'C');
Thanks for your time, but I finally found the way to make it. On border option from the cell, I added "LT", "RT"... and I could made a border-line that surrounds all (may not the best way to make it, if you know another and better way to make it, I would appreciate that).
Hope this can help other people that wishes to do the same!
Your should first draw an empty Cell with a border surrounding it, then you can store your Y Position and reset the PDF positions and begin to draw your cells within your border Cell.
Like this:
//The BorderBox
$actual_position_y = $pdf->GetY();
$pdf->SetFillColor(255, 255, 255);
$pdf->SetDrawColor(0, 0, 0);
$pdf->Cell($your_content_width, $your_content_heigth, "", 1, 1, 'C');
//Your actual content
$pdf->SetXY($yourLeftosition, $actual_position_y);
$pdf->Cell($cellwidth, $cellheigth, "Inscription Number", 0, 1, 'C');
...
Hope this helps :)
Use FancyRow plugin of fpdf,to give the border or create the box If you need check the link here, it might help you. and the another plugin you can use here is table with multicell, check this link.
None of the above works.
it can be done with 4th param in cell() method.
4th parameter you can have border as :
L: left
T: top
R: right
B: bottom
You can provide them in any order with comma separate.
So in your case you can have top row with "L,T,R" as 4th parameter like below:
$this->Cell(280,15,"Inscription Number: 1","L,T,R");
$this->Cell(265,15,"Date: 28/03/2008","L,T,R");
And for middle part only "L,R" only
$this->Cell(265,15,"Name and Surname: Name Surname ","L,R");
$this->Cell(265,15,"","L,R");
And bottom one as
$this->Cell(280,15,"VIP: No - First Time: Yes","L,R,B");
$this->Cell(280,15,"School: My school","L,R,B");
Related
May you please help is my first time doing PDF. I want to create a key tags that will fill in the whole PDF so that I can be able to cut them when i print it. I am failing to place a border outside the text to make a square or rectangle. The first three text must be bold the last test not bold.
I want to create something like this:
<?php
$root =realpath($_SERVER['DOCUMENT_ROOT']);
require($root.'/#services/fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->Line(10,10,45,10);
$pdf->Line(10,10,10,25);
$pdf->Line(10,10,45,10);
$pdf->SetFont('Arial','B',8);
$pdf->Write(0.1,"Block E",0,'C');
$pdf->Ln(3);
$pdf->SetFont('Arial','B',8);
$pdf->Write(0.1,"Block / Unit - Area",0,'C');
$pdf->Ln(3);
$pdf->SetFont('Arial','B',8);
$pdf->Write(0.1,"Floor",0,'C');
$pdf->Ln(3);
$pdf->SetFont('Arial','',8);
$pdf->Write(0.1,"Door No. Door No",0,'C');
$pdf->Output();
?>
I have this pdf:
How can I make the page numbering centered instead of right alignment?
This is how I added the page numbering:
include("mpdf60/mpdf.php");
$mpdf=new \mPDF('c','A4','','' , 0, 0, 0, 0, 0, 0);
$mpdf->setFooter('{PAGENO} of {nbpg}');
$mpdf->WriteHTML($body);
$mpdf->Output('Packing Slip.pdf','I');
How can I make it center? its the 'setFooter' ?
Im am using mpdf.
You can set an HTML Footer and give the proper format:
$mpdf->SetHTMLFooter('<div style="text-align: center">{PAGENO} of {nbpg}</div>');
SetHTMLFooter() Function
you can try the following:
$mpdf->setFooter('|{PAGENO} of {nbpg}|');
This will center align the page numbers. Any thing on the left of first | will be left aligned and anything on the right of second | will be right alligned.
I want to print HTML to PDF using TCPDF so I do this:
$html = '<h1>Hello</h1>
How are you?
<h2>Answer</h2>
I am well, thanks';
// ... etc. Long HTML document.
$pdf->writeHTML($html);
The question is if there is a way how to add a table of contents. If TCPDF can recognize page numbers of headings.
I also sometimes use HTML page breaks:
<div style="page-break-after: always"><span style="display:none"> </span></div>
I understand that I need bookmarks. But in this case TCPDF would have to create them automatically. If I add an ID to html-heading-tag, TCPDF probably does not find it and cannot use it.
<h1 id="abc123">header1</h1>
// but following does not do anything:
$pdf->addTOC()
Since the ToC page is created as the very last it will show that as the last page.
So instead use
$this->Cell(0, 12, ' '.$this->getAliasNumPage().' of '.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
//It will show page numbers
Okay i have a site wich makes signatures. But because some header problems i had to put it in another file and use echo. this is the code:
<h1>Create your European Trucking signatures</h1>
<?php
echo '<img src="SigGen.php?player=$Playername&score=$Score&money=$Money" />';
?>
</div>
But it shows a broken image thingy. But when i go to the SigGen.php itself it does show up like here:
http://european-trucking.com/SigGen.php?player_name=Thimo
This is the code of SigGen:
<?
/*
***Made by: Nodroz***
*** Enjoy your signatures! ***
*/
$username="10528_Thimo"; //Your MySQL Username.
$password="*********"; // Your MySQL Pass.
$database="10528_Thimo"; // Your MySQL database.
$host="95.211.***.***"; // Your MySQL host. This is "localhost" or the IP specified by your hosting company.
$player_name=$_GET['player_name']; // This gets the player his name from the previous page.
/* Next, we will make a connection to the mysql.
If it can't connect, it'll print on the screen: Unable to select database. Be sure the databasename exists and online is. */
mysql_connect($host,$username,$password); // Connection to the database.
#mysql_select_db($database) or die( "Unable to select database. Be sure the databasename exists and online is."); //Selection of the database. If it can't read the database, it'll give an error.
/* To protect MySQL injection. */
$player_name = stripslashes($player_name);
$player_name = mysql_real_escape_string($player_name);
$query="SELECT * FROM Users WHERE Name='$player_name'"; // Gets all the information about the player.
$result=mysql_query($query);
$i=mysql_num_rows($result); // Here we are counting how many rows this result gives us.
/* We will now put the player's information into variables so we can use them more easily. */
/* DON'T FORGET: The names should be exact the same as in your mysql db.*/
if ($i == 1) // If the user has been correct, then it'll give us 1 row. If its 1 row, then it'll proceed with the code.
{
$Playername=mysql_result($result,0,"Name"); // Gets the username of the player and put it in the variable $Playername.
$Money=mysql_result($result,0,"Money"); // Gets the money of the player and put it in the variable $Money.
$Score=mysql_result($result,0,"Score"); // Gets the score of the player and put it in the variable $Score.
// Creating of the .png image.
header('Content-Type: image/png;'); // Don't touch this. We use this to tell the script we're working with an image.
$im = #imagecreatefrompng('PlayerSig.png') or die("Cannot select the correct image. Please contact the webmaster."); // Don't forget to put your picture there. Eg: playersig.png
$text_color = imagecolorallocate($im, 000,000,000); // RED, GREEN, BLUE --> Go to www.colorpicker.com, select a nice color, copy the R/G/B letters provided by colorpicker and put them here.
$text_username = "$Playername"; // This gets the information: player name to be showed in the picture.
$text_score = "$Score"; // Same as above but with score.
$text_money = "$Money"; // Same as above but with money.
$font = 'myfont.ttf'; //Upload your custom font to the directory where this file is placed. Then change the name here.
/* USAGE OF THE imagettftext: First ($im) shouldn't be changed. (16) is the text-size. (0) is the angle of your text. Change it, and you'll see what's going on. (20) is de X-coordinate of the text.
(36) is the Y-coordinate of the text. */
imagettftext($im, 16, 0, 5, 20, $text_color, $font, $text_username); // Prints the username in the picture.
imagettftext($im, 16, 0, 5, 40, $text_color, $font, "Score:");
imagettftext($im, 16, 0, 72, 40, $text_color, $font, $text_score); // Prints the score in the picture.
imagettftext($im, 16, 0, 5, 60, $text_color, $font, "Money:");
imagettftext($im, 16, 0, 72, 60, $text_color, $font, $text_money); // Prints the money in the picture.
imagepng($im);
imagedestroy($im);
} else echo('Username is not in our database. Please try again.'); // If the username doesn't exist (so the row is 0) then it'll give en error.
mysql_close();
?>
Anyone knows why it doesnt show up as an image using echo?
i think the problem is that you cant use variable names in string like this :
THIS WONT WORK
echo 'Hi $userName';
THIS WILL WORK
echo "Hi $userName";
so your line :
echo '<img src="SigGen.php?player=$Playername&score=$Score&money=$Money" />';
needs to be changed to :
echo "<img src='SigGen.php?player=$Playername&score=$Score&money=$Money' />";
try this...
<?php echo '<img src="SigGen.php?player='.$Playername.'&score='.$Score.'&money='.$Money.'" />'; ?>
use the concatenation features of the echo to properly append the variables to the image link
I'm trying to spice up my website by using custom fonts for headings. For me, the most appropriate way to do this is using PHP and GD. I have written a little script which will output the dynamic text based on the $_GET value, however sometimes the image is too wide, which moves everything else about.
How can I get the image to adjust the width of it, based on the width of the text? Here is the code I've written so far:
<?php
// Settings
$sText = $_GET['t']; // Text of heading
$sFont = "font/AvantGarde-Book.ttf"; // Default font for headings
$sMain = $_GET['c'] ? $_GET['c'] : 0xF2AB27; // Get a font or default it
// Create the image
header("content-type: image/png"); // Set the content-type
$hImage = imagecreatetruecolor(200, 24);
ImageFill($hImage, 0, 0, IMG_COLOR_TRANSPARENT);
imagesavealpha($hImage, true);
imagealphablending($hImage, false);
imagettftext($hImage, 20, 0, 0, 24, $sMain, $sFont, $sText); // Draw the text
imagepng($hImage); // Generate the image
imagedestroy($hImage); // Destroy it from the cache ?>
Thanks!
Ok, I figured it out! For anyone else who may have this problem, you need to add:
// Calcuate the width of the image
$arSize = imagettfbbox(24, 0, $sFont, $sText);
$iWidth = abs($arSize[2] - $arSize[0]);
$iHeight = abs($arSize[7] - $arSize[1]);
Before the imagecreatetruecolor()
The function imagettfbbox will calculate the size of what the text will be based on the font you picked. Use the results in your call to imagecreatetruecolor.