Answers.Body: <p>I got in touch with Craft support and this was a bug that the Craft Commerce team fixed in Craft v4. They were kind enough to backport the fix to v3. Should work for anyone else moving forward!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-26T03:02:38.533Z
Answers.LastActivityDate: 2024-04-26T03:02:38.533Z
Answers.UserDisplayName: cherrykoda
Answers.Body: <p>According to the error, the issue is that <code>$pdf</code> is null... so maybe the variable name is wrong, or there's some other upstream issue that's causing <code>$pdf</code> to not exist.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-12T00:49:43.127Z
Answers.LastActivityDate: 2024-04-12T00:49:43.127Z
Answers.UserDisplayName: andrew.welch
Body: <p>The error I'm receiving is:
  <code>Call to a member function getRenderLanguage() on null</code></p>
  <p><a href="https://i.sstatic.net/4DqxW.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4DqxW.png" alt="enter image description here" /></a></p>
  <p>My Code (Edit - simplified):</p>
  <pre><code> $mergeService = new Merger();
   $batchFileName = 'VAT-' . $country . ( $date ? '-' . $date : '');
   foreach ($orders as $order) {
     $orderPdf = Commerce::getInstance()-&gt;getPdfs()-&gt;renderPdfForOrder($order, '', null);
     $mergeService-&gt;addRaw($orderPdf);
   }
   $batchPdf = $mergeService-&gt;merge();
  </code></pre>
  
Tags: <craft3><plugin-craftcommerce><modules><plugin-craftcommerce3><pdf>
Title: Error when calling renderPdfForOrder() in Module
ThreadText: # Error when calling renderPdfForOrder() in Module
  
  (Asked by: username_0 on 2024-04-11)
  
  The error I'm receiving is:
  `Call to a member function getRenderLanguage() on null`
  
  [![enter image description here](https://i.sstatic.net/4DqxW.png)](https://i.sstatic.net/4DqxW.png)
  
  My Code (Edit - simplified):
  
  ```
   $mergeService = new Merger();
   $batchFileName = 'VAT-' . $country . ( $date ? '-' . $date : '');
   foreach ($orders as $order) {
     $orderPdf = Commerce::getInstance()->getPdfs()->renderPdfForOrder($order, '', null);
     $mergeService->addRaw($orderPdf);
   }
   $batchPdf = $mergeService->merge();
  
  ```
  
  **Tags:** craft3, plugin-craftcommerce, modules, plugin-craftcommerce3, pdf
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2024-04-26. Score: 0 | Accepted answer
  
  I got in touch with Craft support and this was a bug that the Craft Commerce team fixed in Craft v4. They were kind enough to backport the fix to v3. Should work for anyone else moving forward!
  
  
  ---
  
  ### Answer by username_1 on 2024-04-12. Score: 1
  
  According to the error, the issue is that `$pdf` is null... so maybe the variable name is wrong, or there's some other upstream issue that's causing `$pdf` to not exist.
  
  
  ---
  
  