mPDF auto print issue - php

I'm using a php class, mpdf, which generates PDF's very nicely. I'm trying to get the file to automatically print (i.e., open the print dialog) when rendered. I've extended the core functioning with the code below to add javascript to the pdf. The pdf is rendered but without auto-printing. Any help would be great. Thanks!
require('mpdf.php');
class PDF_JavaScript extends mPDF {
var $javascript;
var $n_js;
function IncludeJS($script) {
$this->javascript=$script;
}
function _putjavascript() {
$this->_newobj();
$this->n_js=$this->n;
$this->_out('<<');
$this->_out('/Names [(EmbeddedJS) '.($this->n+1).' 0 R]');
$this->_out('>>');
$this->_out('endobj');
$this->_newobj();
$this->_out('<<');
$this->_out('/S /JavaScript');
$this->_out('/JS '.$this->_textstring($this->javascript));
$this->_out('>>');
$this->_out('endobj');
}
function _putresources() {
parent::_putresources();
if (!empty($this->javascript)) {
$this->_putjavascript();
}
}
function _putcatalog() {
parent::_putcatalog();
if (!empty($this->javascript)) {
$this->_out('/Names <</JavaScript '.($this->n_js).' 0 R>>');
}
}
}
class PDF_AutoPrint extends PDF_Javascript {
function AutoPrint($dialog=false) { //Embed some JavaScript to show the print dialog or start printing immediately
$param=($dialog ? 'true' : 'false');
$script="print($param);";
$this->IncludeJS($script); } }
$mpdf = new PDF_AutoPrint('', 'Letter', 0, '', 12.7, 12.7, 14, 12.7, 8, 8);
$stylesheet = file_get_contents('eabill.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($message,2);
$mpdf->AutoPrint(true);
$mpdf->Output();

This works for me to print generated PDF file, i used it to print website page contents without menus, banners etc just content with own header and footer
$header = 'Document header';
$html = 'Your document content goes here';
$footer = 'Print date: ' . date('d.m.Y H:i:s') . '<br />Page {PAGENO} of {nb}';
$mpdf = new mPDF('utf-8', 'A4', 0, '', 12, 12, 25, 15, 12, 12);
$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);
$mpdf->SetJS('this.print();');
$mpdf->WriteHTML($html);
$mpdf->Output();

