<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Save word doc as PDF in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399091#M31475</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The errors are COM related (i.e. not directly related to Python), are they the exact same errors on every machine you test them on?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Both errors mention this file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'C:\\Program Files\\Microsoft Office\\Office12\\1033\\WDMAIN11.CHM'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is it (my computer doesn't have it)? Can you open or read it? From memory .CHM files are a kind of help file...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 01 Feb 2012 18:23:12 GMT</pubDate>
    <dc:creator>StacyRendall1</dc:creator>
    <dc:date>2012-02-01T18:23:12Z</dc:date>
    <item>
      <title>Save word doc as PDF</title>
      <link>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399090#M31474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a problem I am hoping someone can help with. I've written a script that opens a word doc, populates several bookmarks, then saves to PDF and closes. It runs beautifully on my machine, however, I have been unable to get it to work anywhere else. The problem appears to be with the line of code that saves my document to pdf having stripped out this section to test by itself. I have tried both win32client and comtypes. Both give me a similar error, but for the life of me I have no idea what the error means.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the win32client code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, os, string, win32com.client&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;wdFormatPDF = 17&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;OUTPATH = str(arcpy.GetParameterAsText(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create table of Contents&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_TOC = OUTPATH + r"\Table of Contents.pdf"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Start Word Application&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;app = win32com.client.Dispatch("Word.Application")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;app.visible = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TABLEOFCONTENTS = "C:\\Files\\Table of Contents.dotx"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;doc = app.Documents.Open(TABLEOFCONTENTS)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;doc.SaveAs(out_TOC, FileFormat=wdFormatPDF)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;doc.Close()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;app.Quit()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files\Hurricane Tools\Scripts\CreateAffectedAreaMaps.py", line 17, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doc.SaveAs(out_TOC, FileFormat=wdFormatPDF)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;COMObject Open&amp;gt;", line 8, in SaveAs&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Word', u'Command failed', u'C:\\Program Files\\Microsoft Office\\Office12\\1033\\WDMAIN11.CHM', 36966, ), None)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;comtypes code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, os, string, comtypes.client&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;wdFormatPDF = 17&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;OUTPATH = str(arcpy.GetParameterAsText(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create table of Contents&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_TOC = OUTPATH + r"\Table of Contents.pdf"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Start Word Application&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;app = comtypes.client.CreateObject('Word.Application')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;app.visible = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TABLEOFCONTENTS = "C:\\Files\\Table of Contents.dotx"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;doc = app.Documents.Open(TABLEOFCONTENTS)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;doc.SaveAs(out_TOC, FileFormat=wdFormatPDF)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;doc.Close()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;app.Quit()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;comtypes error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files\Hurricane Tools\Scripts\comtypesdoctopdf.py", line 17, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doc.SaveAs(out_TOC, FileFormat=wdFormatPDF)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;COMError: (-2146824090, None, (u'Command failed', u'Microsoft Word', u'C:\\Program Files\\Microsoft Office\\Office12\\1033\\WDMAIN11.CHM', 36966, None))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Like I said, it runs perfectly on my system, but on an identical system (identical in that we are running the same versions of Arc, python, and word) it does not. Any clue what those errors are?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2012 17:21:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399090#M31474</guid>
      <dc:creator>JohnLay</dc:creator>
      <dc:date>2012-02-01T17:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Save word doc as PDF</title>
      <link>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399091#M31475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The errors are COM related (i.e. not directly related to Python), are they the exact same errors on every machine you test them on?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Both errors mention this file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'C:\\Program Files\\Microsoft Office\\Office12\\1033\\WDMAIN11.CHM'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is it (my computer doesn't have it)? Can you open or read it? From memory .CHM files are a kind of help file...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2012 18:23:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399091#M31475</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2012-02-01T18:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Save word doc as PDF</title>
      <link>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399092#M31476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have that file (Office '07), but it's 0 bytes.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2012 18:26:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399092#M31476</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-02-01T18:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: Save word doc as PDF</title>
      <link>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399093#M31477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Instead of having a dependacy on MS Word, you can use &lt;/SPAN&gt;&lt;A href="http://www.reportlab.com/software/opensource/"&gt;reportlab&lt;/A&gt;&lt;SPAN&gt; or you can try docx module found &lt;/SPAN&gt;&lt;A href="http://pypi.python.org/pypi/docx/0.1.2"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;docx will create a MS Word document and reportlab will allow you to create the PDF documents.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Feb 2012 10:04:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399093#M31477</guid>
      <dc:creator>AndrewChapkowski</dc:creator>
      <dc:date>2012-02-02T10:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Save word doc as PDF</title>
      <link>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399094#M31478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the replies. I had never written a line of python before last week and managed to get a fairly complicated script to run perfectly on my machine; it just doesn't work on anyone else's. Since I'm in "crash course" mode, I'll give docx and reportlab a try.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Feb 2012 11:25:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399094#M31478</guid>
      <dc:creator>JohnLay</dc:creator>
      <dc:date>2012-02-02T11:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Save word doc as PDF</title>
      <link>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399095#M31479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, for the life of me I can't figure out how to get docx to work. There is no documentation provided (that I could find anyway) and what little coding examples I have been able to locate do not work for me. I get a "module object has no attribute open" or "open is not defined" when I simply try to open the doc file. ReportLab also does not appear to be a solution as I am first editing my document template with SearchCursor and Bookmarks commands before exporting to PDF.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any other possible work arounds?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Feb 2012 17:07:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399095#M31479</guid>
      <dc:creator>JohnLay</dc:creator>
      <dc:date>2012-02-02T17:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Save word doc as PDF</title>
      <link>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399096#M31480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Check this out: &lt;/SPAN&gt;&lt;A href="https://github.com/mikemaccana/python-docx/blob/master/tests/test_docx.py"&gt;https://github.com/mikemaccana/python-docx/blob/master/tests/test_docx.py&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Feb 2012 17:24:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399096#M31480</guid>
      <dc:creator>AndrewChapkowski</dc:creator>
      <dc:date>2012-02-02T17:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Save word doc as PDF</title>
      <link>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399097#M31481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Check my vb codes on &lt;/SPAN&gt;&lt;A href="http://www.rasteredge.com/how-to/vb-net-imaging/word-convert-pdf/"&gt;Word to pdf&lt;/A&gt;&lt;SPAN&gt; converting, and the Word can be 2007 or any later version, I have tested this converting project several times, and it works well within .net framework 2.0 and all the above versions. Hope it can help you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim PDF As New RasterEdgeImaging()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub WordConvertToPdf()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If True Then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WordInputFile = ("C:/1.docx")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ImageOutputFile = ImageFormat.pdf&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; doc.Save(@"C:/1.docx", 1, @"C:/1.pdf")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2014 02:51:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/save-word-doc-as-pdf/m-p/399097#M31481</guid>
      <dc:creator>HILLARYHALL</dc:creator>
      <dc:date>2014-04-10T02:51:48Z</dc:date>
    </item>
  </channel>
</rss>

