/// <summary> /// Called when a step of this type is executed in the workflow. /// </summary> /// <param name="JobID">ID of the job being executed</param> /// <param name="StepID">ID of the step being executed</param> /// <param name="argv">Array of arguments passed into the step's execution</param> /// <param name="ipFeedback">Feedback object to return status messages and files</param> /// <returns>Return code of execution for workflow path traversal</returns> public int Execute(int JobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback) { if (JobID <= 0) { throw new ArgumentOutOfRangeException("JobID", JobID, "Job ID must be a positive value"); } try { string strTemp = ""; bool bAttach = false; if (StepUtilities.GetArgument(ref argv, m_expectedArgs[1], false, out strTemp)) { bAttach = true; } string strResolution; if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[2], false, out strResolution)) { strResolution = "1200"; } int iResolution = 1200; if (!Int32.TryParse(strResolution, out iResolution)) { iResolution = 1200; } string outputPath = ""; if (!bAttach) { SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Filter = "PDF files (*.pdf)|*.pdf"; pSaveFileDialog.Title = "Choose output location..."; string strInitDir = ""; if (StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strInitDir)) { if (System.IO.Directory.Exists(strInitDir)) { pSaveFileDialog.InitialDirectory = strInitDir; } } if (pSaveFileDialog.ShowDialog() != DialogResult.OK) { return(-1); } outputPath = pSaveFileDialog.FileName; } string inputPath = JTXUtilities.SaveJobMXD(JobID); if (bAttach) { outputPath = SystemUtilities.GetTemporaryFileLocation(inputPath, "pdf"); } // delete output file if it already exists System.IO.FileInfo fi = new System.IO.FileInfo(outputPath); if (fi.Exists) { fi.Delete(); } MapDocumentClass map = new MapDocumentClass(); if (!map.get_IsMapDocument(inputPath)) { throw new ApplicationException("Invalid map or specified map not found."); } map.Open(inputPath, null); IActiveView pActiveView = (IActiveView)map.PageLayout; IExport pExport = new ExportPDFClass(); pExport.ExportFileName = outputPath; tagRECT deviceFrameRect; deviceFrameRect.left = 0; deviceFrameRect.right = 800; deviceFrameRect.top = 0; deviceFrameRect.bottom = 600; pActiveView.ScreenDisplay.DisplayTransformation.set_DeviceFrame(ref deviceFrameRect); int iOutputResolution = iResolution; int iScreenResolution = 96; pExport.Resolution = iOutputResolution; IOutputRasterSettings pOutputRasterSettings = (IOutputRasterSettings)pExport; pOutputRasterSettings.ResampleRatio = 1; tagRECT exportRect; exportRect.left = pActiveView.ExportFrame.left * (iOutputResolution / iScreenResolution); exportRect.top = pActiveView.ExportFrame.top * (iOutputResolution / iScreenResolution); exportRect.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution); exportRect.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution); IEnvelope pPixelBoundsEnv = new EnvelopeClass(); pPixelBoundsEnv.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom); pExport.PixelBounds = pPixelBoundsEnv; int hdc = pExport.StartExporting(); pActiveView.Output(hdc, iOutputResolution, ref exportRect, null, null); pExport.FinishExporting(); pExport.Cleanup(); if (bAttach) { JTXUtilities.AddAttachmentToJob(JobID, outputPath, jtxFileStorageType.jtxStoreInDB); } return(0); } catch (Exception ex) { throw ex; } }