KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Error when Exporting - Could not save content to temporary folder otherwise PDF is Blank Laravel #1639

Closed Mukesh opened this topic on on Sep 30, 2020 - 34 comments

Mukesh commented on Sep 30, 2020

I'm getting an error when attempting to export. Here's the error: [2020-09-30 10:21:40] local.ERROR: Could not save content to temporary folder

I am using window 8 and xampp and laravel. My code is below.

MyReport.php

<?php 
namespace App\Modules\Report;

class MyReport extends \koolreport\KoolReport
{
	use \koolreport\export\Exportable;
}
?>

MyReport.view.php

<html>
    <body style="margin: 1in">
        <div class='page-header' style='height:30px'>
            <span>Header</span>
        </div>

        ...
        ...

        <div class='page-footer' style='height:30px'>
            <span>Footer</span>
        </div>
    </body>
</html>

CertificateController.php

<?php 
namespace App\Modules\Report;
use App\Modules\Report\MyReport;;

class CertificateController extends Controller
{
	public function index(Request $request){
		try{
			$report = new MyReport();
			$report->run();
			$report->export("MyReport")->settings(
				array(
					"useLocalTempFolder"=>true,
				))->pdf(array(
					"format"=>"A4",
					"orientation"=>"portrait"
			))->toBrowser("report.pdf", true);

		}catch(\Exception $e){
			Log::error($e->getMessage());
			return view('error.home');
			return false;
		}
	}
	
}
?>

Can you help me where I am going wrong.

David Winterburn commented on Oct 1, 2020

Hi,

Please check for a local "tmp" folder in either koolreport/export or where your report is. If it exists please try this simple comment to see if it works or returns an error:

<?php
    file_put_contents($pathToLocalTmp, "Hello world");
?>
Mukesh commented on Oct 1, 2020

Hi, I tried with your code it works fine but my code still giving the same error.

When i am generating PDF with below code PDF is blank but my MyReport.view.php have html content.

$report = new MyReport();
			$report->run();
			$report->export("MyReport")->settings(
				array(
					"useLocalTempFolder"=>true,
				))->pdf(array(
					"format"=>"A4",
					"orientation"=>"portrait"
			))->toBrowser("report.pdf", true);
David Winterburn commented on Oct 1, 2020

Hi,

Looks like the "Could not save content to temporary folder" error is no longer there.

Regarding blank pdf issue, which http server were you using? If it's a PHP's built-in server or Laravel's the Export package won't work correctly because Export uses PhantomJS which is knowed to not work perfectly with some dev servers like the PHP's one. If it's the case with yours, please try Apache, nginxx, etc.

Mukesh commented on Oct 1, 2020

I am working on localhost, xampp and Apache server.

David Winterburn commented on Oct 1, 2020

Please create a file called "MyReportPdf.view.php" with only text like "Hello world". Then use this export command:

$report->export("MyReportPdf")
...

Let us know the result. Thanks!

Mukesh commented on Oct 1, 2020

Nothing, showing blank page.

David Winterburn commented on Oct 2, 2020

In your local tmp directory there should be a number of files with .tmp and .pdf extensions. Please open the latest .tmp file with your text editor and see if it has any content?

Mukesh commented on Oct 5, 2020

No tmp, and pdf file created inside temp folder

David Winterburn commented on Oct 5, 2020

Please try the follow commands and let us know the result:

<?php
    ini_set('display_errors', '1');
    ini_set('display_startup_errors', '1');
    error_reporting(E_ALL);
    file_put_contents($pathToLocalTmp . "/test.txt", "Hello world"); 
Mukesh commented on Oct 5, 2020

This code working fine, creating .txt file, and inserting hello word. But when i am trying to generate PDF its generating blank.

David Winterburn commented on Oct 5, 2020

Hi,

