<?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: Combine PDFs for facing pages in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371442#M29387</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I started with that script a few months ago (I specifically upgraded to 10 so I could do this -- the rest of the City is at 9.3.1 or earlier).&amp;nbsp; I've since modified it quite a bit, but the basic idea is the same.&amp;nbsp; Don't get lost worrying about creating lists -- you're creating pages and then merging them all together.&amp;nbsp; What you're basically doing is a loop to create all the even-numbered pages, then loop to create all the odd-numbered pages, then a third loop to merge them all.&amp;nbsp; The trick is in the numbering of the pages as you create them.&amp;nbsp; First loop is 1, 3, 5, 7, ..., second loop is 2, 4, 6, 8, ..., third loop is 1, 2, 3, 4, 5, 6, 7, 8...&amp;nbsp; Keep the files names simple like the example script.&amp;nbsp; Spell out the path name completely and just loop the page number and concatenate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Paul&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;---------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Paul Cone&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mapping and GIS&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;City of Portland, Bureau of Transportation&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Apr 2011 17:03:47 GMT</pubDate>
    <dc:creator>PaulCone</dc:creator>
    <dc:date>2011-04-11T17:03:47Z</dc:date>
    <item>
      <title>Combine PDFs for facing pages</title>
      <link>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371437#M29382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have been furiously trying to make this code work &lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s90000002p000000.htm"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s90000002p000000.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think my problem is with the page numbering.&amp;nbsp; But I'm past that, I just want to know if their is a way in Python to combine two folders of PDFs.&amp;nbsp; Each folder has 68 individual PDFs, Folder1 is the left side, Folder2 is the right.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Folder1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Folder 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;B7.pdf&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C7.pdf&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;B8.pdf&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C8.pdf&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...etc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...etc&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is their a way to combine these two folders full of PDFs into one 136 page PDF with left and right pages based on which folder they reside in?&amp;nbsp; I'd rather not spell out every single path name and append, it defeats the purpose.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Apr 2011 20:56:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371437#M29382</guid>
      <dc:creator>TomMagdaleno</dc:creator>
      <dc:date>2011-04-04T20:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Combine PDFs for facing pages</title>
      <link>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371438#M29383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just read the contents of both directories into a list of (PageA,PageB) pairs and iterate over the list, calling the appendPages method on PageA and then PageB.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Apr 2011 21:10:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371438#M29383</guid>
      <dc:creator>LoganPugh</dc:creator>
      <dc:date>2011-04-04T21:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combine PDFs for facing pages</title>
      <link>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371439#M29384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Logan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Could you give an example?&amp;nbsp; I'm new to this.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Apr 2011 21:36:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371439#M29384</guid>
      <dc:creator>TomMagdaleno</dc:creator>
      <dc:date>2011-04-04T21:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Combine PDFs for facing pages</title>
      <link>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371440#M29385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I know I can run something like this below, but how do I create my list?&amp;nbsp; Would it have full paths?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Author:&amp;nbsp; ESRI&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Date:&amp;nbsp;&amp;nbsp;&amp;nbsp; July 5, 2010&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Version: ArcGIS 10.0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Purpose: This script will append multiple PDFs into a single output PDF file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The script is intended to run within a script tool.&amp;nbsp; There are two&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parameters:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1) Select PDF Files to Append,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2) Output PDF.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Notes: The order of the PDFs is based on how they are entered.&amp;nbsp; The PDF at the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; top of the list is first followed by those below it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, os, string&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Read input parameters from script tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PDFList = string.split(arcpy.GetParameterAsText(0), ";")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outPDFpath = arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Create a new PDF object to store the results&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputPDF = arcpy.mapping.PDFDocumentCreate(outPDFpath)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Loop through and append each PDF in the list&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for eachPDF in PDFList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputPDF.appendPages(str(eachPDF))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Save the changes and open the result automatically&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputPDF.saveAndClose()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;os.startfile(outPDFpath)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Remove variable reference to file&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del outputPDF&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Apr 2011 22:40:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371440#M29385</guid>
      <dc:creator>TomMagdaleno</dc:creator>
      <dc:date>2011-04-04T22:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Combine PDFs for facing pages</title>
      <link>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371441#M29386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To demonstrate how to combine the lists (which may be of different lengths) see the following example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;aList = ["a", "c", "e", "g"]
bList = ["b", "d", "f", "h", "i", "j"]
n1 = len(aList)
n2 = len(bList)
combo = []
for i in range(0, n1):
&amp;nbsp; combo += [aList&lt;I&gt;, bList&lt;I&gt;]
if n2 &amp;gt; n1:
&amp;nbsp; combo += bList[n1:n2]
print combo
&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Ensure that aList is the shorter of the two and bList is equal to or greater than aList.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:12:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371441#M29386</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T17:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Combine PDFs for facing pages</title>
      <link>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371442#M29387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I started with that script a few months ago (I specifically upgraded to 10 so I could do this -- the rest of the City is at 9.3.1 or earlier).&amp;nbsp; I've since modified it quite a bit, but the basic idea is the same.&amp;nbsp; Don't get lost worrying about creating lists -- you're creating pages and then merging them all together.&amp;nbsp; What you're basically doing is a loop to create all the even-numbered pages, then loop to create all the odd-numbered pages, then a third loop to merge them all.&amp;nbsp; The trick is in the numbering of the pages as you create them.&amp;nbsp; First loop is 1, 3, 5, 7, ..., second loop is 2, 4, 6, 8, ..., third loop is 1, 2, 3, 4, 5, 6, 7, 8...&amp;nbsp; Keep the files names simple like the example script.&amp;nbsp; Spell out the path name completely and just loop the page number and concatenate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Paul&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;---------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Paul Cone&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mapping and GIS&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;City of Portland, Bureau of Transportation&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Apr 2011 17:03:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/combine-pdfs-for-facing-pages/m-p/371442#M29387</guid>
      <dc:creator>PaulCone</dc:creator>
      <dc:date>2011-04-11T17:03:47Z</dc:date>
    </item>
  </channel>
</rss>

