-2

The StoreID (unique) is in Column1, a pdf map location in Column2, and the file name is "Warehouse1" (this will vary). (names not really sequenced numerically)

County1     C:/maps/map1.pdf 
County1     C:/maps/map2.pdf 
County2     C:/maps/map1.pdf 
County2     C:/maps/map3.pdf 
County3     C:/maps/map3.pdf 
County4     C:/maps/map2.pdf 
County4     C:/maps/map4.pdf

Is it possible to append the pdf maps with the same county and naming the new pdf file grouped by the value in the county field and the file name?

Output would be something like this:

C:\maps\final\County1_Warehouse1.pdf (pdf file is map1.pdf and map2.pdf)
C:\maps\final\County2_Warehouse1.pdf (pdf file is map1.pdf and map3.pdf)
C:\maps\final\County3_Warehouse1.pdf (pdf file is map3.pdf)
C:\maps\final\County4_Warehouse1.pdf (pdf file is map2.pdf and map4.pdf)

Right now the data is in a database but I can export this info into any format needed. I will be performing this task several times a year so I would like to automate it if possible.

Ideas as to how to do this? I am familiar with python programing.

user12059
  • 733
  • 2
  • 13
  • 27
  • The `pypdf2` library should be able to concatenate pdf files. Here is an example of how to do it : https://github.com/mstamy2/PyPDF2/blob/master/Sample_Code/basic_merging.py. – Unatiel Sep 08 '17 at 22:52
  • I am trying to get my head around how to get the info from the file. Could I use a csv reader to group by county somehow and then run the corresponding map locations through the PdfFileMerger Class? Guess if you don't post code you get down voted. Just trying to figure out where to start. – user12059 Sep 08 '17 at 23:10
  • In your question you say the data is in a database and that you can export it in any format. If you can export data to csv, then yes a `csv.reader()` would allow you to get the pdf paths you need for `PdfFileMerger`. [`itertools.groupby()`](https://docs.python.org/3.6/library/itertools.html#itertools.groupby) will be useful to group by county. Also, while questions without code are **usually** downvoted, your question was probably downvoted because there are several questions in your question (merging the files, extracting data from db), and then there are several ways to solve each of them. – Unatiel Sep 09 '17 at 12:17

1 Answers1

0

Solution can be found at following post

NewbieX
  • 19
  • 7