SlideShare a Scribd company logo
1 of 35
MrSID to PDF: Converting 13,000
files with ArcPy / Python
City of Rockville
Mike Onzay, Celine Yang, Dung Tran
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Goals of Project
• Convert MrSID files to PDF
• PDF can be printed at correct drawing scale
• Retain coded filenames
• Create Engineering drawing sets
• Link to PDF from ArcMap
• Learn ArcPy and Python
www.rockvillemd.gov
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Internal Workflow
Plans
Processing
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
B-374-12-INSW-2014
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID + AutoCAD = PDF
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID to PDF with Python inside ArcMap
import arcview
import arcpy,os
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
lyr.visible = "True"
lname = lyr.name
outFile = os.path.join(r"H:DesignSheetPDFs", lname.replace('.sid') + ".pdf")
arcpy.mapping.ExportToPDF(mxd, outFile, "PAGE_LAYOUT", 640, 480, 300,
"BETTER", "RGB", "TRUE", "ADAPTIVE", "RASTERIZE_BITMAP", "", "",
"LAYERS_ONLY", "FALSE")
lyr.visible = "False"
del mxd
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID to PDF with Python outside ArcMap
import arcview
import arcpy,os
mxd = arcpy.mapping.MapDocument(r"C:GISdesignsheet.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
print df.scale
lyr = arcpy.mapping.Layer(r"gisserver2DesignSheetA001A-001-01-M-1956.sid")
arcpy.mapping.AddLayer(df,lyr)
print df.scale
lyr.visible = "True"
lname = lyr.name
outFile = r"C:GISoutput" + lname.replace('.sid', '.pdf')
arcpy.mapping.ExportToPDF(mxd, outFile, "PAGE_LAYOUT", 640, 480, 300, "BETTER", "RGB",
"TRUE", "ADAPTIVE", "RASTERIZE_BITMAP", "", "", "LAYERS_ONLY", "FALSE")
lyr.visible = "False"
print outFile
del mxd
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID to PDF with Python outside ArcMap
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Expected Output Unexpected Output
MrSID to PDF with Python outside ArcMap
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID to PDF with Python outside ArcMap
arcpy.MakeRasterLayer_management(sourcefile, fnametemp)
arcpy.SaveToLayerFile_management(fnametemp,fnamesave)
addlayer = arcpy.mapping.Layer(fnamesave)
arcpy.mapping.AddLayer(df,addlayer,"Auto_ARRANGE")
arcpy.ApplySymbologyFromLayer_management (fnamesave,fnametemp)
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID to PDF with Python outside ArcMap
if df.scale != 1.0:
df.scale = 0.999999
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID + ArcMap / ArcPy = PDF
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Goals of Project
 Convert MrSID files to PDF
 Retain coded filenames
 PDF can be printed at correct drawing scale
• Create Engineering drawing sets
• Link to PDF from ArcMap
• Learn ArcPy and Python
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
www.rockvillemd.gov
New Filename Syntax
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Combining PDFs – PyPDF2
page = 0
merger = PdfFileMerger()
…
merger.append(open(os.path.join(PDF_source,pdf), 'rb'))
merger.addBookmark(pdf, page)
merger.setPageMode("/UseOutlines")
page += 1
…
merger.addMetadata({u'/Author':u'City of Rockville'})
merger.addMetadata({u'/Keywords': u'public works, engineering'})
...
merger.write(open(os.path.join(PDF_letter,number), 'wb'))
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID to PDF: Converting 13,000 files with ArcPy / Python
www.rockvillemd.gov
Open PDF from ArcMap
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Open PDF from ArcMap
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Open PDF from ArcMap
import webbrowser #only need this line inside ArcMap
import os
def OpenLink( [DESIGN_GROUP] ):
path = r'filesPublic WorksDesign Sheets-PDF Converted'
design = [DESIGN_GROUP]
code_list = design.split(',')
for code in code_list:
if len(code) == 4:
letter = code[0]
number = code[1:4]
for root, folder, files in os.walk(path):
for pdf in files:
if pdf[:5] == '{0}-{1}'.format(letter, number):
os.startfile(os.path.join(path, letter, number, pdf))
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Open PDF from ArcMap
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Phase One Complete
 About 9,000 MrSID files were converted to PDF
 About 13,000 PDF files were combined into 4800
PDF drawing sets.
 Critical design sheet codes are stored as
bookmarks in each PDF
 Can link to PDFs from ArcMap
 Can easily print one or more pages from PDF
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID PDFArcMap
ArcPy / Python
+ =
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Phase Two – Moving Forward
• Need to adjust workflow for new files
• Need to accommodate revisions and
as-builts into existing files
• Still need to convert ‘old/older/oldest’ files
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Phase Two – Moving Forward
Plans
Processing
Still kept for georeferencing
Single page PDFs
Manually moved to final folders
Burdensome dealing with as-builts
and revisions
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Phase Two – Moving Forward
Plans
Processing
C-242-01-AV-2013.pdf
P-208-13-NO-2012_Rev2.pdf
Single page PDFs
Manually moved to final folders
Burdensome dealing with asbuilts
and revisions Use Python!
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Phase Two – PyPDF2
Import os, shutil, datetime
From PyPDF2 import PdfFileReader, PdfFileWriter, PdfFileMerger
1. Check if existing PDF needs to be updated
2. Get bookmark names
3. Split single PDF into Multiple PDFs (pages)
4. Determine which pages need revisions
5. Replace pages
6. Move the old page into replaced folder
7. Merge updated pages + non-updated pages into single pdf
8. Write log files
9. Copy and overwrite updated PDFs to folders
10. Delete all staging files
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
PyPDF2 – Revisions and Asbuilts
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Phase Two – Complete
• Adjusted workflow for new files, revisions
and as-builts
• Converted 1,117 ‘old/older/oldest’ files
• Matching MrSID and PDF folder/files
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Phase Two – Complete
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID PDFArcMap
ArcPy / Python
+ =
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
Lessons Learned
Python libraries whether proprietary (ArcPy) or open source (PyPDF2) make coding easier
Be ready to deal with exceptions.
Hidden files, such as Thumbs.db, are tricky to deal with when you don’t know they are there.
Python sets are very cool
We learned how to pass a variable outside of a function
Use str.replace(old, new[, count]) instead of str.rstrip([chars])
You cannot use Acrobat Pro to replace or add a page on a PDF that was touched by PyPDF2 or the
internal structure of the bookmarks will break.
If you are stuck ask for help -- offline. Brainstorming with a real person can be fun.
Document your code early and often
www.rockvillemd.gov
MrSID to PDF: Converting 13,000 files with ArcPy / Python
MrSID to PDF: Converting 13,000 files with ArcPy /
Python
City of Rockville
Mike Onzay, Celine Yang, Dung Tran
www.rockvillemd.gov
Questions ?

More Related Content

Recently uploaded

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

MrSID to PDF: Converting 13000 files with ArcPy / Python

  • 1. MrSID to PDF: Converting 13,000 files with ArcPy / Python City of Rockville Mike Onzay, Celine Yang, Dung Tran www.rockvillemd.gov
  • 2. MrSID to PDF: Converting 13,000 files with ArcPy / Python Goals of Project • Convert MrSID files to PDF • PDF can be printed at correct drawing scale • Retain coded filenames • Create Engineering drawing sets • Link to PDF from ArcMap • Learn ArcPy and Python www.rockvillemd.gov
  • 3. www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 4. Internal Workflow Plans Processing www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 5. B-374-12-INSW-2014 www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 6. MrSID + AutoCAD = PDF www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 7. www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 8. MrSID to PDF with Python inside ArcMap import arcview import arcpy,os mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] for lyr in arcpy.mapping.ListLayers(mxd,"",df): lyr.visible = "True" lname = lyr.name outFile = os.path.join(r"H:DesignSheetPDFs", lname.replace('.sid') + ".pdf") arcpy.mapping.ExportToPDF(mxd, outFile, "PAGE_LAYOUT", 640, 480, 300, "BETTER", "RGB", "TRUE", "ADAPTIVE", "RASTERIZE_BITMAP", "", "", "LAYERS_ONLY", "FALSE") lyr.visible = "False" del mxd www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 9. MrSID to PDF with Python outside ArcMap import arcview import arcpy,os mxd = arcpy.mapping.MapDocument(r"C:GISdesignsheet.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] print df.scale lyr = arcpy.mapping.Layer(r"gisserver2DesignSheetA001A-001-01-M-1956.sid") arcpy.mapping.AddLayer(df,lyr) print df.scale lyr.visible = "True" lname = lyr.name outFile = r"C:GISoutput" + lname.replace('.sid', '.pdf') arcpy.mapping.ExportToPDF(mxd, outFile, "PAGE_LAYOUT", 640, 480, 300, "BETTER", "RGB", "TRUE", "ADAPTIVE", "RASTERIZE_BITMAP", "", "", "LAYERS_ONLY", "FALSE") lyr.visible = "False" print outFile del mxd www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 10. MrSID to PDF with Python outside ArcMap www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python Expected Output Unexpected Output
  • 11. MrSID to PDF with Python outside ArcMap www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 12. MrSID to PDF with Python outside ArcMap arcpy.MakeRasterLayer_management(sourcefile, fnametemp) arcpy.SaveToLayerFile_management(fnametemp,fnamesave) addlayer = arcpy.mapping.Layer(fnamesave) arcpy.mapping.AddLayer(df,addlayer,"Auto_ARRANGE") arcpy.ApplySymbologyFromLayer_management (fnamesave,fnametemp) www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 13. MrSID to PDF with Python outside ArcMap if df.scale != 1.0: df.scale = 0.999999 www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 14. MrSID + ArcMap / ArcPy = PDF www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 15. MrSID to PDF: Converting 13,000 files with ArcPy / Python Goals of Project  Convert MrSID files to PDF  Retain coded filenames  PDF can be printed at correct drawing scale • Create Engineering drawing sets • Link to PDF from ArcMap • Learn ArcPy and Python www.rockvillemd.gov
  • 16. MrSID to PDF: Converting 13,000 files with ArcPy / Python www.rockvillemd.gov New Filename Syntax
  • 17. MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 18. Combining PDFs – PyPDF2 page = 0 merger = PdfFileMerger() … merger.append(open(os.path.join(PDF_source,pdf), 'rb')) merger.addBookmark(pdf, page) merger.setPageMode("/UseOutlines") page += 1 … merger.addMetadata({u'/Author':u'City of Rockville'}) merger.addMetadata({u'/Keywords': u'public works, engineering'}) ... merger.write(open(os.path.join(PDF_letter,number), 'wb')) www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 19. MrSID to PDF: Converting 13,000 files with ArcPy / Python www.rockvillemd.gov
  • 20. Open PDF from ArcMap www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 21. Open PDF from ArcMap www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 22. Open PDF from ArcMap import webbrowser #only need this line inside ArcMap import os def OpenLink( [DESIGN_GROUP] ): path = r'filesPublic WorksDesign Sheets-PDF Converted' design = [DESIGN_GROUP] code_list = design.split(',') for code in code_list: if len(code) == 4: letter = code[0] number = code[1:4] for root, folder, files in os.walk(path): for pdf in files: if pdf[:5] == '{0}-{1}'.format(letter, number): os.startfile(os.path.join(path, letter, number, pdf)) www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 23. Open PDF from ArcMap www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 24. Phase One Complete  About 9,000 MrSID files were converted to PDF  About 13,000 PDF files were combined into 4800 PDF drawing sets.  Critical design sheet codes are stored as bookmarks in each PDF  Can link to PDFs from ArcMap  Can easily print one or more pages from PDF www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 25. MrSID PDFArcMap ArcPy / Python + = www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 26. Phase Two – Moving Forward • Need to adjust workflow for new files • Need to accommodate revisions and as-builts into existing files • Still need to convert ‘old/older/oldest’ files www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 27. Phase Two – Moving Forward Plans Processing Still kept for georeferencing Single page PDFs Manually moved to final folders Burdensome dealing with as-builts and revisions www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 28. Phase Two – Moving Forward Plans Processing C-242-01-AV-2013.pdf P-208-13-NO-2012_Rev2.pdf Single page PDFs Manually moved to final folders Burdensome dealing with asbuilts and revisions Use Python! www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 29. Phase Two – PyPDF2 Import os, shutil, datetime From PyPDF2 import PdfFileReader, PdfFileWriter, PdfFileMerger 1. Check if existing PDF needs to be updated 2. Get bookmark names 3. Split single PDF into Multiple PDFs (pages) 4. Determine which pages need revisions 5. Replace pages 6. Move the old page into replaced folder 7. Merge updated pages + non-updated pages into single pdf 8. Write log files 9. Copy and overwrite updated PDFs to folders 10. Delete all staging files www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 30. PyPDF2 – Revisions and Asbuilts www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 31. Phase Two – Complete • Adjusted workflow for new files, revisions and as-builts • Converted 1,117 ‘old/older/oldest’ files • Matching MrSID and PDF folder/files www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 32. Phase Two – Complete www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 33. MrSID PDFArcMap ArcPy / Python + = www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 34. Lessons Learned Python libraries whether proprietary (ArcPy) or open source (PyPDF2) make coding easier Be ready to deal with exceptions. Hidden files, such as Thumbs.db, are tricky to deal with when you don’t know they are there. Python sets are very cool We learned how to pass a variable outside of a function Use str.replace(old, new[, count]) instead of str.rstrip([chars]) You cannot use Acrobat Pro to replace or add a page on a PDF that was touched by PyPDF2 or the internal structure of the bookmarks will break. If you are stuck ask for help -- offline. Brainstorming with a real person can be fun. Document your code early and often www.rockvillemd.gov MrSID to PDF: Converting 13,000 files with ArcPy / Python
  • 35. MrSID to PDF: Converting 13,000 files with ArcPy / Python City of Rockville Mike Onzay, Celine Yang, Dung Tran www.rockvillemd.gov Questions ?

Editor's Notes

  1. Title slide: who we are, intro to project
  2. Goals of the project; next five slides are about design sheets, internal process and initial conversion
  3. Design sheets are engineering drawings.
  4. internal process: pages are scanned, TIFFs are cleaned up; files are coded and entered into a spreadsheet; files are exported to MrSID and copied into a well defined folder structure
  5. Folder structure. Cornerstone Slide for AutoCAD
  6. Manual export to PDF in ArcMap
  7. Oops!
  8. Oops!
  9. AddLayer bug
  10. makeRasterLayer and ApplySymbologyLayer. Make temporary raster layer from sid file, save it to a layer file, set a variable = to that saved layer file, add the layer, then apply the symbology from the original layer to the saved layer.
  11. Scale bug
  12. Approximately 10000 files were converted using this method
  13. Completed three goals of the project. In order to link from ArcMap to PDF we had to create a new filename syntax
  14. We determined that since every page of a drawing set shared the same first letter, number combo and year we could use that as our new filename. It is far easier to link to one file that different individual files.
  15. PyPDF2
  16. Window that appears when there is more than one value
  17. Where to insert the script
  18. Defined function MUST be named OpenLink
  19. Window that appears when there is more than one value
  20. Phase one complete
  21. Folder structure. Cornerstone Slide
  22. Phase 2 Moving Forward
  23. Phase 2 Moving Forward – current internal process; scanner was upgraded to output PDF; we still retain MrSIDs for georeferencing
  24. Phase 2 Moving Forward – modify internal process
  25. Phase 2 Moving Forward – compare, extract, replace, rebuild
  26. Result of revisions and asbuilts
  27. Phase 2 Moving Forward
  28. Phase 2 Moving Forward
  29. Folder structure. Cornerstone Slide
  30. The chars argument is not a suffix; rather, all combinations of its values are stripped.
  31. Title slide: who we are, intro to project