//导出
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (tbxSavePath.Text.Trim() == "" || !tbxSavePath.Text.Trim().Contains("\\"))
            {
                MessageBox.Show("请选择正确的输出路径!", "提示");
                return;
            }
            IExport pExport = null;

            try
            {
                switch (pSimpleFiletype)
                {
                case "tif":
                    pExport = new ExportTIFF() as IExport;
                    break;

                case "EMF":
                    pExport = new ExportEMF() as IExport;
                    break;

                case "eps":
                    pExport = new ExportPS() as IExport;
                    break;

                case "ai":
                    pExport = new ExportAI() as IExport;
                    break;

                case "pdf":
                    pExport = new ExportPDF() as IExport;
                    break;

                case "svg":
                    pExport = new ExportSVG() as IExport;
                    break;

                case "bmp":
                    pExport = new ExportBMP() as IExport;
                    break;

                case "jpg":
                    pExport = new ExportEMF() as IExport;
                    break;

                case "png":
                    pExport = new ExportPNG() as IExport;
                    break;

                case "gif":
                    pExport = new ExportGIF() as IExport;
                    break;

                default:
                    return;
                }
                pExport.ExportFileName = pSavePath;
                pExport.Resolution     = pResolution;
                tagRECT pTagRECT;
                pTagRECT = pActiveView.ExportFrame;
                IPrintAndExport printAndExport = new PrintAndExport();
                printAndExport.Export(pActiveView, pExport, pResolution, false, null);
                Marshal.ReleaseComObject(pExport);
                MessageBox.Show("导出成功!", "提示");
            }
            catch (COMException ex)
            {
                MessageBox.Show("导出失败\n" + ex.Message, "错误");
                return;
            }
        }
 private void PrintMap(string chem)
 {
     IMxDocument mxd = (IMxDocument)m_application.Document;
     IActiveView docActiveView = mxd.ActivatedView;
     IExport docExport = new ExportPNGClass();
     IPrintAndExport docPrintExport = new PrintAndExport();
     docExport.ExportFileName = string.Format(@"S:\Projects\TARRANT-Witchita\GIS\Figures\WaterQuality\{0}_{1}.png", cmbLayers.SelectedItem.ToString(), chem);
     docPrintExport.Export(docActiveView, docExport, 300, false, null);
 }
Example #3
0
        private bool ExportToPDF(string sFileName)
        {
            IMxDocument pMXDoc;
            IGraphicsContainer docGraphicsContainer;
            IElement docElement;
            IOutputRasterSettings docOutputRasterSettings;
            IMapFrame docMapFrame;
            IActiveView tmpActiveView;
            IActiveView pAV;
            IExport docExport;
            IPrintAndExport docPrintExport;
            System.Guid UID;

            try
            {
                pMXDoc = GetDoc();
                pAV = pMXDoc.ActiveView;

                /* This function sets the OutputImageQuality for the active view. If the active view is a pagelayout, then
                    * it must also set the output image quality for each of the maps in the pagelayout.
                    */
                if (pAV is IMap)
                {
                    docOutputRasterSettings = pAV.ScreenDisplay.DisplayTransformation
                        as IOutputRasterSettings;
                    docOutputRasterSettings.ResampleRatio = 1;
                    //pMXDoc.ActiveView = (IActiveView)pMXDoc.PageLayout;
                }
                else if (pAV is IPageLayout)
                {
                    //Assign ResampleRatio for PageLayout
                    docOutputRasterSettings = pAV.ScreenDisplay.DisplayTransformation
                        as IOutputRasterSettings;
                    docOutputRasterSettings.ResampleRatio = 1;
                    //and assign ResampleRatio to the maps in the PageLayout.
                    docGraphicsContainer = pAV as IGraphicsContainer;
                    docGraphicsContainer.Reset();
                    docElement = docGraphicsContainer.Next();
                    while (docElement != null)
                    {
                        if (docElement is IMapFrame)
                        {
                            docMapFrame = docElement as IMapFrame;
                            tmpActiveView = docMapFrame.Map as IActiveView;
                            docOutputRasterSettings =
                                tmpActiveView.ScreenDisplay.DisplayTransformation as
                                IOutputRasterSettings;
                            docOutputRasterSettings.ResampleRatio = 1;
                        }
                        docElement = docGraphicsContainer.Next();
                    }
                    docMapFrame = null;
                    docGraphicsContainer = null;
                    tmpActiveView = null;
                }
                //docOutputRasterSettings = null;
                //docOutputRasterSettings =(IOutputRasterSettings) pAV.ScreenDisplay.DisplayTransformation;
                //docOutputRasterSettings.ResampleRatio = 1;
                docExport = new ExportPDFClass();
                docPrintExport = new PrintAndExport();

                //Process myProc = new Process();
                //set the export filename (which is the nameroot + the appropriate file extension)
                UID = System.Guid.NewGuid();
                docExport.ExportFileName = sFileName + "_" + UID.ToString() + ".PDF";
                Logger.WriteLine("Export:" + docExport.ExportFileName);

                //Output Image Quality of the export.  The value here will only be used if the export
                // object is a format that allows setting of Output Image Quality, i.e. a vector exporter.
                // The value assigned to ResampleRatio should be in the range 1 to 5.
                // 1 corresponds to "Best", 5 corresponds to "Fast"

                // check if export is vector or raster
                if (docExport is IOutputRasterSettings)
                {
                    // for vector formats, assign the desired ResampleRatio to control drawing of raster layers at export time
                    //RasterSettings = (IOutputRasterSettings)docExport;
                    //RasterSettings.ResampleRatio = 1;

                    // NOTE: for raster formats output quality of the DISPLAY is set to 1 for image export
                    // formats by default which is what should be used
                }

                try
                {
                    docPrintExport.Export(pAV, docExport, 600, true, null);
                }
                catch (Exception EX)
                {
                    Logger.WriteLine("Error in 2ExportPDF " + EX.Message + "Stack" + EX.StackTrace);
                }
                //MessageBox.Show("Finished exporting " + sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "Export Active View Sample");
                pMXDoc.ActiveView = (IActiveView)pMXDoc.FocusMap;
                Logger.WriteLine("ExportToPDF:");
            }
            catch (COMException ComEX)
            {
                Logger.WriteLine("Error in ExportPDF " + ComEX.ErrorCode + " " + ComEX.Message + "Stack" + ComEX.StackTrace);
            }
            catch (Exception EX)
            {
                Logger.WriteLine("Error in ExportPDF " + EX.Message + "Stack" + EX.StackTrace);
            }
            return true;
        }