Please open the file koolreport/export/Handler.php and look for this line:

    if (file_put_contents($source, $content)) {

Please put the following commands just before it:

    echo "file path = $source<br>";
    echo "content = " . htmlentities($content); 
    if (file_put_contents($source, $content)) {

Then click your export button to see if any content is outputted to the screen. If there's one please check to see if there's any file with the outputted file path. Let us know the result. Thanks!

Mukesh commented on Oct 5, 2020
echo "file path = $source<br>";

The above code showing temp folder path of C Drive.

echo "content = " . htmlentities($content); 

The above code showing HTML content of view.

David Winterburn commented on Oct 5, 2020

If there's file path and content please check to see if there's any file with the outputted file path.

Mukesh commented on Oct 5, 2020

Sir PDF is generating but blank

David Winterburn commented on Oct 5, 2020

We are taking step by step checks. I am asking you if the $source file path exists and if there's any content in it?

Mukesh commented on Oct 5, 2020

Yes, Folder path exists but .tmp file path does not exist.(5f7afbad77efb1.tmp)

David Winterburn commented on Oct 6, 2020

It's strange that the .tmp file couldn't be found but now exception wasn't thrown. Please open the file koolreport/export/Handler.php and replace the following code:

        if (file_put_contents($source, $content)) {
            return $source;
        } else {
            throw new \Exception("Could not save content to temporary folder");
            return false;
        }

with this:

        if (file_put_contents($source, $content)) {            
            echo "Content is saved to $source";
        } else {
            echo "There's problem saving content to $source";
            throw new \Exception("Could not save content to temporary folder");
        }
        exit;

Then run export again and let us know the result. Thanks!

Mukesh commented on Oct 6, 2020

Result is : Content is saved to C:\Users\myuser\AppData\Local\Temp/5f7bf0bbccaf51.tmp

David Winterburn commented on Oct 6, 2020

Please check content of the file C:\Users\myuser\AppData\Local\Temp/5f7bf0bbccaf51.tmp

Mukesh commented on Oct 6, 2020

Below content in the .tmp file.

<html>
    <body style="margin:1cm"><script  type='text/javascript'  src='/koolreport_assets/2165036260/KoolReport.js'></script>
    HHHHHHHHHHHHHHHHH
    <p>Hello</p>
    <p>Hello</p>
    <p>Hello</p>
    <p>Hello</p>
    <p>Hello</p>
    <p>Hello</p>
    <p>Hello</p>
    <p>Hello</p>
    </body>
</html>
Mukesh commented on Oct 6, 2020

I am waiting for your reply, What i do.

David Winterburn commented on Oct 6, 2020

The content looks good. Please open Handler.php and look for this line:

        $result = shell_exec($command);

and put this just before:

        echo "command=$command<br>"; exit;
        $result = shell_exec($command);

Run export to see the outputted command. Then copy and paste the command to your command line/terminal to see the result. If there's no error message there should be a pdf file in the tmp folder. If there's any error let us know.

Mukesh commented on Oct 6, 2020

Showing result below

command=E:\xampp\htdocs\cs\vendor\koolreport\export/bin/phantomjs.exe --ignore-ssl-errors=true E:\xampp\htdocs\cs\vendor\koolreport\export/pdf/pdf.js C:\Users\username\AppData\Local\Temp/5f7c2512a25631.tmp C:\Users\username\AppData\Local\Temp/5f7c2512a28762.pdf eyJ3aWR0aCI6IjYwMHB4IiwiaGVpZ2h0IjoiNzAwcHgiLCJtYXJnaW4iOnsidG9wIjoiMC41aW4iLCJib3R0b20iOiIwLjVpbiIsImxlZnQiOiIxaW4iLCJyaWdodCI6IjFpbiJ9LCJleHBlY3RlZExvY2F0aW9uIjoiaHR0cDpcL1wvbG9jYWxob3N0OjgwMDBcL2NvbXBsaWFuY2VcL2NlcnRpZmljYXRlIiwicmVzb3VyY2VXYWl0aW5nIjoxMDAwLCJmb3JtYXQiOiJBNCJ9

This command error: command not recognized as internal or external

David Winterburn commented on Oct 6, 2020

Please make sure you downloaded the correct PhantomJS binary file to this path: E:\xampp\htdocs\cs\vendor\koolreport\export/bin/phantomjs.exe from this link:

https://phantomjs.org/download.html

Then try to run this standard example of PhantomJS:

https://phantomjs.org/screen-capture.html

Let us know the result. Thanks!

Mukesh commented on Oct 6, 2020

Hi Did Correct version and i checked with Hello.js example of phantomjs its working fine

David Winterburn commented on Oct 6, 2020

Please use this path in your hello.js example: E:\xampp\htdocs\cs\vendor\koolreport\export/bin/phantomjs.exe

Mukesh commented on Oct 6, 2020

Result is: phantomjs://repl-input:1 in global code

David Winterburn commented on Oct 7, 2020

If you can run PhantomJS example fine, please repeat this step:

https://www.koolreport.com/forum/topics/1639#p8845

Mukesh commented on Oct 7, 2020

When I am running this command PDF file is created with my html content in the temp folder. what i do next.

Mukesh commented on Oct 7, 2020

Hello, I am waiting for reply.

David Winterburn commented on Oct 7, 2020

Please create a file called github.js in your tmp folder with this content:

var page = require('webpage').create();
page.open('http://github.com/', function() {
  page.render('github.png');
  phantom.exit();
});

Then open the command line/terminal and run the following command (remember to change path/to/tmp with your path):

E:\xampp\htdocs\cs\vendor\koolreport\export/bin/phantomjs.exe path/to/tmp/github.js

Let us know the result and post your exact command for us. Thanks!

KoolReport commented on Oct 7, 2020

Thank you Mukesh for chatting with us via Messenger. All are working now. The root cause is that Export package will not work with PHP Built-In Webserver. This built-in webserver is normally started with command php -S or php artisan serve in Laravel. The Export package will work with popular/production webserver like Apache or Nginx. For further details, please look at our post here.

Mukesh commented on Oct 8, 2020

Thank you team for help.

KoolReport commented on Oct 8, 2020

You are welcome :)

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Export