Support » Plugin: Gravity PDF » PDF Not Attaching

  • Resolved AvalonMel


    I’ve created my own template and tested it using the test url and it displays great. It seemed that no matter what code I changed I couldn’t actually get it to trigger when I submitted my form, so I renamed my template to example-template.php Now when I submit my form the PDF is generated and stored on the server and an email is sent to the admin, but the PDF doesn’t attach to the email. Help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Jake Jackson



    Have you followed the instructions on setting up the plugin, including notifications, here:

    You’ll also need to enable notifications in your form.

    Let me know if you have any problems.

    Yes, I followed those directions but it’s not working. Well…it’s saving, but not attaching. I changed if($form_id == 1) to if($form_id == 4) [the id of my form] but nothing. Are there any other variables I need to change?

    I’ve compared the Notifications screen of my form to that of the example form and they’re identical. I’ve also compared the form settings. Identical.

    This is the code I’ve added to my theme’s functions.php

    function gform_pdf_create($entry, $form)
        $user_id = $entry['id'];
        $form_id = $entry['form_id'];
        /* only output PDF if the $form_id matches */
    	/* 4 is the ID for the second half of the contract */
        if($form_id == 4)
            /* include the pdf processing file */
           require PDF_PLUGIN_DIR.'render_to_pdf.php';
            /* generate and save default PDF */
            //$filename = PDF_Generator($form_id, $user_id, 'save', true);
            /* comment out the above line and uncomment the line below if you want to use a custom template */
           $filename = PDF_Generator($form_id, $user_id, 'save', true, 'example-template.php', 'EasternEdgePolicyContract.pdf');
    add_action("gform_entry_created", "gform_pdf_create", 10, 2);


    function gform_add_attachment($attachments, $lead, $form){
        $form_id = $lead['form_id'];
        $user_id = $lead['id'];
        $attachments = array();
        $folder_id = $form_id.$user_id.'/';
     	/* 4 is the ID of the second half of the contract */
        if($form_id == 4)
            /* include PDF converter plugin */
            include PDF_PLUGIN_DIR.'render_to_pdf.php';
            //$attachment_file = PDF_SAVE_LOCATION. $folder_id . get_pdf_filename($form_id, $user_id);
            $attachment_file = PDF_SAVE_LOCATION. $folder_id . 'FormName.pdf';
            $attachments[] = $attachment_file;
        return $attachments;
    /* add attachment to both the admin and user notification */
    add_filter("gform_admin_notification_attachments", 'gform_add_attachment', 10, 3);
    add_filter("gform_user_notification_attachments", 'gform_add_attachment', 10, 3);

    Can you help any more?

    Plugin Author Jake Jackson


    Hi Mel,

    You’re using a custom template name but forgot to tell the attachment function to use the new name.

    Change $attachment_file = PDF_SAVE_LOCATION. $folder_id . 'FormName.pdf'; to $attachment_file = PDF_SAVE_LOCATION. $folder_id . 'EasternEdgePolicyContract.pdf'; and you should be fine.

    Thanks! Figures it was a simple oversight. Now… do you know if there’s anyway to access that PDF from a browser after it’s been generated? The URL is giving me a 404 even though I can see the file on the server. I need to open up the PDF so that the user can print it (through the website, not through their email program).

    Plugin Author Jake Jackson


    PDFs on the server are protected via the .htaccess file to stop unwanted people downloading the PDFs. The most secure way to do it is to generate the PDF automatically. There’s a description on how to do this in our FAQs:

    That’s close to what I was doing (using $_GET to get the form and entry ID to build the url) but that will make all the difference. Thanks again!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘PDF Not Attaching’ is closed to new replies.