Failed to CreatePDF

Hi,
3.0.2 not create PDF´s with local PhantomJSCloud in log
i found

production.ERROR: PhantomJSCloud - failed to create pdf: {“context”:“PHP”,“user_id”:0,“account_id”:0,“user_name”:"",“method”:“GET”,“url”:“https://blabla.bla”,“user_agent”:"",“ip”:“127.0.0.1”,“count”:1} []

Try changing line 1210 in app/Models/Invoice.php from

} catch (Exception $exception) {

to

} catch (\Exception $exception) {

And then try again and re-check the logs, there may be more details shown about the error.

https://github.com/invoiceninja/invoiceninja/blob/master/app/Models/Invoice.php#L1210

Line 1210 is


Utils::logError("PhantomJSCloud - failed to create pdf: {$pdfString}");

The catch line should be within a few lines.

NO,


    public function getPDFString()
    {
        if ( ! env('PHANTOMJS_CLOUD_KEY') && ! env('PHANTOMJS_BIN_PATH')) {
            return false;
        }

        $invitation = $this->invitations[0];
        $link = $invitation->getLink('view', true);

        if (env('PHANTOMJS_BIN_PATH')) {
            $pdfString = CurlUtils::phantom('GET', $link . '?phantomjs=true');
        } elseif ($key = env('PHANTOMJS_CLOUD_KEY')) {
            if (Utils::isNinjaDev()) {
                $link = env('TEST_LINK');
            }
            $url = "http://api.phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$link}?phantomjs=true%22,renderType:%22html%22%7D";
            $pdfString = CurlUtils::get($url);
        }

        $pdfString = strip_tags($pdfString);

        if ( ! $pdfString || strlen($pdfString) < 200) {
            Utils::logError("PhantomJSCloud - failed to create pdf: {$pdfString}");
            return false;
        }

        return Utils::decodePDF($pdfString);
    }

    /**
     * @param $invoiceItem
     * @param $invoiceTotal
     * @return float|int
     */

Hmm… I guess the try/catch will be added in 3.0.3.

In that case try adding dd($response->getStatus()); at the end of app/Libraries/CurlUtils.php after $client->send().

If you haven’t already you may want to check that the value for PHANTOMJS_BIN_PATH works from the command line.

you mean around line 57


 public static function phantom($method, $url)
    {
        if ( ! $path = env('PHANTOMJS_BIN_PATH')) {
            return false;
        }

        $client = Client::getInstance();
        $client->getEngine()->setPath($path);

        $request = $client->getMessageFactory()->createRequest($url, $method);
        $response = $client->getMessageFactory()->createResponse();

        // Send the request
        $client->lsend($request, $response);
        
        if ($response->getStatus() === 200) {
            return $response->getContent();
        } else {
            //$response->getStatus();
            return false;
        }

    }

Yup, it’d be helpful to know the status (assuming it isn’t 200).