Jump to content

Output pdf with images inside pages


figo2476

Recommended Posts

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

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;

?>

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);

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.