I'm creating an FPDI PDF. This is what I do now:
libraries_load('fpdi');
$pdf = new FPDI();
$path = drupal_get_path('theme', 'xmed') . '/docs/verkocht_template.pdf';
$pdf->setSourceFile(realpath($path));
$tplIdx = $pdf->importPage(1, '/MediaBox');
$pdf->addPage();
$pdf->useTemplate($tplIdx, 0, 0, 210);
$path = drupal_get_path('theme', 'xmed') . '/fonts/lato.php';
$pdf->AddFont('lato-light-webfont','','lato-light-webfont.php');
$pdf->SetFont('lato-light-webfont', '', 14);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetXY(47, 71);
$pdf->Write(0, $name);
I'm also placing some other variables on my PDF. This is the result now:
But as you can see the $name variable is to long... . I've tried this:
$naam = wordwrap($naam, 20);
But that gave me this result:
What would be the best solution to fix this?
Simply use MultiCell() instead of Write(). It allows you to define a width (1st parameter) on which the text will be wrapped automatically.
Related
$path = Yii::app()->basePath;
require_once($path . '/extensions/tcpdf/tcpdf.php');
$pdf = new TCPDF();
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(true);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->AddPage();
$pdf->SetLineWidth(0.1);
$pdf->SetFont('times', '', 10);
$pdf->SetMargins(20, 20, 20, true);
$footer_image_file = Yii::app()->request->baseUrl.'/images/logo.jpg';
$content = '<div> $content </div>';
$pdf->writeHTML($content, true, false, true, false, '');
ob_end_clean();
$pdf->Output("Reports.pdf", "D");
I want to add image in fooder for every new pages.. please anyone help me...
Simply put the code displaying the image within the Footer() base method. This base method is called for any new page by either the AddPage() method and Close().
Important : The Footer method should not be called directly.
This method is supposed to be implemented in your class, so override it like this :
function Footer()
{
.... /* Put your code here (see a working example below) */
$logoX = 186; // 186mm. The logo will be displayed on the right side close to the border of the page
$logoFileName = "/images/myLogo.jpg";
$logoWidth = 15; // 15mm
$logo = $this->PageNo() . ' | '. $this->Image($logoFileName, $logoX, $this->GetY()+2, $logoWidth);
$this->SetX($this->w - $this->documentRightMargin - $logoWidth); // documentRightMargin = 18
$this->Cell(10,10, $logo, 0, 0, 'R');
}
I hope this helps and I've well understood your question.
function Footer()
{
.... /* Put your code here (see a working example below) */
$logoX = 40; //
$logoFileName = "/images/myLogo.jpg";
$logoWidth = 130; // 15mm
$logoY = 280;
$logo = $this->PageNo() . ' | '. $this->Image($logoFileName, $logoX, $logoY, $logoWidth);
$this->SetX($this->w - $this->documentRightMargin - $logoWidth); // documentRightMargin = 18
$this->Cell(10,10, $logo, 0, 0, 'C');
}
This codes are perfectly placed a image in the center of page footer.Thanks a lot pti_jul.:-)))))
What setting would I need to change and to what in order for the rendered PDF file to be exactly 11 in. by 8.5 in.? Right now, for some reason the PDF I generate is 11.69 in. by 8.27 in. .
The code above is the only thing that works at producing a PDF, I've tried "new FPDF" instead of "new FPDI" and all I get are errors. How can I alter this code to be 11x8.5?
<?php
ob_clean();
ini_set("session.auto_start", 0);
define('FPDF_FONTPATH','font/');
define('FPDI_FONTPATH','font/');
require('fpdf.php');
require('fpdi.php');
$pdf = new FPDI();
$pdf->setSourceFile("Flyer.pdf");
$tplIdx = $pdf->importPage(1);
$specs = $pdf->getTemplateSize($tplIdx);
$pdf->addPage($specs['h'] > $specs['w'] ? 'P' : 'L');
$pdf->useTemplate($tplIdx, 0, 0, 297, 210);
$pdf->SetFont('helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
$pdf->Write(0, 'This is just a simple text');
ob_end_clean();
$pdf->Output('marketing.pdf', 'F');
?>
11.69 x 8.27 inches is A4 size used by default by FPDF (the documentation says: Default value is A4.)
11 x 8.5 inches is the Letter paper size so you should just set it as a parameter for the constructor:
$pdf = new FPDF('P','inch','Letter');
I have on server the image. I want to make a watermark (text) on image and save this image as a new with other name. My function is:
function watermark($path, $watermark){
$imageURL = $path;
list($width,$height) = getimagesize($imageURL);
$imageProperties = imagecreatetruecolor($width, $height);
$targetLayer = imagecreatefromjpeg($imageURL);
imagecopyresampled($imageProperties, $targetLayer, 0, 0, 0, 0, $width, $height, $width, $height);
$WaterMarkText = $watermark;
$watermarkColor = imagecolorallocate($imageProperties, 191,191,191);
imagestring($imageProperties, 5, 130, 117, $WaterMarkText, $watermarkColor);
imagejpeg ($imageProperties);
imagedestroy($targetLayer);
imagedestroy($imageProperties);
}
where parameters are:
$watermark = $_POST['watermark'];
$path = "/images/$file_name";
When I start the scypt, the image with watermark is creating and displays on screen. My aim is to not display the new image but save in the same folder with name: $file_name_watermark. How can i do this?
From the docs on imagejpeg():
filename
The path to save the file to. If not set or NULL, the raw image stream
will be outputted directly.
So:
imagejpeg ($imageProperties, 'some/path.jpg');
PDFBOX / JSF
Im trying to change the font height of a given text. I know how to change the fontsize only.
PDPageContentStream contentStreambc = new PDPageContentStream(doc1, page, true, true);
contentStreambc.setFont( fonta, 16 );
contentStreambc.beginText();
contentStreambc.moveTextPositionByAmount(200, 320);
contentStreambc.drawString( "abcdef");
contentStreambc.endText();
contentStreambc.close();
The code works fine. But How I change the font height ?
thanks in advance stack members.
If you need something like this
you can create it with this code:
PDRectangle rec = new PDRectangle(220, 70);
PDDocument document = null;
document = new PDDocument();
PDPage page = new PDPage(rec);
document.addPage(page);
PDPageContentStream content = new PDPageContentStream(document, page, true, true);
content.beginText();
content.moveTextPositionByAmount(7, 55);
content.setFont(PDType1Font.HELVETICA, 12);
content.drawString("Normal text (size 12)");
content.setTextMatrix(1, 0, 0, 1.5f, 7, 30);
content.drawString("Stretched text (size 12, factor 1.5)");
content.setTextMatrix(1, 0, 0, 2f, 7, 5);
content.drawString("Stretched text (size 12, factor 2)");
content.endText();
content.close();
document.save("SimplePdfStretchedText.pdf");
The code stretches the text by setting the text matrix accordingly; for details cf. chapter 9 of the PDF specification ISO 32000-1.
PS: As you mention bar codes in a comment to another answer, this should indeed allow you to make higher bar codes while keeping the distances.
I am well aware that google offers as part of their chart api dynamic marker icons for google maps here:
https://developers.google.com/chart/image/docs/gallery/dynamic_icons
There is just only one small problem, the whole API seems to be deprecated. Plus I would really like to have more variety because not all of the icons offer the same flexibility.
So I found this webpage:
http://mapicons.nicolasmollet.com/numbers-letters/numbers/?style=classic
The icons look nice but they are not dynamic and well my client doesn't seem to like em. So is there a differenct webpage or some other sort of service which offers neat dynamic icons?
Doesn't have to be for google maps. Can be for any purpose just be suitable for maps as well :-)
Thank you in advance!
OK, I did a project some time ago that does exactly this but its independent of google maps, even though I used it to create dynamic map markers. Here is the whole php function:
<?php
function createImage($number, $color) {
$blank = "/var/www/rbc/dashboard/images/".$color."-0.png";
//$image = #imagecreatefrompng($blank);
$image = LoadPNG($blank);
// pick color for the text
$fontcolor = imagecolorallocate($image, 255, 255, 255);
$font = 2;
$fontsize = 8;
$width = imagefontwidth($font) * strlen($number) ;
$height = imagefontheight($font) ;
$x = (imagesx($image) - $width) / 2;
$y = 5;
//white background
$backgroundColor = imagecolorallocate ($image, 255, 255, 255);
//white text
$textColor = imagecolorallocate($image, 255, 255, 255);
// preserves the transparency
imagesavealpha($image, true);
imagealphablending($image, false);
imagestring($image, $font, $x, $y, $number, $textColor);
// tell the browser that the content is an image
header('Content-type: image/png');
// output image to the browser
imagepng($image);
// delete the image resource
imagedestroy($image);
}
function LoadPNG($imgname) {
/* Attempt to open */
$im = imagecreatefrompng($imgname);
/* See if it failed */
if(!$im) {
/* Create a blank image */
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
if(!isset($_GET['color'])) {
$_GET['color'] = "blue";
}
if(!isset($_GET['number'])) {
$_GET['number'] = "99";
}
createImage($_GET['number'], $_GET['color']);
?>
which you show with <img src="image.php?color=red&number=2" />
HTH