Magento PDF-Ausgaben von Artikeln

The Magento extension "PDF Catalog" from Magazento provides a good way to output individual products and entire categories as PDFs.

In the free version, the frontend provides the option to save individual products and entire categories (on the server), print them (PDF download), or display them as a PDF preview. Simply download the ZIP file, unpack it, and upload it via FTP.

However, a problem arises with the PHP configuration allow_url_fopen = Off. Since the Magento extension uses file_get_contents on URLs in some places, the stylesheet and product images cannot be retrieved. The PDF is still generated, but it is unformatted and contains no images. However, this problem can be solved relatively easily if the server configuration supports cURL. By replacing file_get_contents in two files, access to the stylesheet and images in the cache is restored, resulting in a properly formatted PDF:

1. File: lib\dompdf6\include\image_cache.cls.php

Find the following line here:
$image = file_get_contents($full_url);

and replace it with:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $full_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$image = curl_exec($curl);
curl_close($curl);

2. File: lib\dompdf6\include\stylesheet.cls.php

Find the following line here:
$css = file_get_contents($file);

and replace it with:
if (!(parse_url($file,PHP_URL_SCHEME)=='http')){
$css = file_get_contents($file);
} else {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $file);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$css = curl_exec($curl);
curl_close($curl); }
... back to the blog