0

On my PHP FPDF script

<?php
...
$mypdf->Image("http://s3-ap-southeast-1.amazonaws.com/mybucket/path/to/the/image/file.png", null, null, 150, 150);
...
?>

and it causes errors. However when I try to do the same thing but with a different image not hosted on S3, it works.

How is this possible that S3 does not work with FPDF?

1
  • What error are you getting exactly? Commented Nov 18, 2016 at 9:32

1 Answer 1

2

I was having the same problem and I after some digging in the fpdf source figured out the issue was with fopen(). In order to use this method with an S3 image you need to use an S3 Stream Wrapper. This requires the AWS SDK for PHP or you could also roll your own if really wanted to.

My code looks like this

$credentials = new Aws\Credentials\Credentials('KEY','SECRET');
$client = new Aws\S3\S3Client([
    'version'=>'latest',
    'region'      => 'REGION',
    'credentials' => $credentials
]);
$client->registerStreamWrapper();

// Link to file
$url = 's3://bucket/key';

// add background image
$fpdf->Image($url, 0, 0, $fpdf->GetPageWidth(), $fpdf->GetPageHeight());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.