I upload PDFs using File/browse option from frontend and As I Upload, I want to have a watermark uploaded to those PDFs automatically. Below is a sample code for upload pdf in Store function of the controller
if ($request->hasFile('qpid')) {
$paperuploads = $request->file('qpid');
foreach ($paperuploads as $paperupload){
$paperuploadfilename = 'QP_'. time() . '.' . $paperupload->getClientOriginalExtension();
$destinationPath = public_path('/storage/papers');
Is there any way to dynamically add watermark to PDF? Thanks
For benefit of others, I got this solved by using following Github repository:
https://github.com/ajaxray/markpdf
Then using symfony process to call MarkPDF and thereby getting this implemented.
Related
I upload an image on form vue to server laravel and store it in public in folder image_cards correctly and display it correctly. But after maybe one hour or two, it doesn't show. What is the problem I have?
if ($request->hasFile('image')) {
$file = $request->file('image');
$filename = $file->getClientOriginalName();
$path = $request->file('image')->move(public_path('image_cards'), $filename);
$card->image = $filename;
}
Edit: the problem with Heroku is it doesn't store images and save its path. The other web host saves the path to the image.
You are missing image path and you need to return full image path. please use following code to return image path
$card->image=public_path('image_cards').'/'.$filename;
the solution is heroku in documentation it doesn't save the path of file after some time like one or two hour –
I want to save an image (from URL) and relocate it to another folder without creating a form, into a controller. How can I realize it?
Download image inside Controller -> relocate it to another folder -> save image name into my database (in an existing table).
Your question is broad and you don't specify if you are using Doctrine DBAL and ORM and what exactly your problem is, so I will assume that you do use them and you are aware how to inject entity manager inside a controller action.
First you have to download the image and save the image:
$content = file_get_contents("http://example.com/image.jpg");
//Store in the filesystem.
$fp = fopen("/location/to/save/image.jpg", "w");
fwrite($fp, $content);
fclose($fp);
Then save the path into the database:
$imageEntity->setPath('image.jpg');
$entityManager->flush($imageEntity);
I have been trying to import products into Magento and images. The products are being imported and created properly but the images to not get imported.
I am aware of the basics of importing as I have done it in the past but cannot figure out what the issue is and what to do next.
some notes how and what I did:
I am aware to add a "/" before the image name
image name is case sensitive
upload images in media/import folder
media folder to be 777
Tried different folders like var/import or
media/catalog/product/import
Removed the .htcaccess file in media
Flushed cache
when i upload manually an image on a product it does show up properly
i tried specifying the _media_attribute_id in a column as 88 maybe
that should help but it didn't
If you have a Mage_Catalog_Model_Product, all you need to do is this:
$fn = '/absolute/path/to/image.jpg';
$types = array('thumbnail', 'small_image', 'image'); // or null if you already have the product's thumbnail, small image, and image set
$move = true; // move the source file, don't leave it sitting around
$exclude = false; // enabled in product view
$label = 'Turquoise';
$product->addImageToMediaGallery($fn, $types, $move, $exclude); // Strictly speaking, only the first parameter is required
if(!empty($label)) {
$gallery = $product->getData('media_gallery');
$gallery_img = array_pop($gallery);
$gallery_img['label'] = $label;
array_push($gallery['images'], $gallery_img);
$product->setData('media_gallery', $gallery);
}
$product->save();
I have faced the same problem while uploading product image. And i tested many methods to figure that out. But nothing helped me. At last in one of the tutorial I have seen that the image name and the sku name has to be same. with the extension of file extension. So i followed it and by God's grace it worked. You may try that also. It worked for me. I had spent almost one full day to figure that out.
I have create private folder in application folder: application/private/username, I'm uploading images here with ajax, that works, but how can I retrieve that image with ajax, and display it in img tag. First problem is that http://example.com/application/private/useraname/img.jpg is protected, I can't access it through out url in browser, how to display an image. Just advice, I wanna write code on my own.
This is part of function(that is part of controller) that grabs image:
$filepath = 'path to image';
header("Content-type: image/jpeg");
if (file_exists($filepath)) {
$img_handle = imagecreatefromjpeg($filepath) or die("");
echo $img_handle;
ImageJpeg($img_handle);
}
But how to get this image with ajax?
You might want to create a PHP file that would get the filename eg thumb.php?src=img.jpg and inside that file, you load the image from that path and display it. This way the path of the images are not exposed to the user.
I'm using DOMPDF to generate PDF's that can contain images and I'm having a weird issue with that.
The PDF is generated inside a loop and the amount of PDF's that needs to be generated varies. When there is only 1 PDF generated everything goes well. The image (or logo in this case) is getting inserted beautifully.
But when there are 2 or more PDF's that have to be generated for some reason the image is replaced with a red cross. But: the image in the first PDF generated in that batch works perfectly. So: the image in PDF #1 loads perfectly, the image in PDF #2 and up is getting replaced with a red cross.
I'm using the latest stable release of DOMPDF (v0.5.2). I've also tested with v0.5.1 but that had the same behaviour.
The server I'm testing this on runs on Linux, with PHP 5.3.8. No errors in the error-log about this (and I do have error logging enabled).
--- edit:
The "path" to the image is an absolute URL, not an absolute or relative (PHP) path and with outputting the contents of the loop to the browser (or a normal HTML email, without the PDF attachment) it displays the image (in all mails) perfectly.
--- edit2:
Using a function to flush all buffers at the end of the loop (which, unfortunately, doesn't change anything to my issue):
function flush_buffers()
{
ob_end_flush();
ob_flush();
flush();
ob_start();
}
An example of the loop I'm using:
for ( $i = 0; $i < count($cert); ++$i )
{
// load the email-template
ob_start();
include($template);
$content = ob_get_contents();
ob_end_clean();
// require dompdf
include_once('dompdf/dompdf_config.inc.php');
// set PDF path - inside temp dir
$newpdf = trailingslashit(realpath(sys_get_temp_dir())).$cert[$i]['coupon'].'.pdf';
// replace shortcodes with wanted content
$certificate = preg_replace($shortcodes, $replacements, $certificate);
$certificate = '<html><body>'.$certificate.'</body></html>'."\n";
$dompdf = new DOMPDF();
$dompdf->load_html($certificate);
$dompdf->set_paper($pageformat, $orientation);
$dompdf->render();
save_pdf($newpdf, $dompdf->output()); // save PDF
#flush_buffers();
}
One of the shortcodes is [logo] and that's getting replaced with an img-tag. As I previously mentioned: that image works fine in the first PDF, but not in the other PDF's.
Upgrading to dompdf 0.6beta2 fixed this issue. Thanks Fabien!