title: Adobe Acrobat API in Python
body: <p><strong>System:</strong></p>
  
  <pre><code>Python 3.6
  Windows 10
  </code></pre>
  
  <p><strong>Goal:</strong>
  <p>Use the Adobe Acrobat API to use the "Save As" feature to save a pdf to jpegs.<p>
  Note: For my purposes I cannot use Wand or other packages.
  <p>
  <strong>Resources:</strong><p>
  <a href="https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FIAC_API_OLE_Objects%2FAcroExch_PDDoc.htm%23IX_AcroExch_PDDoc&amp;rhsearch=com.adobe.acrobat.jpeg" rel="noreferrer">Adobe_API_Documentation</a><p>
  <a href="http://kitchingroup.cheme.cmu.edu/blog/2013/11/23/Automating-Adobe-Acrobat-Pro-with-python/" rel="noreferrer">Implementation_Example 1</a><p>
  <a href="https://www.codesd.com/item/not-implemented-exception-when-using-pywin32-to-control-adobe-acrobat.html" rel="noreferrer">Error_Handling_Issue</a><p>
  <a href="https://www.myengineeringworld.net/2013/03/vba-macro-to-convert-pdf-files-into.html" rel="noreferrer">VBA_Example</a></p>
  
  <p><strong>Current Code:</strong></p>
  
  <pre><code>import winerror
  import win32com
  from win32com.client.dynamic import Dispatch, ERRORS_BAD_CONTEXT
  
  ERRORS_BAD_CONTEXT.append(winerror.E_NOTIMPL)
  
  my_dir = r"path\\to\\example\\"
  my_pdf = "example.pdf"
  
  os.chdir(my_dir)
  src = os.path.abspath(my_pdf)
  
  pdDoc = Dispatch("AcroExch.PDDoc")
  pdDoc.Open(src)
  
  jsObject = pdDoc.GetJSObject()
  
  jsObject.SaveAs(os.path.abspath('./output_example.jpeg'), "com.adobe.acrobat.jpeg")
  </code></pre>
  
  <p><strong>Issue:</strong>
  <p> <em>jsObject</em> is Null
  <p> Resulting in the following traceback:</p>
  
  <pre><code>---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-26-9c82c454eb2a&gt; in &lt;module&gt;()
  ----&gt; 1 jsObject.SaveAs(os.path.abspath('./output_example.jpeg'), "com.adobe.acrobat.jpeg")
  
  AttributeError: 'NoneType' object has no attribute 'SaveAs'
  </code></pre>
  
  <p><strong>Error Documentation Notes:</strong><p></p>
  
  <pre><code>GetJSObject
  Gets a dual interface to the JavaScript object associated with the PDDoc. This allows automation clients full access to both built-in and user-defined JavaScript methods available in the document. For more information on working with JavaScript, see Developing Applications Using Interapplication Communication.
  
  Syntax
  LDispatch* GetJSObject();
  
  Returns
  The interface to the JavaScript object if the call succeeded, NULL otherwise.
  </code></pre>