### Install Gravity PDF Extensions with Composer Source: https://docs.gravitypdf.com/v6/extensions/installing-upgrading-extensions These are example Composer commands to install various Gravity PDF extensions. After configuring the repository and authentication, run these commands in your project's CLI to add the desired extensions. Ensure you have the correct license keys for each extension if installing multiple individually. ```bash composer require gravitypdf/gravity-pdf-bulk-generator composer require gravitypdf/gravity-pdf-core-booster composer require gravitypdf/gravity-pdf-enhanced-download composer require gravitypdf/gravity-pdf-previewer composer require gravitypdf/gravity-pdf-reports-for-gfchart composer require gravitypdf/gravity-pdf-watermark composer require gravitypdf/pdf-for-gravityview ``` -------------------------------- ### PHP: Set up and tear down Gravity PDF template files Source: https://docs.gravitypdf.com/v6/developers/template-configuration-and-image The setUp() method is used to install custom fonts when a template is installed, and the tearDown() method cleans up additional template-related files when the template is deleted. This example demonstrates adding a custom font and removing an installation directory. ```php 'Fira Sans', 'regular' => __DIR__ . '/../install/Hello_World/font-fira-sans/FiraSans-Regular.ttf', 'italics' => __DIR__ . '/../install/Hello_World/font-fira-sans/FiraSans-Italic.ttf', 'bold' => __DIR__ . '/../install/Hello_World/font-fira-sans/FiraSans-SemiBold.ttf', 'bolditalics' => __DIR__ . '/../install/Hello_World/font-fira-sans/FiraSans-SemiBoldItalic.ttf', ]; \GPDFAPI::add_pdf_font( $font_data ); } /** * Runs when the template is deleted via the PDF Template Manager * * @Internal Great for cleaning up any additional directories */ public function tearDown() { $misc = \GPDFAPI::get_misc_class(); /* Cleanup files */ $misc->rmdir( __DIR__ . '/../install/Hello_World' ); } /** * Return the templates configuration structure which controls what extra fields will be shown in the "Template" section when configuring a form's PDF. * * @return array The array, split into core components and custom fields */ public function configuration() { return [ /* Enable core fields */ 'core' => [ ], /* Create custom fields to control the look and feel of a template */ 'fields' => [ ], ]; } } ``` -------------------------------- ### Diagnose Composer 401 Errors with cURL Source: https://docs.gravitypdf.com/v6/extensions/installing-upgrading-extensions This snippet demonstrates how to use cURL to test Composer authentication. Replace the example credentials with your actual username and password from your auth.json file to get a detailed error message from the API, which can help identify license activation problems. ```shell # Replace the username and password with the values in your auth.json file curl --user "https://example.com:NpMmzRwVpkudnXQRfuEdk7wEi2W88Fz6" https://composer.gravitypdf.com/gravity-pdf-bulk-generator-2.0.0.zip ``` -------------------------------- ### Example composer.json for WordPress Project with Gravity PDF Source: https://docs.gravitypdf.com/v6/users/installation This example demonstrates a complete composer.json file for a WordPress project that includes the Gravity PDF plugin. It configures repositories (including wpackagist and Gravity PDF's own), allows plugins like composer/installers, and specifies PHP and plugin requirements. ```json { "name": "acme/wordpress-website", "type": "project", "config": { "allow-plugins": { "composer/installers": true } }, "repositories": [ { "type": "composer", "url": "https://wpackagist.org", "only": [ "wpackagist-plugin/*", "wpackagist-theme/*" ] }, { "type": "composer", "url": "https://composer.gravitypdf.com", "only": [ "gravitypdf/*" ] } ], "require": { "php": "^8.3", "wpackagist-plugin/two-factor": "^0.9", "gravitypdf/gravity-pdf": "^6.12" } } ``` -------------------------------- ### Hook into Gravity PDF Plugin Installation (PHP) Source: https://docs.gravitypdf.com/v6/developers/actions/gfpdf_plugin_installed This action hook executes only when the Gravity PDF plugin is activated for the first time. It's suitable for running one-time setup routines or checks that should only occur upon initial installation. No specific input parameters are provided. ```php add_action( 'gfpdf_plugin_installed', function() { /* Run any one-time checks you need to */ } ); ``` -------------------------------- ### Example of Invoice Due Date Calculation Source: https://docs.gravitypdf.com/v6/templates/invoice-vertex Illustrates how the 'Invoice Due Date' setting calculates the due date based on the form submission date and a specified number of days. This is a conceptual example. ```text If form submission date is `2024-11-29` and due date setting is `7` days, the invoice would be due on `2024-12-06`. ``` -------------------------------- ### Get WordPress Installation Path (ABSPATH) Source: https://docs.gravitypdf.com/v6/developers/helper-parameters The `ABSPATH` WordPress constant represents the root directory of your WordPress installation. While less commonly used for template assets compared to other methods, it can be utilized to reference files located in the WordPress root. ```php ``` -------------------------------- ### PHP PDF Template Header Example Source: https://docs.gravitypdf.com/v6/developers/first-custom-pdf This is a valid PDF template header example for Gravity PDF. It includes essential metadata such as Template Name, Version, Description, Author, Group, License, and Required PDF Version, along with optional Tags for better searchability within the PDF Template Manager. ```php /** * Template Name: Zadani * Version: 1.2 * Description: A minimalist business-style template that will generate a well-spaced document great for printing. Through the Template tab, you can control the PDF header and footer, change the background color or image, and show or hide the form title, page names, HTML fields and the Section Break descriptions. * Author: Gravity PDF * Author URI: https://gravitypdf.com * Group: Core * License: GPLv2 * Required PDF Version: 4.0 * Tags: Header, Footer, Background, Optional HTML Fields, Optional Page Fields, Container Background Color */ ``` -------------------------------- ### Ansible Deployment Hook for Gravity PDF Core Fonts Source: https://docs.gravitypdf.com/v6/users/core-pdf-fonts This Ansible task automates the download and synchronization of Gravity PDF's Core Fonts during a Trellis deployment. It clones the font repository and uses rsync to move the files to the appropriate directory within the web application. Ensure the `dest` path is correctly configured for your specific project setup. ```yaml --- # Download and sync core Gravity PDF fonts - git: repo: 'https://github.com/GravityPDF/mpdf-core-fonts' dest: "{{ deploy_helper.shared_path }}/mpdf-core-fonts" version: master force: yes - synchronize: src: "{{ deploy_helper.shared_path }}/mpdf-core-fonts/" dest: "{{ deploy_helper.new_release_path }}/web/app/PDF-Templates/fonts" rsync_opts: - "--exclude=.git" delegate_to: "{{ inventory_hostname }}" ``` -------------------------------- ### Gravity PDF Shortcode Examples Source: https://docs.gravitypdf.com/v6/users/shortcodes-and-mergetags Examples of using the Gravity PDF shortcode with and without an entry ID. The entry ID can be specified directly or via a URL parameter. If no entry ID is provided, it can be inferred from URL parameters like 'entry' or 'lid'. ```shortcode [gravitypdf id="560f2ef799945" entry="250"] [gravitypdf id="560f2ef799945"] ``` -------------------------------- ### Install Gravity PDF using WP-CLI Source: https://docs.gravitypdf.com/v6/users/installation This WP-CLI command installs and activates the Gravity PDF plugin directly from a provided URL. It's a convenient method for developers who manage their WordPress sites using the command line interface. ```bash wp plugin install https://gravitypdf.com/download-gravity-pdf --activate ``` -------------------------------- ### Install Gravity PDF Plugin using Composer Source: https://docs.gravitypdf.com/v6/users/installation This command installs the Gravity PDF plugin into your project using Composer. It assumes the Composer repository has already been added to your composer.json file. This method is recommended for developers for streamlined dependency management. ```bash composer require gravitypdf/gravity-pdf ``` -------------------------------- ### Trellis: Override deploy_build_after Hook Source: https://docs.gravitypdf.com/v6/users/core-pdf-fonts This configuration snippet for Trellis shows how to override the default `deploy_build_after` hook to include a custom deployment script. This is necessary for integrating custom deployment tasks, such as installing Gravity PDF Core Fonts, into the deployment process. Add the custom hook file to the `deploy_build_after` list. ```yaml # Overriding a hook that Trellis already uses by default default_deploy_build_after: - "{{ playbook_dir }}/roles/deploy/hooks/build-after.yml" - "{{ playbook_dir }}/deploy-hooks/build-after.yml" # add this line ``` -------------------------------- ### Configure Composer Authentication for Gravity PDF Source: https://docs.gravitypdf.com/v6/extensions/installing-upgrading-extensions This configuration is used to set up authentication for the Gravity PDF Composer repository. It requires a username (your site URL) and a password (your license key) to ensure only valid customers can install extensions. Replace placeholders with your actual site URL and license key. ```json { "http-basic": { "composer.gravitypdf.com": { "username": "https://{WORDPRESS_HOME_URL}", "password": "{LICENSE_KEY}" } } } ``` ```json { "http-basic": { "composer.gravitypdf.com": { "username": "https://example.com", "password": "gravity-pdf-core-booster@NpMmzRwVpkudnXQRfuEdk7wEi2W88Fz6, gravity-pdf-previewer@6NZMdPGmwUTgzfUh6qmfVgGp4kZA7jQ4" } } } ``` -------------------------------- ### HTML Examples for CSS Border Radius Source: https://docs.gravitypdf.com/v6/developers/pdf-features/rounded-corners Provides various HTML examples illustrating the application of CSS border-radius for styling PDF templates. These examples showcase standard rounding, larger corners, single corner rounding, creating circles, and controlling horizontal/vertical radii independently. ```html
``` -------------------------------- ### Add Gravity PDF Composer Repository Source: https://docs.gravitypdf.com/v6/extensions/installing-upgrading-extensions This JSON snippet is added to your `composer.json` file to specify the Gravity PDF Composer repository URL. This allows Composer to find and download Gravity PDF packages. The `only` key ensures this repository is only used for packages starting with `gravitypdf/`. ```json { "repositories": [ { "type": "composer", "url": "https://composer.gravitypdf.com", "only": [ "gravitypdf/*" ] } ] } ``` -------------------------------- ### Valid Cascading CSS Examples in mPDF Source: https://docs.gravitypdf.com/v6/developers/pdf-features/supported-html-and-css Provides examples of valid cascading CSS selectors that mPDF supports. These demonstrate how to apply styles based on element relationships, including nested elements and combinations of element types with classes or IDs. These are effective for styling block-level elements. ```css div.topic table td {...} div #my-id {...} table tr {...} div p.my-class {...} ``` -------------------------------- ### Disable/Enable Gravity PDF Enhanced Download with JavaScript Source: https://docs.gravitypdf.com/v6/extensions/enhanced-download-add-on Developers can programmatically control the Enhanced Download overlay using custom JavaScript events. Dispatch 'gpdfEdOverlayStatus' with 'false' to disable or 'true' to re-enable the feature, including its associated cookie. ```javascript // Disable the Enhanced Download functionality (including the first-party cookie) const overlayDisableEvent = new CustomEvent('gpdfEdOverlayStatus', {detail: false}); document.getElementById('c-gpdf-pretty-download-ui').dispatchEvent(overlayDisableEvent); // Re-enable the Enhanced Download functionality const overlayEnableEvent = new CustomEvent('gpdfEdOverlayStatus', {detail: true}); document.getElementById('c-gpdf-pretty-download-ui').dispatchEvent(overlayEnableEvent); ``` -------------------------------- ### CSS Variables for Enhanced Download Overlay Source: https://docs.gravitypdf.com/v6/extensions/enhanced-download-add-on These CSS variables control the colors and background of the Enhanced Download overlay. They can be overridden in your theme's CSS to customize the appearance. Default values are provided for text, shadow, focus, and background. ```css :root { --gpdf-addon-ed-overlay-color: #fff; --gpdf-addon-ed-overlay-text-shadow-color: #0a0e14; --gpdf-addon-ed-overlay-focus-color: #efe108; --gpdf-addon-ed-overlay-background: rgba(0, 0, 0, 0.85) radial-gradient(rgba(255, 255, 255, 0.25), rgba(0, 0, 0, 0.75)); } ``` -------------------------------- ### Configure Product/Shipping Tax Rates with CSS Classes Source: https://docs.gravitypdf.com/v6/templates/invoice-aurora Customize tax rates for individual products or shipping by applying specific CSS classes to form fields. This allows for granular tax control beyond the default settings. The format is `tax-{rate}-{label}`, where `{rate}` is a percentage and `{label}` is the tax name. ```html ``` -------------------------------- ### Enable Tax Inclusive Pricing with Custom Tax Rates Source: https://docs.gravitypdf.com/v6/templates/invoice-vertex This describes how to enable tax-inclusive pricing and apply specific tax rates to products or shipping using custom CSS classes. The format `tax-{rate}-{label}` allows for precise tax configuration per item, where {rate} is a percentage and {label} is the tax name. Taxes can be disabled per product using `tax-0`. ```css .tax-5\.25-CA-Taxes { } ``` ```css .tax-0 { } ``` -------------------------------- ### Change Specific Field Label with gfpdf_field_label (PHP) Source: https://docs.gravitypdf.com/v6/developers/filters/gfpdf_field_label Modify the label for an individual field using its ID with the gfpdf_field_label filter. This example targets field ID 20. Ensure Gravity Forms and Gravity PDF are installed. ```php add_filter( 'gfpdf_field_label', function( $label, $field, $entry ) { if( $field->id === 20 ) { return 'Field #20 Label'; } return $label; }, 10, 3 ); ``` -------------------------------- ### Basic Background Image Implementation Source: https://docs.gravitypdf.com/v6/developers/pdf-features/backgrounds Demonstrates how to include background images using standard CSS properties like `background`, `background-image`, `background-repeat`, and `background-position`. It shows how to control image display and fit within containers. Currently, multiple background images per container are not supported. ```html
This is my content
This is my content
This is my content
This is my content
This is my content
This is my content
``` -------------------------------- ### Get PDF Working Directory Path (PDF_TEMPLATE_LOCATION) Source: https://docs.gravitypdf.com/v6/developers/helper-parameters The `PDF_TEMPLATE_LOCATION` constant holds the file path to the PDF working directory, including specific paths for multisite installations. While available, using `__DIR__` is generally preferred for referencing local assets. -------------------------------- ### PDF for GravityView API - create_single_entry_pdf() Source: https://docs.gravitypdf.com/v6/extensions/api/pdfgv/create-single-entry-pdf Generates a temporary Single Entry View PDF. It can either save the PDF to disk, returning its absolute path, or stream it directly to the user's browser. Note that when saving, the PDF is cached for up to 12 hours and should be manually deleted if immediate cleanup is required. This method can only be used after the WordPress 'init' hook has run. ```APIDOC ## POST /websites/gravitypdf_v6/api/create_single_entry_pdf ### Description Generates a temporary PDF for a single GravityView entry. The PDF can be saved to disk (returning the file path) or streamed to the browser. Caching is enabled for saved PDFs (up to 12 hours), requiring manual deletion if needed. This method requires the WordPress 'init' hook to have run. ### Method POST ### Endpoint /websites/gravitypdf_v6/api/create_single_entry_pdf ### Parameters #### Query Parameters - **view_id** (integer) - Required - The GravityView ID (Post ID) for the View. - **entry_id** (string | integer) - Required - A Gravity Forms entry ID valid for the current View. Can be a comma-separated string for multiple entries if the Multiple Forms Extension is enabled. - **output_type** (string) - Optional - Valid values: `download`, `display`, `save`. Defaults to `save`. ### Request Example ```json { "view_id": 120, "entry_id": 20, "output_type": "save" } ``` ### Response #### Success Response (200) - **string** - The full path to the generated PDF on success if output_type is 'save'. If output_type is 'download' or 'display', the PDF is streamed and the execution exits. #### Error Response - **WP_Error** - Returned on failure. #### Response Example ```json { "path": "/path/to/your/temp/pdf/file.pdf" } ``` ``` -------------------------------- ### Useful Paths and URLs for PDF Template Development Source: https://docs.gravitypdf.com/v6/developers/helper-parameters Constants and functions providing paths and URLs essential for referencing assets like images and stylesheets within your custom PDF templates. ```APIDOC ## Useful Paths and URLs for PDF Template Development ### Description Provides details on PHP constants and WordPress functions that help in referencing directories and files within custom PDF templates, ensuring correct paths for assets like images and stylesheets. ### Method N/A (These are constants and functions used within PHP template files) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Key PHP Constants and Functions: #### `__DIR__` * **Description**: A PHP magic constant that returns the absolute path to the current file. Recommended for referencing local images and PHP files. * **Usage**: `` #### `PDF_TEMPLATE_LOCATION` * **Description**: A constant containing the path to the PDF working directory (or multisite working directory). `__DIR__` is generally recommended over this. * **Usage**: `` #### `PDF_TEMPLATE_URL_LOCATION` * **Description**: A constant containing the URL to the PDF working directory (or multisite working directory). Useful for providing links to files on the host machine. * **Usage**: `View Sample` #### `wp_upload_dir()` * **Description**: A WordPress function that returns an array with path and URL information about the WordPress uploads directory. * **Usage**: ` ` #### `ABSPATH` * **Description**: A WordPress constant referencing the root directory where WordPress is installed. Less commonly used for storing template assets. * **Usage**: `` ``` -------------------------------- ### Access Gravity PDF Misc Class and Check Admin Page (PHP) Source: https://docs.gravitypdf.com/v6/developers/api/get_misc_class This snippet demonstrates how to get the Gravity PDF misc class object using GPDFAPI::get_misc_class() and check if the current page is a Gravity PDF admin page with the is_gfpdf_page() method. It requires the Gravity PDF plugin to be installed and active. ```php add_action( 'init', function() { if ( class_exists( 'GPDFAPI' ) ) { /* Get Gravity PDF misc class */ $misc = GPDFAPI::get_misc_class(); /* Check if we are on a Gravity PDF admin page */ if ( $misc->is_gfpdf_page() ) { //load scripts or styles on the Gravity PDF admin page here } } } ); ``` -------------------------------- ### Get All Gravity Forms PDFs (PHP) Source: https://docs.gravitypdf.com/v6/developers/api/get_form_pdfs Retrieves all configured PDFs for a specific Gravity Form and iterates through them to display their names. This example demonstrates checking for the existence of the GPDFAPI class and handling potential errors from the API call. It's useful for dynamically listing available PDF forms associated with a Gravity Form. ```php add_action( 'init', function() { if ( class_exists( 'GPDFAPI' ) ) { /* Get a list of PDFs assigned to form #2 */ $pdfs = GPDFAPI::get_form_pdfs( 2 ); if ( ! is_wp_error( $pdfs ) && sizeof( $pdfs ) > 0 ) { echo ''; } } } ); ``` -------------------------------- ### Add HTML to Specific Form's PDF Invoices (PHP) Source: https://docs.gravitypdf.com/v6/templates/hooks/invoices/gfpdf-pre-invoice-html This snippet shows how to conditionally add custom HTML content to the start of PDF Invoices, but only for a specific form. It checks the form ID within the provided arguments and returns early if the ID does not match the target form (ID 20 in this example). ```php add_action( 'gfpdf_pre_invoice_html', function( $args ) { if ( (int) ( $args['form']['id'] ?? 0 ) !== 20 ) { return; } ?>

