Anyway to reduce size of pdf using python script.
I have a batch file that exports ArcGIS pdf maps to a directory. I would like to include a step in the script where the pdf file is reduced in size instead of manually opening each file in Acrobat X Pro after the script has run and doing it there. Can this be done using python scripting or does the automation stop at exporting the map? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Merge pdf files using information from two files
I have two files (right now they are spreadsheets but I can export them to any format). File1 has StoreID (unique) in one column and a pdf map location in the second column. (Names not really sequenced numerically) 1 C:/maps/map1.pdf 2 C:/maps/map2.pdf 3 C:/maps/map3.pdf 4 C:/maps/map4.pdf File2 has 3 columns. Column1 is the County name (unique), Column2 are the store IDs that fall in that county separated by commas, and Column3 is warehouse that services the store. County11,2Warehouse1 County21,3Warehouse1 County33 Warehouse4 County42,4Warehouse3 Is it possible to compare both files and append the maps that belong in each county and naming it by the county_warehouse.pdf? 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_Warehouse4.pdf (pdf file is map3.pdf) C:\maps\final\County4_Warehouse1.pdf (pdf file is map2.pdf and map4.pdf) I could spend some time reorganizing the second file to look like this if it makes it easier: County11Warehouse1 County12Warehouse1 County21Warehouse1 County23Warehouse1 County33Warehouse4 County42Warehouse3 County44Warehouse3 Ideas as to how to accomplish this? -- https://mail.python.org/mailman/listinfo/python-list
Merging pdf files based on a value in a field
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. Ideas as to how to do this? -- https://mail.python.org/mailman/listinfo/python-list
Re: Merging pdf files based on a value in a field
Suggestions to use pyPDF2 to append files did not pan out. I had to go with the arcpy module. pyPDF2 does NOT merge correctly when trying to output multiple files based on a a similar value or key (essentially the group by concept). import csv import arcpy from arcpy import env import shutil, os, glob # clear out files from destination directory files = glob.glob(r'C:\maps\JoinedMaps\*') for f in files: os.remove(f) # open csv file f = open("C:\maps\Maps.csv", "r+") ff = csv.reader(f) # set variable to establish previous row of csv file (for comaprrison) pre_line = ff.next() # Iterate through csv file for cur_line in ff: # new file name and location based on value in column (county name) newPdfFile = (r'C:\maps\JoinedMaps\County-' + cur_line[0] +'.pdf') # establish pdf files to be appended joinFile = pre_line[1] appendFile = cur_line[1] # If columns in both rows match if pre_line[0] == cur_line[0]: # <-- compare first column # If destnation file already exists, append file referenced in current row if os.path.exists(newPdfFile): tempPdfDoc = arcpy.mapping.PDFDocumentOpen(newPdfFile) tempPdfDoc.appendPages(appendFile) # Otherwise create destination and append files reference in both the previous and current row else: tempPdfDoc = arcpy.mapping.PDFDocumentCreate(newPdfFile) tempPdfDoc.appendPages(joinFile) tempPdfDoc.appendPages(appendFile) # save and delete temp file tempPdfDoc.saveAndClose() del tempPdfDoc else: # if no match, do not merge, just copy shutil.copyfile(appendFile,newPdfFile) # reset variable pre_line = cur_line Final output looked like this: County-County1 (2 pages - Map1 and Map2) County-County2 (2 pages - Map1 and Map3) County-County3 (1 page - Map3) County-County2 (3 pages - Map2, Map3, and Map4) -- https://mail.python.org/mailman/listinfo/python-list
Grab metadata from images and save to file, batch mode
I have a directory (and sub-directories) full of images that I want to cycle through and grab certain metadata values and save those values to a single row in a cvs file. I would like to tack on the full path name to the row as a separate value. Folder C:\Images\Family Brother.jpg Sister.jpg Mom.jpg Keys/Values Original Date/Time User Name File Name Thus, data might look like this in a Family.csv file 2014:11:10 13:52:12; BillyBob111; Brother.jpg; C:\Images\Family\Brother.jpg 2015:10:54 11:45:34; BillyBob111; Sister.jpg; C:\Images\Family\Sister.jpg 2010:10:31 19:22:11; SallySue232; Mom.jpg; C:\Images\Family\Mom.jpg Big time noob. Much of what I have read cites command line examples dealing with single files and no info as to how to extract specific keys and their values. What module would some of you users recommend I use (I want it to be python as that is what I am trying to learn) Can you give me some coding suggestions to get me goings? I haven't found any substantive scripts to use as guides. Many thanks in advance -- https://mail.python.org/mailman/listinfo/python-list
Looking for sample python script using Tkinter
I have a script that I trying to go from command line entry to interface entry. I am tinkering with Tkinter and want to review some Tkinter interface building scripts. Really basic stuff covering file selection and making some of the data captured required I am learning how to use Tkinter (Python 2.7) to build a data entry interface where the variables (about 15 data entry fields in all) will be used later in the script to perform some analyses. I have a few requirements when capturing the data: Must be able to navigate to a file and capture entire filename and pathname (which may be on a network rather than the C drive) Capture date Capture text (Some of the data entry fields will have commas) Some of the data entry fields are required, some are not. Is there a sample script out there that I can review to see how these features are accomplished? I am particularly stumped by #1 and 4. Thanks to any and all help. -- https://mail.python.org/mailman/listinfo/python-list
Calling macro from python script bombs out when custom table style is used
I have a python script (2.7.5) that calls a macro from an excel template. Both scripts ran fine until i tried to apply a custom table style within excel. I suspect this has something to do with the win32.com client application not recognizing custom table styles. Does anyone have a work around suggestion? My python script: import os.path import win32com.client mySourceExcelFile = "C:\\tests\\Source\\Cats.xlsm" projectArea = ("C:\\tests\\Target\\results\\") projectName = ("Cats") print projectName print repr(projectArea) xlApp = win32com.client.DispatchEx('Excel.Application') xlsPath = os.path.expanduser(mySourceExcelFile) wb = xlApp.Workbooks.Open(Filename=xlsPath) wb.Application.DisplayAlerts = False xlApp.Run("FormatFile", projectArea, projectName) xlApp.Quit() My 2007 excel macro Sub FormatFile(strResultsDir As String, targetFileName As String) ' ' Application.DisplayAlerts = False Workbooks.Open fileName:=strResultsDir & targetFileName & ".dbf" ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1", ActiveCell.SpecialCells(xlLastCell)), , xlYes).Name = _ "Table1" Range("Table1[#All]").Select 'ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight1" ActiveSheet.ListObjects("Table1").TableStyle = "MyStyle" ActiveWorkbook.SaveAs fileName:=strResultsDir & targetFileName & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False ActiveWorkbook.Close Application.Quit End Sub Macro bombs out when it gets to my custom table style ActiveSheet.ListObjects("Table1").TableStyle = "MyStyle" Works fine when table style is one that comes with excel: TableStyleLight1 -- https://mail.python.org/mailman/listinfo/python-list
Adding new lines to word document using zipfile module within python 2.7?
Writing text to a word document (word 2007) using the zipfile module via python coding (python 2.7). Below if the section of code I am using to do this. I can't figure out what character I need to use to get it to add new lines to the zipfile. if Count: blurb = "\r\nINSERT TABLE HERE\r\n\r\nSA* - South America\r\nNA** - North America\r\nCA*** - Central America" else: blurb = "" further down I also have the following code (a small snippet of actual code for clarification) replaceText = {"TEXTBLURB" : blurb} Right now "if Count" is true, the output in the word document looks like this: INSERT TABLE HERE SA* - South America NA** - North America CA*** - Central America I want it too look like this: INSERT TABLE HERE SA* - South America NA** - North America CA*** - Central America I have a MS Word template file called "Automated Response.docx" that has a TAG imbedded between two paragraphs called "TEXTBLURB". Using a python script, if a certain condition is met, I want to replace this tag with some text (see above "blurb") that contains newlines, otherwise, don't add the text between paragraphs. I can't figure out the python code needed to imbed newlines into the tag. Ideas as to how to add new lines via python coding? I tried \r, \n, \r\n, ^11 and . None worked. -- http://mail.python.org/mailman/listinfo/python-list
Working with Access tables and python scripts
I have an existing extensive python script that I would like to modify slightly to run a different variation on a process. I also have all the variables I need to run this script (about 20 in total)stored in an Access 2010 64 bit database. Is it possible to create a button on an Access form (or other GUI) to pass the information that is stored in the various fields in the database to the python script? Not all the values are in a single table. A query joining related tables would need to be done. Ideally I would like to execute the script from the Access data entry form immediately after entering the required data into the database. If so, how might I go about accomplishing this? I am at a loss as to where to even start such a task. Any and all help greatly appreciated. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can I Import table from txt file into form letter using Python?
On Thursday, February 21, 2013 2:12:12 PM UTC-8, WorkerBee wrote: > Very new to python but diving in with both feet here. > > > > I am trying to extend a python script to include automating a response form > letter by including the results from a text file in tabular format into the > letter. > > > > I have a text file called “Cities” that I want to add to a paragraph in > document. (It can be a text document. I can copy it into a word document > later) > > > > The Cities.txt file looks like this: > > > > "CITYNAME", Pop > > "Master Chief", 4277647 > > "El Carro", 10017844 > > "Geat Stanton", 717804 > > "Eureka", 1973732 > > "Lands End",5329713 > > "Pembrook", 2751614 > > "White Park", 6854152 > > "Greenbriar", 3243175 > > "Lost Crutches", 1285470 > > "Storeybrook", 26 > > "Burlington Heights City",10793 > > "Nyte", 11613743 > > "Dog Patch", 472314 > > "Miserable Lives", 2439334 > > "Lincoln Park Pirates", 6808633 > > "Son ofaFrancisco", 2295350 > > "Lois Lane Heights", 5178065 > > > > The first line is header info which will need to be renamed. The remaining > lines need to be entered as two columns but doubled up across the page. The > file will always be called cities but the data will change for each form > letter. Thus the cities could be 100 records long, or no cities found > depending on the search results. The table has to be 6.5 inches wide. Height > will vary. Thus for this file the data will need to look like this: > > > > "Below is a list of the following cities that are within your area of > interest." > > > > City Name Population City Name Population > > Master Chief 4277647 Storeybrook 26 > > El Carro 10017844Burlington Heights City 10793 > > Geat Stanton 717804 Nyte11613743 > > Eureka1973732 Dog Patch 472314 > > Lands End 5329713 Miserable Lives 2439334 > > Pembrook 2751614 Lincoln Park Pirates6808633 > > White Park6854152 Son ofaFrancisco2295350 > > Greenbriar3243175 Lois Lane Heights 5178065 > > Lost Crutches 1285470 > > > > (Note: No data would say something like: "There are no cities within your > area of interest." No table is inserted.) > > > > Note that the city names sizes change so the column widths may need to change > also. My current process is to import the text file into Excel. Rename and > bold font headings and copy and paste second set of headings in columns 3 and > 4. Cut and paste half the rows into new columns below the second set of > headings. Copy and paste into word document. Auto fit table to window. > > > > I actually have several text files. Some require 1, 2 or 3 SETS of columns. I > figure if I can get coding for the above example, I can figure out how to > change it for all other text files. > > > > I am trying to automate as much as the process as possible. Using python, I > have automated the processing required to get the text files, now I want to > try to automate putting this data into a standardized word document. > Basically I'm trying to automate a form letter that has a few modifications > depending on the query results. Can anyone help me here, if not with the > code, a site that would help me figure it out by myself? > > > > BTW, I have NO control over the appearance of the form letter. A committee of > silly bureaucrats argued endlessly over the format last year and thus its > format is carved in stone. I just plug in the data like a good grunt worker > bee, so please refrain from slamming me on the ridiculousness of multiple > columns. Appearance is everything around here. > > > > Thanks in advance. Columns are supposed to line up. They lined up in my editor. Didn't see a preview/edit option so I had to post without using these features. Sorry. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I Import table from txt file into form letter using Python?
On Thursday, February 21, 2013 2:12:12 PM UTC-8, WorkerBee wrote: > Very new to python but diving in with both feet here. > > > > I am trying to extend a python script to include automating a response form > letter by including the results from a text file in tabular format into the > letter. > > > > I have a text file called “Cities” that I want to add to a paragraph in > document. (It can be a text document. I can copy it into a word document > later) > > > > The Cities.txt file looks like this: > > > > "CITYNAME", Pop > > "Master Chief", 4277647 > > "El Carro", 10017844 > > "Geat Stanton", 717804 > > "Eureka", 1973732 > > "Lands End",5329713 > > "Pembrook", 2751614 > > "White Park", 6854152 > > "Greenbriar", 3243175 > > "Lost Crutches", 1285470 > > "Storeybrook", 26 > > "Burlington Heights City",10793 > > "Nyte", 11613743 > > "Dog Patch", 472314 > > "Miserable Lives", 2439334 > > "Lincoln Park Pirates", 6808633 > > "Son ofaFrancisco", 2295350 > > "Lois Lane Heights", 5178065 > > > > The first line is header info which will need to be renamed. The remaining > lines need to be entered as two columns but doubled up across the page. The > file will always be called cities but the data will change for each form > letter. Thus the cities could be 100 records long, or no cities found > depending on the search results. The table has to be 6.5 inches wide. Height > will vary. Thus for this file the data will need to look like this: > > > > "Below is a list of the following cities that are within your area of > interest." > > > > City Name Population City Name Population > > Master Chief 4277647 Storeybrook 26 > > El Carro 10017844Burlington Heights City 10793 > > Geat Stanton 717804 Nyte11613743 > > Eureka1973732 Dog Patch 472314 > > Lands End 5329713 Miserable Lives 2439334 > > Pembrook 2751614 Lincoln Park Pirates6808633 > > White Park6854152 Son ofaFrancisco2295350 > > Greenbriar3243175 Lois Lane Heights 5178065 > > Lost Crutches 1285470 > > > > (Note: No data would say something like: "There are no cities within your > area of interest." No table is inserted.) > > > > Note that the city names sizes change so the column widths may need to change > also. My current process is to import the text file into Excel. Rename and > bold font headings and copy and paste second set of headings in columns 3 and > 4. Cut and paste half the rows into new columns below the second set of > headings. Copy and paste into word document. Auto fit table to window. > > > > I actually have several text files. Some require 1, 2 or 3 SETS of columns. I > figure if I can get coding for the above example, I can figure out how to > change it for all other text files. > > > > I am trying to automate as much as the process as possible. Using python, I > have automated the processing required to get the text files, now I want to > try to automate putting this data into a standardized word document. > Basically I'm trying to automate a form letter that has a few modifications > depending on the query results. Can anyone help me here, if not with the > code, a site that would help me figure it out by myself? > > > > BTW, I have NO control over the appearance of the form letter. A committee of > silly bureaucrats argued endlessly over the format last year and thus its > format is carved in stone. I just plug in the data like a good grunt worker > bee, so please refrain from slamming me on the ridiculousness of multiple > columns. Appearance is everything around here. > > > > Thanks in advance. OOPS. One more thing, I hope. Python version is 2.7. Locked into this version due to software constraints. -- http://mail.python.org/mailman/listinfo/python-list
Grouping on and exporting to csv files
My current Test_Sort.csv looks like this (which constantly changes-although never more than 4 records, thus far anyway): RecNo,Count,District,Fruit,StoreNo 1,100,0,oranges,1254 2,30,3,apples,654 3,100,0,bananas,21 4,0,4,grapes,478 I wrote the following python 2.7 script (stuck with 2.7) - import sys import csv import operator source = "E:\\Data\\Test_Sort.csv" result = "E:\\Data\\Test_Sort1.csv" with open(source,"rb") as source: rdr= csv.reader( source ) with open(result,"wb") as result: next(rdr, None) # Skip header wtr= csv.writer( result ) for r in rdr: wtr.writerow( (r[2], r[3])) # Only write columns 3 and 4 to a csv file exit exit data = csv.reader(open("E:\\Data\\Test_Sort1.csv"),delimiter=',') sortedlist = sorted(data, key=operator.itemgetter(0,1)) # sort by column 1, the 2 print sortedlist - My sortedlist results are: [['0', 'bananas'], ['0', 'oranges'], ['3', 'apples'], ['4', 'grapes']] I want to output all fruits with the same District number out to a csv file called by its District number. (No headers) Thus in above example I would ultimately have three csv files: 0.csv bananas oranges 3.csv apples 4.csv grapes Question is : Any ideas as to how export this sortedlist to the tables described above? I already have a script that already will look at each file and count the number of lines and insert the correct number of commas and the word "and" where appropriate in a sentence. My ultimate goal is to read each file and print out a sentence based on whether it has record or not, and if so how many records and then add the word "and" and/or commas between records if greater than 1. I will then concatenate all the sentences together to form a paragraph. Thus, the above example would say: The western district sold bananas and oranges. The central district sold apples. The southern district sold grapes. or if the files were: 0.csv apples bananas oranges 2.csv grapes The resulting paragraph would read: The western district sold apples, bananas, and oranges. The eastern district sold grapes. It may seem like a crazy way about getting my results but it was the best I could come up with given my limited knowledge of python. Thanks for any and all help. -- http://mail.python.org/mailman/listinfo/python-list
Coding issue with XML for word document
I am constructing a sentence to insert into a word xml template. My code is below #Create a list if len(myList) > 0: if len(myList) > 1: testText = list_format(myList) + " dealers." else: myText = myList[0] + " dealer." #Contruct sentence #myBlurb = "My Favorite Cars - My favorite cars are available at " + myText + "" myBlurb = "My Favorite Cars - My favorite cars are available at " + myText + "" else: myBlurb = "" --- If a list exists (not = 0) Then I am trying to get the following output: My Favorite Cars - My favorite cars are available at (list of dealers) dealers. There is a newline above and below this line. The first three words and the dash are bold. All other words are regular. This works myBlurb = "My Favorite Cars - My favorite cars are available at " + myText + "" But when I try to bold, it bombs. It does not seem to like either of these (+ myText + "") (separately or together) appended on the end. Thia does not work myBlurb = "My Favorite Cars - My favorite cars are available at " + myText + " What am I missing here? -- https://mail.python.org/mailman/listinfo/python-list
Re: Coding issue with XML for word document
> myBlurb = "My Favorite Cars - > My favorite cars are available at " + > myText + " > > What am I missing here? Sorry about posting in python group. My XML coding was embedded in python script. I will do better next time. The problem was with placement of tags. The following worked: myBlurb = "My Favorite Cars - My favorite cars are available at " + myText + " I needed to put the carriage return within the wrapper. I also needed to add the text elements and before and after the variable. -- https://mail.python.org/mailman/listinfo/python-list