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?
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());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.