A paragraph of text to be included at the start of every PDF Invoice for a specific form.

` tag, get its file path, URL, and dimensions. The example also includes a check to ensure the image file exists before attempting to display it, preventing broken image icons. ```php /* * 39 is the ID of our field * The signature details isn't in the 'field' sub-key */ echo wp_kses_post( $form_data['signature_details_id'][39]['img'] ); /* a HTML tag that includes the signature */ echo esc_html( $form_data['signature_details_id'][39]['path'] ); /* the full path to the signature */ echo esc_html( $form_data['signature_details_id'][39]['url'] ); /* the URL to the signature */ echo esc_html( $form_data['signature_details_id'][39]['width'] ); /* the signature width in pixels */ echo esc_html( $form_data['signature_details_id'][39]['height'] ); /* the signature height in pixels */ /* Output signature if it exists (this prevents a red X showing up in the PDF when the image doesn't exist) */ if ( is_file( $form_data['signature_details_id'][39]['path'] ) ) { echo ''; /* best to use the path to reference the image and check it exists on the server first */ } ``` -------------------------------- ### Initialize Plugin on gfpdf_fully_loaded Action (PHP) Source: https://docs.gravitypdf.com/v6/developers/actions/gfpdf_fully_loaded This code snippet demonstrates how to use the `gfpdf_fully_loaded` action hook to initialize a custom Gravity PDF plugin. It assumes the existence of a `Prefix_Custom_Gravity_PDF_Plugin` class with an `init` method. The hook passes the `GFPDFRouter` object, allowing access to helper classes. ```php add_action( 'gfpdf_fully_loaded', 'prefix_intialise_custom_plugin' ); /** * We haven't used a closure like in all the other examples because your plugin could initially be run on PHP 5.2. * However, the `gfpdf_fully_loaded` action doesn't fire if the Gravity PDF minimum requirements are not met * so if you create your Prefix_Custom_Gravity_PDF_Plugin class in a separate file and include it during this hook (or use an autoloader) you can happily * use PHP 5.4 code without causing any problems. */ function prefix_intialise_custom_plugin( $gfpdf ) { /* Initialise your plugin here */ require_once( __DIR__ . '/Prefix_Custom_Gravity_PDF_Plugin.php' ); $prefix_custom_plugin = new Prefix_Custom_Gravity_PDF_Plugin(); $prefix_custom_plugin->init(); } ``` -------------------------------- ### Troubleshoot PDF Generation Errors with Gravity Forms Logging Source: https://docs.gravitypdf.com/v6/extensions/enhanced-download-add-on If the loading indicator shows an error during PDF download, enable Gravity Forms logging to diagnose the cause. Check the log file for 'ERROR' messages to identify authentication or generation issues. This helps pinpoint specific files, functions, or line numbers triggering the error. ```text ERROR --> PDF Authentication Failure ERROR --> PDF Generation Error. ``` -------------------------------- ### Accessing Gravity PDF API Methods Source: https://docs.gravitypdf.com/v6/developers/api/whats-it-for Demonstrates how to call static methods from the GPDFAPI class to interact with the Gravity PDF API. This is the primary way to access the API's functionalities. ```php ``` -------------------------------- ### Output Content on PDF Help Settings Page (PHP) Source: https://docs.gravitypdf.com/v6/developers/actions/gfpdf_post_help_settings_page This snippet demonstrates how to use the 'gfpdf_post_help_settings_page' action hook to display custom HTML content at the end of the PDF Help Settings tab. The content appears before the Uninstaller section due to the priority of 3. No external dependencies are required beyond Gravity PDF. ```php add_action( 'gfpdf_post_help_settings_page', function() { /* We set the action priority to 3 so this content will be included before the Uninstaller */ ?>

Remote request error for https://resources.gravitypdf.com/logo.png: "http_request_not_executed: User has blocked requests through HTTP." ``` -------------------------------- ### Gravity PDF Shortcode Raw Attribute Source: https://docs.gravitypdf.com/v6/users/shortcodes-and-mergetags Example of using the 'raw' attribute with the Gravity PDF shortcode. This attribute displays a URL to the PDF instead of generating a direct link to it. ```shortcode [gravitypdf id="560f2ef799945" raw="1"] ```