# Automatically Assign GravityPDF \[RESOLVED\]

**URL:** <https://community.gravityforms.com/t/automatically-assign-gravitypdf-resolved/17627>\
**Category:** Get Help\
**Tags:** gravitypdf, gpdfapi\
**Created:** [June 6, 2024, 7:15pm UTC](https://community.gravityforms.com/t/automatically-assign-gravitypdf-resolved/17627 "2024-06-06T19:15:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user640f07280bb7c404](https://avatars.discourse-cdn.com/v4/letter/u/8edcca/32.png) [@user640f07280bb7c404](https://community.gravityforms.com/u/user640f07280bb7c404)\
**Post date:** [June 6, 2024, 7:15pm UTC](https://community.gravityforms.com/t/automatically-assign-gravitypdf-resolved/17627/1 "2024-06-06T19:15:46Z")

</div>

With GravityPDF is there a way to automatically add a PDF to every form created by default, rather than having to manually add a PDF each time?

---

<div class="post-metadata">

**Author:** ![user640f07280bb7c404](https://avatars.discourse-cdn.com/v4/letter/u/8edcca/32.png) [@user640f07280bb7c404](https://community.gravityforms.com/u/user640f07280bb7c404)\
**Post date:** [June 6, 2024, 10:39pm UTC](https://community.gravityforms.com/t/automatically-assign-gravitypdf-resolved/17627/2 "2024-06-06T22:39:19Z")

</div>

Just in case anyone has the need to do the same in future, the following snippet will auto add PDF’s to existing and new Gravity Forms.

```auto
add_action( 'init', function() {
	
    if ( class_exists( 'GPDFAPI' ) ) {

        // change $settings to reflect your Form Name and the template you're using

        $settings = array(
            'name' => 'Form Name',
            'template' => 'template-name',
            'filename' => 'File-Name',
        );

       // Gets all Gravity Forms
		
		$forms = GFAPI::get_forms();

      // Loops through each Gravity Form
		
		foreach($forms as $form) {

         // $pdfexists = 0 each loop
			
		$pdfexists = 0;

        // Gets Gravity Form Id
			
		$form_id = rgar( $form, 'id' );

               // Gets all PDFS for the Gravity Form
			
		$pdfs = GPDFAPI::get_form_pdfs( $form_id );

		foreach ( $pdfs as $pdf ) {

              // Loops through all PDFS and if PDF already exists then exits loop
			 
        if ( $pdf['name'] === $settings['name'] ) { $pdfexists = 1; break 1;}
		
		 }

            // If the PDF does not already exist, add PDF
			
		if ($pdfexists != 1) { $pdf = GPDFAPI::add_pdf( $form_id, $settings ); }
			
	}
    }
	});

```

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [June 29, 2024, 2:36am UTC](https://community.gravityforms.com/t/automatically-assign-gravitypdf-resolved/17627/3 "2024-06-29T02:36:50Z")

</div>

Closed on June 29, 2024, 2:36am UTC


