<?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: python get PDF page count in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-get-pdf-page-count/m-p/400029#M31545</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jeff,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why of course not... that would have saved me too much time. Not sure how I missed that one... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;many thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ryan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 Dec 2011 13:45:04 GMT</pubDate>
    <dc:creator>RyanKelley</dc:creator>
    <dc:date>2011-12-06T13:45:04Z</dc:date>
    <item>
      <title>python get PDF page count</title>
      <link>https://community.esri.com/t5/python-questions/python-get-pdf-page-count/m-p/400026#M31542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Having a tough time finding an easy answer to this. We have Report Lab, but haven't had much success getting at this piece. Seems like it should be very easy... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am appending multiple PDFs and am writing out a TOC for a cover page, but need the number of pages in each PDF I am appending. Any thoughts?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ryan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Dec 2011 16:15:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-get-pdf-page-count/m-p/400026#M31542</guid>
      <dc:creator>RyanKelley</dc:creator>
      <dc:date>2011-12-05T16:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: python get PDF page count</title>
      <link>https://community.esri.com/t5/python-questions/python-get-pdf-page-count/m-p/400027#M31543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ok, an answer and something that doesn't need some crazy function... Also, the pyPdf library can give you results in one line of code apparently, which I didn't try.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;pdf = "my.pdf"

import re

rxcountpages = re.compile(r"/Type\s*/Page([^s]|$)", re.MULTILINE|re.DOTALL)

def countPages(filename):
&amp;nbsp;&amp;nbsp;&amp;nbsp; data = file(filename,"rb").read()
&amp;nbsp;&amp;nbsp;&amp;nbsp; return len(rxcountpages.findall(data))

if __name__=="__main__":
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Number of pages in PDF File:", countPages(pdf)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:16:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-get-pdf-page-count/m-p/400027#M31543</guid>
      <dc:creator>RyanKelley</dc:creator>
      <dc:date>2021-12-11T18:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: python get PDF page count</title>
      <link>https://community.esri.com/t5/python-questions/python-get-pdf-page-count/m-p/400028#M31544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Ryan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have you tried the pageCount property on the PDFDocument object?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
pdfDoc = arcpy.mapping.PDFDocumentOpen(path)
print pdfDoc.pageCount
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:16:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-get-pdf-page-count/m-p/400028#M31544</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-11T18:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: python get PDF page count</title>
      <link>https://community.esri.com/t5/python-questions/python-get-pdf-page-count/m-p/400029#M31545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jeff,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why of course not... that would have saved me too much time. Not sure how I missed that one... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;many thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ryan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Dec 2011 13:45:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-get-pdf-page-count/m-p/400029#M31545</guid>
      <dc:creator>RyanKelley</dc:creator>
      <dc:date>2011-12-06T13:45:04Z</dc:date>
    </item>
  </channel>
</rss>

