Jump to content

Output pdf with images inside pages


figo2476

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.