Have you tried (snippet):
class PDF_AutoPrint extends PDF_Javascript {
function AutoPrint($dialog=false) {
//Embed some JavaScript to show the print dialog or start printing immediately
if( $dialog ){
$script="this.print();";
$this->IncludeJS($script);
}
}
Credit: Create an Auto-Print PDF
Or, taking the code from the second example in that article:
require('mpdf.php');
class PDF_AutoPrint extends PDF_Javascript {
function AutoPrint( $dialog=false ){
if( $dialog ){
$this->_newobj();
$this->n_js=$this->n;
$this->_out('<<');
# Not sure whether this line is spot on, may need tweaking
$this->_out('/OpenAction '.($this->n+2).' 0 R/Type/Catalog/Pages 1 0 R/PageMode/UseNone/PageLayout/OneColumn');
$this->_out('>>');
$this->_out('endobj');
$this->_newobj();
$this->_out('<<');
$this->_out('/Type/Action/S/Named/N/Print');
$this->_out('>>');
$this->_out('endobj');
}
}
}
$mpdf = new PDF_AutoPrint('', 'Letter', 0, '', 12.7, 12.7, 14, 12.7, 8, 8);
$stylesheet = file_get_contents('eabill.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($message,2);
$mpdf->AutoPrint(true);
$mpdf->Output();

I use DTukans way + added false as a parameter.
Works in FireFox and IE - did not work for chrome :(
$mpdf->SetJS('this.print(false);');

I wrote this as an external file and requested a print via javascript.
post_to_url("pdf.export.php", {htmlForPdf:pdf})
https://stackoverflow.com/a/133997/903454

Related

FPDF PHP - Line is not working properly in second page

Following is my code which prints "HELLO", then a dotted line. This thing gets repeated 50 times. Everything is working fine but when 2nd page starts, dotted lines disappear. What modification is required in this code?
<?php
require("fpdf.php");
class PDF extends FPDF
{
function SetDash($black=null, $white=null)
{
if($black!==null)
$s=sprintf('[%.3F %.3F] 0 d',$black*$this->k,$white*$this->k);
else
$s='[] 0 d';
$this->_out($s);
}
}
$pdf = new PDF('P', 'mm', 'A4');
$pdf->AliasNbPages();
$pdf->AddPage();
$margin = 0;
$pdf->SetFont('Arial','B',12);
for ($i = 0; $i < 50; $i++)
{
$pdf->Cell(90, 10, "Hello", 0, 1);
$pdf->SetDrawColor(0,0,0);
$pdf->SetDash(2,2);
$margin = $margin + 10;
$pdf->Line(10,$margin,200,$margin);
}
$pdf->Output();
?>
You're incrementing the value of your $margin variable by 10 after each line even if a page break occurs in the middle of the loop. Thus, the top margin of the first line on the second page will be 10 millimeters greater than the top margin of the last line on the first page.
You need to reset the margin when a new page is added.
A solution for this problem would be to override FPDF's AcceptPageBreak method. This method intercepts the adding of a new page when the bottom of a page is reached.
class PDF extends FPDF
{
var $lineY = 0;
// ...
function AcceptPageBreak()
{
$this->lineY = 0;
return parent::AcceptPageBreak();
}
}
Then, in your loop, you can do:
$pdf->Line(10, $pdf->lineY, 200, $pdf->lineY);

FPDF not writing on all pages

Hi I'm using FPDF and FPDI, I'm using FPDI to concatenate several PDFs then using FPDF to fill in the information based on a form that is filled out, I've setup a SetPage method within FPDF to be able to set the page on which I'm working on, I'm able to write on the first file completely fine (first 3 pages). However, when I'm trying to write on the second file (4th and continuing pages), I use the SetXY and Write but nothing is written, I am able to add an image (barcode at the bottom of the page) but no text, any ideas as to what I'm doing wrong?
This is the code that I've got to concatenate the files:
<?php
session_start();
require_once('lib/pdf/fpdf.php');
require_once('lib/pdi/fpdi.php');
require_once('lib/barcode/class/BCGFontFile.php');
require_once('lib/barcode/class/BCGColor.php');
require_once('lib/barcode/class/BCGDrawing.php');
require_once('lib/barcode/class/BCGcode39extended.barcode.php');
$contractType = $_SESSION['addition'];
require_once('barcode.php');
if(isset($contractType))
{
$files = array('lib/blank/NDA.pdf');
if($contractType = 'artist')
{
array_push ($files,
'lib/blank/Distro.pdf',
'lib/blank/Management-Trial.pdf'
);
} else {
echo "Whoops! Something must've happened when you were filling out your contracts! Please try filling them out again. Sorry!";
}
}
$pdf = new FPDI();
foreach ($files AS $file) {
$pageCount = $pdf->setSourceFile($file);
for($n = 1; $n <= $pageCount; $n++) {
$tmpIdx = $pdf->importPage($n);
$size = $pdf->getTemplateSize($tmpIdx);
if($size['w'] > $size['h']) {
$pdf->AddPage('L', array($size['w'], $size['h']));
} else {
$pdf->AddPage('P', array($size['w'], $size['h']));
}
$pdf->useTemplate($tmpIdx);
}
}
//NDA FILLER
include('lib/filler/NDA.php');
//Distro Contract Filler
include('lib/filler/Distro.php');
//session_unset();
$pdf->Output();
?>
This is the code for filling out the first PDF (which works completely fine):
NDA.php
<?php
//ID No.
$idcoded = 'idbars/'.$_SESSION['name'].'.png';
/*
for($p = 2; $p <= $pages; $p++)
{
$pdf->Image($idcoded,0,350);
$pdf->setPage($p);
}
*/
$pdf->SetPage(1);
$pdf->Image($idcoded,0,350);
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
//NDA DATE
$pdf->SetXY(51, 109.5);
$pdf->Write(0, date(d));
$pdf->SetXY(72, 109.5);
$pdf->Write(0, date(F));
//Legal Name
$pdf->SetXY(72, 114.5);
$pdf->Write(0, $_SESSION['name']);
//stage Name
$pdf->SetXY(80, 119.5);
$pdf->Write(0, $_SESSION['sname']);
$pdf->setPage(2);
$pdf->Image($idcoded,0,350);
$pdf->setPage(3);
$pdf->Image($idcoded,0,350);
$signature = 'idbars/'.$_SESSION['name'].'_sig.png';
$pdf->Image($signature,20,105,100);
?>
This is what I'm using to try to write on the second PDF, I've tried combining the NDA.php and Distro.php into one file and that makes no difference
Distro.php
<?php
$pdf->SetPage(4);
$pdf->SetXY(10,10);
$pdf->Cell(0, $_SESSION['name']);
$pdf->Write(0, $_SESSION['name']);
$pdf->Image($idcoded,0,350);
?>
The page that this is building works off of this form:
https://secure.gr8label.com/sign/artist/Dev%20Test/
FPDF "caches" the font information that is currently used. As you jump back to another page FPDF "thinks" that the font is already defined/set but in the PDF file itself it isn't. You should set your font and size in your import loop, to ensure that the font is available on all pages (I think it also could work, by defining it only on the first one).
Anyhow you should have seen that jumping between written pages results in problems and you should create a logic which creates the file from top to bottom without using things like "SetPage()" at all.

TCPDF and FPDI with multiple pages

This looks like the simplest thing but I can't get it to work.
I need to add text to the first page of a multi-page pdf (could be any number of pages)
Using this code on a two page pdf (without the for loop, just using $pdf->importPage(2)) I end up with two pages but the second page is a repeat of page one. The text is written on the first page only which is good but I need all pages included in the output pdf. Here is my code
// Original file with multiple pages
$fullPathToFile = 'full/path/to/file.pdf';
class PDF extends FPDI {
var $_tplIdx;
function Header() {
global $fullPathToFile;
if (is_null($this->_tplIdx)) {
$this->setSourceFile($fullPathToFile);
$this->_tplIdx = $this->importPage(1);
}
$this->useTemplate($this->_tplIdx);
}
function Footer() {}
}
// initiate PDF
$pdf = new PDF();
$pdf->setFontSubsetting(true);
// add a page
$pdf->AddPage();
// The new content
$pdf->SetFont("helvetica", "B", 14);
$pdf->Text(10,10,'Some text here');
// How to get the number of pages of original pdf???
// $numPages = $pdf->getNumPages(???);
// Carry on adding all remaining pages starting from page 2
for($i=2;$i<=$numPages;$i++) {
// Add another page
$pdf->AddPage();
// Do I need to declare the source file here?
// $pdf->setSourceFile($fullPathToWD);
$pdf->importPage($i);
}
// Output the file as forced download
$pdf->Output('theNewFile.pdf', 'D');
Links to docs
TCPDF Classes
http://www.tcpdf.org/doc/code/classTCPDF.html#a5171e20b366b74523709d84c349c1ced
FPDI Classes
http://www.setasign.de/support/manuals/fpdi/
FPDF_TPL Classes
http://www.setasign.de/support/manuals/fpdf-tpl/
Solved my problem...
// Original file with multiple pages
$fullPathToFile = 'full/path/to/file.pdf';
class PDF extends FPDI {
var $_tplIdx;
function Header() {
global $fullPathToFile;
if (is_null($this->_tplIdx)) {
// THIS IS WHERE YOU GET THE NUMBER OF PAGES
$this->numPages = $this->setSourceFile($fullPathToFile);
$this->_tplIdx = $this->importPage(1);
}
$this->useTemplate($this->_tplIdx);
}
function Footer() {}
}
// initiate PDF
$pdf = new PDF();
$pdf->setFontSubsetting(true);
// add a page
$pdf->AddPage();
// The new content
$pdf->SetFont("helvetica", "B", 14);
$pdf->Text(10,10,'Some text here');
// THIS PUTS THE REMAINDER OF THE PAGES IN
if($pdf->numPages>1) {
for($i=2;$i<=$pdf->numPages;$i++) {
$pdf->endPage();
$pdf->_tplIdx = $pdf->importPage($i);
$pdf->AddPage();
}
}
// Output the file as forced download
$pdf->Output('theNewFile.pdf', 'D');
You get the number of pages by adding the first part of this line
$this->numPages = $this->setSourceFile($fullPathToFile);
And see the second last block of code - the for loop adds the remainder of the pages.
Don't know if this is how it should be done? I read in a few places that it wasn't even possible to achieve this, also the code is not supplied in the docs. However, this works, hope it helps someone.
I struggled with this a little and tried to come up with simplest way to add some text to the last page of a multi-page document. Here is the very simple code that worked for me:
require_once('fpdf/fpdf.php');
require_once('fpdf/fpdi.php');
$pdf = new FPDI();
$fullPathToPDF = '/usr/local/common/my.pdf';
$pageCount = $pdf->setSourceFile($fullPathToPDF);
for ($i = 1; $i <= $pageCount; $i++) {
$pdf->importPage($i);
$pdf->AddPage();
$pdf->useTemplate($i);
}
$pdf->SetFont('Helvetica');
$pdf->SetXY(110, 225);
$pdf->Write(8, 'A complete document imported with FPDI');
$pdf->Output($fullPathToPDF);
Just change the full path to file to a location where you have a multi-page PDF.
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
...
$pdf->SetMargins(10, 10, 10);
$pdf->SetAutoPageBreak(true, 10);
foreach($array as $item)
{
$pdf->AddPage(); //add new page for new item
$txt = some_long_long_text;
$pdf->Write(0, $txt, '', 0, 'C', true);
$pdf->endPage(); //do end of page
$pdf->lastPage(); //set cursor at last page, because autopagebreak not do it
}
In example, you have 10 pupils in array, and you need create resume for each. In exam, one resume have 3 pages. So in out u get pdf with 30 pages, with correct text.
SetAutoPageBreak(true, 10), not set cursor at last page, so you need to do it manually with function $pdf->lastPage();
that code wont work, try this:
$pdf = new PDI();
$pdf->AddPage();
$pdf->setSourceFile('zzz.pdf');
$pdf->numPages = $pdf->setSourceFile('zzz.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 20, 200);
if($pdf->numPages>1) {
for($i=2;$i<=$pdf->numPages;$i++) {
$pdf->AddPage();
$tplIdx = $pdf->importPage($i);
$pdf->useTemplate($tplIdx, 10, 20, 200);
}
}

FPDF: Decide when to set header/footer data

I've been struggling with the header and footer data for quite some time now and thought it was time to ask it here on the forum.
What I'm trying to do is decide that if a page is added if the header / footer should be added or not. so code-wise I want to set the header/footer to on or off when adding a page.
I've tried to manipulate the function AddPage by setting an extra argument $setFooterHeader which default is set to true. And then trying to set this argument to false whenever I do an addPage('','',false); but it ignores it for some reason and I can't figure out why.
If I set the default value of the argument to false in the function itself it works like a charm, but when I try to do it in my script and set it as an argument, it totally ignores it.
Here's a code snippet of the fpdf.php file (function addPage)
function AddPage($orientation='', $size='', $setHeaderFooter=true)
{
// Start a new page
if($this->state==0)
$this->Open();
$family = $this->FontFamily;
$style = $this->FontStyle.($this->underline ? 'U' : '');
$fontsize = $this->FontSizePt;
$lw = $this->LineWidth;
$dc = $this->DrawColor;
$fc = $this->FillColor;
$tc = $this->TextColor;
$cf = $this->ColorFlag;
if($this->page>0)
{
// Page footer
if ($setHeaderFooter == true)
{
$this->InFooter = true;
$this->Footer();
$this->InFooter = false;
// Close page
$this->_endpage();
}
}
// Start new page
$this->_beginpage($orientation,$size,$setHeaderFooter);
// Set line cap style to square
$this->_out('2 J');
// Set line width
$this->LineWidth = $lw;
$this->_out(sprintf('%.2F w',$lw*$this->k));
// Set font
if($family)
$this->SetFont($family,$style,$fontsize);
// Set colors
$this->DrawColor = $dc;
if($dc!='0 G')
$this->_out($dc);
$this->FillColor = $fc;
if($fc!='0 g')
$this->_out($fc);
$this->TextColor = $tc;
$this->ColorFlag = $cf;
// Page header
if ($setHeaderFooter == true)
{
$this->InHeader = true;
$this->Header();
$this->InHeader = false;
}
// Restore line width
if($this->LineWidth!=$lw)
{
$this->LineWidth = $lw;
$this->_out(sprintf('%.2F w',$lw*$this->k));
}
// Restore font
if($family)
$this->SetFont($family,$style,$fontsize);
// Restore colors
if($this->DrawColor!=$dc)
{
$this->DrawColor = $dc;
$this->_out($dc);
}
if($this->FillColor!=$fc)
{
$this->FillColor = $fc;
$this->_out($fc);
}
$this->TextColor = $tc;
$this->ColorFlag = $cf;
}
Below is a code snippet of my PHP script which uses FPDF
/** PHP FPDF */
require_once 'classes/FPDF/fpdf.php';
require_once 'classes/FPDI/fpdi.php';
class PDF extends FPDI
{
function Header()
{
$this->SetFont( 'Arial', 'B', 18 ); //set font to Arial, Bold, and 16 Size
//create heading with params
//0 - 100% width
//9 height
//"Page Heading" - With this text
//1 - border around it, and center aligned
//1 - Move pionter to new line after writing this heading
//'C' - center aligned
$this->Cell( 0, 9, 'Page Heading', 1, 1, 'C' );
$this->ln( 5 );
}
function Footer()
{
//move pionter at the bottom of the page
$this->SetY( -15 );
//set font to Arial, Bold, size 10
$this->SetFont( 'Arial', 'B', 10 );
//set font color to blue
$this->SetTextColor( 52, 98, 185 );
$this->Cell( 0, 10, 'Footer Text', 0, 0, 'L' );
//set font color to gray
$this->SetTextColor( 150, 150, 150 );
//write Page No
$this->Cell( 0, 10, 'Page No: ' . $this->PageNo(), 0, 0, 'R' );
}
}
// Create new PDF object
$pdf = new PDF('P','mm','A4');
$pdf->addPage('','',false);
// Output pdf file
$pdf->Output('test.pdf','D');
Your help is greatly appreciated!!
I have solved this issue by setting a flag outside the class and use this flag in the header and footer function
The fix is in the page section, not in the addPage function
Just before doing an $pdf->addPage You set the flag as addPage automatically calls the header and footer function.
Here's the correct code (snippet of PHP script which uses FPDF)
/** PHP FPDF */
require_once 'classes/FPDF/fpdf.php';
require_once 'classes/FPDI/fpdi.php';
class PDF extends FPDI
{
function Header()
{
if ($this->header == 1)
{
$this->SetFont( 'Arial', 'B', 18 ); //set font to Arial, Bold, and 16 Size
//create heading with params
//0 - 100% width
//9 height
//"Page Heading" - With this text
//1 - border around it, and center aligned
//1 - Move pionter to new line after writing this heading
//'C' - center aligned
$this->Cell( 0, 9, 'Page Heading', 1, 1, 'C' );
$this->ln( 5 );
}
}
function Footer()
{
if ($this->footer == 1)
{
//move pionter at the bottom of the page
$this->SetY( -15 );
//set font to Arial, Bold, size 10
$this->SetFont( 'Arial', 'B', 10 );
//set font color to blue
$this->SetTextColor( 52, 98, 185 );
$this->Cell( 0, 10, 'Footer Text', 0, 0, 'L' );
//set font color to gray
$this->SetTextColor( 150, 150, 150 );
//write Page No
$this->Cell( 0, 10, 'Page No: ' . $this->PageNo(), 0, 0, 'R' );
}
}
}
// Create new PDF object
$pdf = new PDF('P','mm','A4');
$pdf->header = 0;
$pdf->footer = 0;
$pdf->addPage('','',false);
// Output pdf file
$pdf->Output('test.pdf','D');
I know you found out the awnser already for yourself, but as one of the commenters pointed out this didn't work for me with the footer.
The good news is you can do without setting the external flags. You can use $this->PageNo() to determine whether to include the header and footer or not.
For instance if you'd want to exclude the header and footer on the first page, like I did:
function Footer() {
if($this->PageNo() != 1){
// footer code
}
}
If you'd want to let's say exclude them on several pages and not write an endless if statement you should just put the page numbers to exclude in an array and check with in_array() whether the header and/or footer should be included.
You can define multiple different types of headers and footers by calling functions outside the class:
class PDF extends FPDF {
function Header(){
if(!empty($this->enableheader))
call_user_func($this->enableheader,$this);
}
function Footer(){
if(!empty($this->enablefooter))
call_user_func($this->enablefooter,$this);
}
}
$pdf = new PDF('P');
$pdf->SetTextColor(0);
$pdf->SetFont('Arial','B',10);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Cell(50,6,'Headerless & Footerless page');
$pdf->enableheader = 'header1';
$pdf->AddPage();
$pdf->enablefooter = 'footer1';
$pdf->AddPage();
$pdf->AddPage();
$pdf->enableheader = 'header2';
$pdf->AddPage();
$pdf->enablefooter = 'footer2';
$pdf->Output();
function header1($pdf){
$pdf->Cell(50,6,'Header type 1',1,0,'L');
}
function footer1($pdf){
$pdf->SetY(280);
$pdf->Cell(50,6,'Footer type 1',1,0,'L');
$pdf->Cell(0,6,"Page: {$pdf->PageNo()} of {nb}",1,0,'R');
}
function header2($pdf){
$pdf->Cell(50,6,'Header type 2',1,0,'L');
}
function footer2($pdf){
$pdf->SetY(280);
$pdf->Cell(50,6,'Footer type 2',1,0,'L');
$pdf->Cell(0,6,"Page: {$pdf->PageNo()} of {nb}",1,0,'R');
}
The trick to footers is that the footer is added when the next page is created, with the last footer being added when the output is closed.
Therefore, you have to define the header before the page is added, and the footer afterwards but before the next page.

GD Library image creation problem

I am having a problem with a gd library issue. When I use the following code
<script type="text/javascript">
$.fn.infiniteCarousel = function () {
function repeat(str, num) {
return new Array( num + 1 ).join( str );
}
return this.each(function () {
var $wrapper = $('> div', this).css('overflow', 'hidden'),
$slider = $wrapper.find('> ul'),
$items = $slider.find('> li'),
$single = $items.filter(':first'),
singleWidth = $single.outerWidth(),
visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
currentPage = 1,
pages = Math.ceil($items.length / visible);
// 1. Pad so that 'visible' number will always be seen, otherwise create empty items
if (($items.length % visible) != 0) {
$slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
$items = $slider.find('> li');
}
// 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
$items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
$items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
$items = $slider.find('> li'); // reselect
// 3. Set the left position to the first 'real' item
$wrapper.scrollLeft(singleWidth * visible);
// 4. paging function
function gotoPage(page) {
var dir = page < currentPage ? -1 : 1,
n = Math.abs(currentPage - page),
left = singleWidth * dir * visible * n;
$wrapper.filter(':not(:animated)').animate({
scrollLeft : '+=' + left
}, 500, function () {
if (page == 0) {
$wrapper.scrollLeft(singleWidth * visible * pages);
page = pages;
} else if (page > pages) {
$wrapper.scrollLeft(singleWidth * visible);
// reset back to start position
page = 1;
}
currentPage = page;
});
return false;
}
$wrapper.after('<a class="arrow back"><</a><a class="arrow forward">></a>');
// 5. Bind to the forward and back buttons
$('a.back', this).click(function () {
return gotoPage(currentPage - 1);
});
$('a.forward', this).click(function () {
return gotoPage(currentPage + 1);
});
// create a public interface to move to a specific page
$(this).bind('goto', function (event, page) {
gotoPage(page);
});
});
};
$(document).ready(function () {
$('.infiniteCarousel').infiniteCarousel();
$("a.pictureThumb").fancybox({
'autoScale' : true,
'autoDimension' : true,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'speedIn' : 300,
'speedOut' : 200,
'hideOnOverlayClick' : true,
'hideOnContentClick': false
});
});
</script>
With this as the image generator, the only thing that comes out is what looks like programming code instead of an image. This script worked with a different scroller, but since I put this new scroller script (seen above), I am having problems with it generating an image (IE it just shows the loading icon), FireFox actually shows the programming code.
Here is the code that is making the call to the GD function:
<div class="infiniteCarousel">
<div class="wrapper">
<ul>
<?php
do { ?>
<li><a class="pictureThumb" href="picture.php?imgID=<?php $pieces = explode('_', $row_rsPictures['PictureFile']); echo $pieces[0]."_".$pieces[1]."_".$pieces[2]; if ($pieces[3] == "NN"){ echo "_NN_".$pieces[4]."_".$pieces[5];; } else { echo "_".$pieces[3]."_".$pieces[4]; } ?>&thumb=Y" title="<a href='addToCart.php?T=Pic?ID=<?php echo $row_rsPictures['PictureID']; ?>' target='_parent' style='color:#fe6d00' >Add This Image To Your Shopping Cart</a><br><?php echo $row_rsPictures['BoatName'];if($row_rsPictures['BoatNumber'] != "") {
echo " #".$row_rsPictures['BoatNumber'];
} ?><br>driven by: <?php echo $row_rsPictures['DriverName']; ?> at the <?php
$AssocName_array = explode('_', $row_rsPictures['Acronym']);
$AssocName = $AssocName_array[0];
if ($AssocName == "Various") {
$AssocName = "";
}
if ($row_rsPictures['DateTo'] != ""){
$EventYear = date("Y", strtotime($row_rsPictures['DateTo']));
}
else { $EventYear = "";
}
echo $EventYear." ".$AssocName." ".$row_rsPictures['EventName'];?><br>Picture Viewed (<?php echo $row_rsPictures['Views']; ?>) since posted on <?php echo date("n-j-Y", strtotime($row_rsPictures['DatePosted'])); ?>" rel="group">
<img src="../images/gallery/<?php $raceYear = explode('_', $row_rsPictures['EventOverlay']); echo $raceYear[0]; ?>/<?php echo $row_rsPictures['EventOverlay']; ?>/thumb/<?php echo $row_rsPictures['PictureFile']; ?>.jpg" alt="FileName: <?php echo $row_rsPictures['PictureFile'];?>"></a></li>
<?php
} while ($row_rsPictures = mysql_fetch_assoc($rsPictures));
mysql_data_seek($rsPictures, 0);
?>
</ul>
</div>
</div>
and the separate php file that generates the image.
<?php
$filename = explode("_", $_GET['imgID']);
$folder = $filename[0];
$subFolder = $filename[0]."_".$filename[1]."_".$filename[2];
if($filename[3] == "NN") {
$subFolder = $subFolder."_NN";
}
$shot = "../images/gallery/".$folder."/".$subFolder."/".$_GET['imgID'].".jpg";
$watermark = "../images/gallery/watermark.png";
header("Content-type: image/jpg");
$photoImage = ImageCreateFromJPEG($shot);
ImageAlphaBlending($photoImage, true);
$logoImage2 = ImageCreateFromPNG($watermark);
$im = imagecreatetruecolor(800, 16);
$im2 = imagecreatetruecolor(800, 10);
$white = imagecolorallocate($im, 255, 255, 255);
//imagefilledrectangle($photoImage, 0, 0, 796, 15, $white);
$grey = imagecolorallocate($im2, 128, 128, 128);
$red = imagecolorallocate($im2, 255, 0, 0);
//$im = imagecreatetruecolor(796, 25);
$text = $_GET['imgID'];
$text2 = 'COPYRIGHT 1997 - 2011 - DRAGBOATS.COM - ALL RIGHTS RESERVED';
$text3 = '^ THIS BAR WILL NOT APPEAR ON PURCHASED PRINTS ^';
//$black = imagecolorallocate($photoImage, 0, 0, 0);
imagestring($im, 2, 10, 1, $text, $white);
imagestring($im, 2, 440, 1, $text2, $white);
imagestring($im2, 1, 290, 1, $text3, $white);
ImageCopy($photoImage, $im, 0, 0, 0, 0, 800, 16);
ImageCopy($photoImage, $im2, 0, 17, 0, 0, 800, 10);
ImageCopy($photoImage, $logoImage2, 0, 0, 0, 0, 800, 525);
ImageJPEG($photoImage); // output to browser
ImageDestroy($photoImage);
ImageDestroy($logoImage2);
?>
Somewhere there is a conflict that is causing the problem and I can't find it.
Any help is appreciated.
The actual page can be found at http://randykrohn.com/gallery/pictures_test.php?BoatID=881
It appears you're outputting the raw image data (the bytes in the .jpg) file into the gallery popup, with an innappropriate header so that the imgae is being interpreted as text and not an image.
If that last chunk of code under "... the call to GD function" is all in one file, that would explain why. You're outputting a chunk of html, followed by the raw image data, which then gets inserted into the gallery popup. The Content-type header cannot take effect as you've already output some html. If you check your error logs (and/or actually enable errors/warnings), you'd no doubt see the usual "cannot modify headers, output started at line XXX" warnings from PHP.
Try to set php memory limit to 96M (128M - recommended) in php.ini file. If you have no access to that file simply add ini_set('memory_limit', '128M'); to your php file. It must help to solve the issue.
Didn't help, but figured it out on my own. Needed to tell FancyBox to open the link explicitly as an image (ie: fancybox({'type' : 'image'}); Alls well now! Thanks for you help guys!

Categories