Home Forums Support Attach PDF's to Emails using HTTPS domain

This topic contains 1 reply, has 2 voices, and was last updated by  Hillel Coren 1 year, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #13849

    S.Kennedy
    Participant

    \Greetings,
    For those of you having problems attaching PDF’s to emails on Self Hosted platforms with PhantomJS(2.1.1) installed, these steps helped solved my problems.

    In the case of https://yourdomain.com (I used LetsEncrypt Cert) for Invoice Ninja install:
    Follow the Troubleshooting instructions http://docs.invoiceninja.com/en/latest/configure.html#troubleshooting

    Run the following command line “phantomjs test.js”, if the result is as follows:

    n{
    “contentType”: null,
    “headers”: [],
    “id”: 1,
    “redirectURL”: null,
    “stage”: “end”,
    “status”: null,
    “statusText”: null,
    “time”: “2018-05-06T17:09:10.613Z”,
    “url”: “https://yourdomain.com…”,
    “console”: []

    This means that HTTPS is causing an error, so then add the following option to the command “phantomjs –ignore-ssl-errors=true test.js”, the result should be the raw pdf file (a lot of text).

    Now we need to include this command in Invoice Ninja every time it uses PhantomJS to create the pdf file. To do so go to this location in your install:

    “/YOUR_WEB_ROOT/app/Libraries” and edit the file “CurlUtils.php” as follows (arround line 52)

    BEFORE

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

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

    AFTER

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

    $client = Client::getInstance();
    //************** CUSTOM **************
    $client->getEngine()->addOption(‘–ignore-ssl-errors=true’);
    $client->getEngine()->addOption(‘–ssl-protocol=tlsv1’);
    $client->getEngine()->addOption(‘–web-security=false’);
    //************** CUSTOM **************
    $client->isLazy();
    $client->getEngine()->setPath($path);

    These changes will allow INVOICEs and QUOTEs to be sent using HTTPS domain, for PROPOSALs add the same lines of code to the next fuction

    BEFORE

    public static function renderPDF($url, $filename)
    {
    if (! $path = env(‘PHANTOMJS_BIN_PATH’)) {
    return false;
    }

    $client = Client::getInstance();
    $client->isLazy();

    AFTER

    public static function renderPDF($url, $filename)
    {
    if (! $path = env(‘PHANTOMJS_BIN_PATH’)) {
    return false;
    }

    $client = Client::getInstance();
    //************** CUSTOM **************
    $client->getEngine()->addOption(‘–ignore-ssl-errors=true’);
    $client->getEngine()->addOption(‘–ssl-protocol=tlsv1’);
    $client->getEngine()->addOption(‘–web-security=false’);
    //************** CUSTOM **************
    $client->isLazy();

    Additional:
    Make sure your Invoice Ninja domain in settings contains “https” not “http”

    In your .env file remove or comment out
    “PHANTOMJS_CLOUD_KEY=a-demo-key-with-low-quota-per-ip-address”

    Make sure your “PHANTOMJS_BIN_PATH=THE_INSTALLATION_PATH” run this at command line “which phantomjs” it will return The installation path.
    Also ensure “PHANTOMJS_SECRET=SOME_STRING_TEXT” custom string of your choice.

    And that should be it.
    Thanks.

    #13850

    Hillel Coren
    Keymaster

    Thanks for sharing your solution!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Posted in: