The code is in VB .Net but you can easily port it to c#. It's a console application that accepts a parameter (MXD name) and exports the layout of the MXD to PDF. Good luck.
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Output
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Geometry
Imports System.io
Module ExtractPdf
Sub Main()
Dim ao As IAoInitialize = New AoInitialize
Dim pMapDoc As IMapDocument = New MapDocument
Dim pParameter As String() = Environment.GetCommandLineArgs
Dim theMap As String = pParameter(1)
Dim thePath As String
Dim theFileName As String
Dim theWidth As Double
Dim theHeight As Double
Dim pExportPDF As IExportPDF = New ExportPDF
Dim pExport As IExport = pExportPDF
Dim pExportVectorOptionEx As IExportVectorOptionsEx
Dim pPixEnv As IEnvelope = New Envelope
Dim pRect As tagRECT
Dim hDc As Integer
Dim pLayoutView As IActiveView
Dim writer As StreamWriter
Try
If theMap Is Nothing Then
Exit Sub
End If
'Get output path and output file name
thePath = System.IO.Path.GetDirectoryName(theMap)
theFileName = System.IO.Path.GetFileNameWithoutExtension(theMap)
If File.Exists(thePath & "\tilecache_error.log") Then
writer = File.AppendText(thePath & "\tilecache_error.log")
Else
writer = New StreamWriter(thePath & "\tilecache_error.log")
End If
If ao.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcInfo) = esriLicenseStatus.esriLicenseAvailable Then
ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo)
If pMapDoc.IsMapDocument(theMap) Then
'Open map and obtain layout
pMapDoc.Open(theMap)
pLayoutView = pMapDoc.PageLayout
'Get page width and height
pMapDoc.PageLayout.Page.QuerySize(theWidth, theHeight)
'Set up export parameters
pExport.ExportFileName = thePath & "\" & theFileName & ".pdf"
pExport.Resolution = 100
pExportVectorOptionEx = pExportPDF
pExportVectorOptionEx.ExportPictureSymbolOptions = esriPictureSymbolOptions.esriPSOVectorize
pRect.left = 0
pRect.top = 0
pRect.right = theWidth * pExport.Resolution
pRect.bottom = theHeight * pExport.Resolution
pPixEnv.PutCoords(pRect.left, pRect.top, pRect.right, pRect.bottom)
pExport.PixelBounds = pPixEnv
'Start export of layout
hDc = pExport.StartExporting
pLayoutView.Output(hDc, pExport.Resolution, pRect, Nothing, Nothing)
pExport.FinishExporting()
Else
writer.WriteLine("Export PDF (" & Now & ") - " & theFileName & " - Input map parameter is not an ArcGIS map document.")
writer.Close()
End If
Else
writer.WriteLine("Export PDF (" & Now & ") - " & theFileName & " - Can not obtain an ArcInfo license.")
writer.Close()
Exit Sub
End If
ao.Shutdown()
Catch ex As Exception
ao.Shutdown()
writer.WriteLine("Export PDF (" & Now & ") - " & theFileName & " - " & ex.Message)
End Try
End Sub
End Module