• Resolved corrinarusso

    (@corrinarusso)


    Hi all! Can someone please show me how to load my CSS file from my php template?

    My template has over 600 lines of CSS, so I’m just trying to clean it up a bit.

    I have already tried this:

    https://docs.gravitypdf.com/v6/developers/filters/gfpdf_include_list_styles

    and this:

    $stylesheet = file_get_contents(‘assets/mpdfstylePaged.css’);
    $mpdf->WriteHTML($stylesheet,1); // The parameter 1 tells that this is css/style only and no body/html/text

    without success.

    Thanks! Corrie

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter corrinarusso

    (@corrinarusso)

    Of course, as soon as I posted here I implemented the soltion.

    ??

    I’ll leave this here if anyone else was looking for the solution, just add the usual link rel in your php template file, and include the full path to the file, i.e.:

    <link rel=”stylesheet” href=”/wp-content/uploads/PDF_TEMPLATE/file_name_template.php” />

    Plugin Author Jake Jackson

    (@blue-liquid-designs)

    Glad you were able to find a solution @corrinarusso.

    The PDF engine Gravity PDF uses supports the loading of stylesheets over HTTP(S) or loading directly form the file system. The latter option is faster, as it’s one less network request to make:

    <!-- Load stylesheet over the internet (slower) -->
    <link rel="stylesheet" />

    <!-- Use a relative path loads the stylesheet over the internet (slower) -->
    <link rel="stylesheet" href="/wp-content/uploads/PDF_EXTENDED_TEMPLATES/my-stylesheet.css" />

    <!-- Load stylesheet directly from the server (faster) -->
    <link rel="stylesheet" href="<?php echo esc_attr( __DIR__ . '/my-stylesheet.css' )" />

    If you still need PHP in the stylesheet file so you can conditionally apply CSS based on form data, you can always include the PHP file:

    <style>
    <?php include __DIR__ . '/my-stylesheet.php'; ?>
    </style>

    For anyone else interested in this topic, this code goes in your custom PDF template.

    • This reply was modified 4 months, 2 weeks ago by Jake Jackson. Reason: Include example of loading the stylesheet with a relative path, which still uses a network request
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.