figo2476 Posted November 20, 2007 Share Posted November 20, 2007 I play around with File_PDF class. I found some examples in the pear website, but I didn't see any example to output images inside a page. any hint will be appreciated. Link to comment https://forums.phpfreaks.com/topic/78006-output-pdf-with-images-inside-pages/ Share on other sites More sharing options...
Barand Posted November 20, 2007 Share Posted November 20, 2007 Google and ye shall find http://pear.php.net/package/File_PDF/docs/0.0.1/File_PDF/File_PDF.html#methodimage (which probably took less time than typing the question) Link to comment https://forums.phpfreaks.com/topic/78006-output-pdf-with-images-inside-pages/#findComment-394820 Share on other sites More sharing options...
figo2476 Posted November 20, 2007 Author Share Posted November 20, 2007 I did a search and look at the doc in the code. I don't fully understand the API for image. I did: $name = 'www.google.com/pic.jpg'; $this->image($name, 5, 5, 0, 0, 'jpg'); I don't put $link them, since I think it is for linkage.... Correct me if I am wrong Link to comment https://forums.phpfreaks.com/topic/78006-output-pdf-with-images-inside-pages/#findComment-394833 Share on other sites More sharing options...
Barand Posted November 20, 2007 Share Posted November 20, 2007 And when you did that, what happened? Link to comment https://forums.phpfreaks.com/topic/78006-output-pdf-with-images-inside-pages/#findComment-394842 Share on other sites More sharing options...
figo2476 Posted November 20, 2007 Author Share Posted November 20, 2007 It didn't work <?php require_once 'HTTP/Download.php'; require_once 'File/PDF.php'; class MyPDF extends File_PDF { function header() { global $title; $this->setFont('Arial', 'B', 15); $w = $this->getStringWidth($title) + 6; $this->setX((210 - $w) / 2); $this->setDrawColor('rgb', 0/255, 80/255, 180/255); $this->setFillColor('rgb', 230/255, 230/255, 0/255); $this->setTextColor('rgb', 220/255, 50/255, 50/255); $this->setLineWidth(1); $this->cell($w, 9, $title, 1, 1, 'C', 1); $this->newLine(10); } function footer() { $this->setY(-15); $this->setFont('Arial', 'I', ; $this->setTextColor('gray', 128/255); $this->cell(0, 10, 'Page ' . $this->getPageNo(), 0, 0, 'C'); } function chapterTitle($num, $label) { $this->setFont('Arial', '', 12); $this->setFillColor('rgb', 200/255, 220/255, 255/255); $this->cell(0, 6, "Chapter $num : $label", 0, 1, 'L', 1); $this->newLine(4); } function chapterBody($file) { $this->setFont('Times', '', 12); $this->multiCell(0, 5, $file); $this->newLine(); $this->setFont('', 'I'); $this->cell(0, 5, '(end of chapter)'); } function printChapter($num, $title, $file) { $this->addPage(); $this->chapterTitle($num, $title); //$this->chapterBody($file); $link = "http://www.site.com/images/thumbs/150/16511.jpg"; $this->image('test', 5, 5, 10, 10, 'jpg', $link); } } ?> <?php $pdf = MyPDF::factory( array( 'orientation' => 'P', 'unit' => 'mm', 'format' => 'A4'), 'MyPDF' ); $pdf->setCompression(false); $title = '20000 Leagues Under the Seas'; $pdf->setInfo('title', $title); $pdf->setInfo('author', 'Jules Verne'); $pdf->printChapter(1, 'A RUNAWAY REEF', 'abcABCdfk;sdkf;lksd;lfkds;lfk;sdfjlkdsjfljdslf sldjfldsjfljsdlfjlsdjfljdslf sdfjlsdjflsdjfljsdfljs sdfldsjf'); $pdf->printChapter(2, 'THE PROS AND CONS', 'defDEF'); return $pdf; ?> Link to comment https://forums.phpfreaks.com/topic/78006-output-pdf-with-images-inside-pages/#findComment-394850 Share on other sites More sharing options...
figo2476 Posted November 20, 2007 Author Share Posted November 20, 2007 It is not correct. Then I put the test.jpg next to my php file, the pdf still doesn't include any image. $name='test.jpg'; $this->image($name, 50, 50, 20, 20, 'jpg'); Link to comment https://forums.phpfreaks.com/topic/78006-output-pdf-with-images-inside-pages/#findComment-394899 Share on other sites More sharing options...
Barand Posted November 20, 2007 Share Posted November 20, 2007 try changing $this->image('test', 5, 5, 10, 10, 'jpg', $link); to $this->image('test.jpg', 5, 5, 10, 10); Link to comment https://forums.phpfreaks.com/topic/78006-output-pdf-with-images-inside-pages/#findComment-395016 Share on other sites More sharing options...
figo2476 Posted November 20, 2007 Author Share Posted November 20, 2007 I have found 3 things: * If I just use the pure example from the website, I am able to simply put $this->image('test.jpg', 5, 5, 10, 10); in the code. It will work well. * After put the code into my cms, I need to specify the explicit path, even the image is just next to the php file. * If I say: $name = 'www.other_site.com.au/pic.jpg'; $this->image('test.jpg', 5, 5, 10, 10); This won't work. This scenario occurs, when some images are not sitting in the same server as the code. Is it possible to make it work in this scenario? try changing $this->image('test', 5, 5, 10, 10, 'jpg', $link); to $this->image('test.jpg', 5, 5, 10, 10); Link to comment https://forums.phpfreaks.com/topic/78006-output-pdf-with-images-inside-pages/#findComment-395509 Share on other sites More sharing options...
figo2476 Posted November 20, 2007 Author Share Posted November 20, 2007 I have found 3 things: * If I just use the pure example from the website, I am able to simply put $this->image('test.jpg', 5, 5, 10, 10); in the code. It will work well. * After put the code into my cms, I need to specify the explicit path, even the image is just next to the php file. * If I say: $name = 'www.other_site.com.au/pic.jpg'; $this->image('test.jpg', 5, 5, 10, 10); This won't work. This scenario occurs, when some images are not sitting in the same server as the code. Is it possible to make it work in this scenario? try changing $this->image('test', 5, 5, 10, 10, 'jpg', $link); to $this->image('test.jpg', 5, 5, 10, 10); It should be $name = 'www.other_site.com.au/pic.jpg'; $this->image($name, 5, 5, 10, 10); This won't work. Link to comment https://forums.phpfreaks.com/topic/78006-output-pdf-with-images-inside-pages/#findComment-395511 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.