private void ShowOutputFileDialog(IActiveView docActiveView, int iOutputResolution = 320) { IExport docExport; IPrintAndExport docPrintExport; IWorldFileSettings worldFileSetting; //string localFilePath, fileNameExt, newFileName, FilePath; SaveFileDialog sfd = new SaveFileDialog(); //设置对话框标题 sfd.Title = "地图输出"; //设置文件类型 sfd.Filter = "EMF(*.emf)|*.emf|AI (*.ai) |*.ai|PDF (*.pdf)|*.pdf |SVG (*.svg)| *.svg|TIFF(*.tif)|*.tif|JPEG (*.jpg)| *.jpg|PNG (*.png)| *.png"; //设置默认文件类型显示顺序 sfd.FilterIndex = 5; //保存对话框是否记忆上次打开的目录 sfd.RestoreDirectory = true; //设置默认的文件名 int start = m_mapDocumentName.LastIndexOf("\\"); int end = m_mapDocumentName.LastIndexOf("."); sfd.FileName = m_mapDocumentName.Substring(start + 1, end - start - 1); //点了保存按钮进入 if (sfd.ShowDialog() == DialogResult.OK && sfd.FileName != "") { switch (sfd.FilterIndex) { case 1: { docExport = new ExportEMFClass(); break; } case 2: { docExport = new ExportAIClass(); break; } case 3: { docExport = new ExportPDFClass(); break; } case 4: { docExport = new ExportSVGClass(); break; } case 5: { docExport = new ExportTIFFClass(); IExportTIFF exportTiff = docExport as IExportTIFF; exportTiff.GeoTiff = true; exportTiff.CompressionType = esriTIFFCompression.esriTIFFCompressionLZW; break; } //对于TIFF格式导出带有地理配准的文件 case 6: { docExport = new ExportJPEGClass(); break; } case 7: { docExport = new ExportPNGClass(); break; } default: { docExport = new ExportTIFFClass(); break; } } docPrintExport = new PrintAndExportClass(); worldFileSetting = docExport as IWorldFileSettings; string localFilePath = sfd.FileName.ToString(); //获得文件路径 //string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径 docExport.ExportFileName = localFilePath; docPrintExport.Export(docActiveView, docExport, iOutputResolution, true, null); } }
private void button_save_Click(object sender, EventArgs e) { IActiveView docActiveView = axPageLayoutControl1.ActiveView; IExport docExport = new ExportJPEGClass(); IPrintAndExport docPrintExport = new PrintAndExportClass(); int iOutputResolution = 300; //设置输出文件名 docExport.ExportFileName = "D:\\a_gis工程设计实践课\\盗墓难度专题图.JPG"; //输出当前视图到输出文件 docPrintExport.Export(docActiveView, docExport, iOutputResolution, true, null); }
private void btnExport_Click(object sender, EventArgs e) { try { if (sfdExportMap.ShowDialog() != System.Windows.Forms.DialogResult.Cancel) { IExport docExport = null; string strSaveFile = string.Concat(sfdExportMap.FileName); int intDpi = Convert.ToInt32(nudDpi.Value); IActiveView docActiveView = pActiveView; //Can add other formats in here H.Koo 071515 if (sfdExportMap.FilterIndex == 1) { docExport = new ExportJPEG() as IExport; } else if (sfdExportMap.FilterIndex == 2) { docExport = new ExportPDF() as IExport; } else if (sfdExportMap.FilterIndex == 3) { docExport = new ExportTIFF() as IExport; } else if (sfdExportMap.FilterIndex == 4) { docExport = new ExportBMP() as IExport; } IPrintAndExport docPrintAndExport = new PrintAndExportClass(); docExport.ExportFileName = strSaveFile; docPrintAndExport.Export(docActiveView, docExport, intDpi, chkClip.Checked, null); docExport.Cleanup(); MessageBox.Show("Complete"); this.Close(); } } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
/* * Export */ private void exportToolStripMenuItem_Click(object sender, EventArgs e) { string outPath = OutputClass.OutPath(); IExport pExport = OutputClass.OutExport(outPath); IActiveView outActiveView = axPageLayoutControl1.ActiveView; pExport.ExportFileName = outPath; double outResolution = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.Resolution; IPrintAndExport outPrintnExport = new PrintAndExportClass(); outPrintnExport.Export(outActiveView, pExport, outResolution, true, null); MessageBox.Show("输出成功"); }
public void PrintActiveViewArcPressParameterized(int iResampleRatio) { /* Prints the Active View of the document with ArcPress */ IPrintAndExport PrintAndExport = new PrintAndExportClass(); IActiveView docActiveView = ArcMap.Document.ActiveView; IPrinter docPrinter; IArcPressPrinter docArcPressPrinter; string sNameRoot; short iNumPages; // assign the output path and filename. We can use the Filter property of the export object to // automatically assign the proper extension to the file. sNameRoot = ArcMap.Application.Document.Title.Substring(0, ArcMap.Application.Document.Title.Length - 4); //create new ArcPress printer classes docPrinter = new ArcPressPrinterClass(); docArcPressPrinter = new ArcPressPrinterClass(); try { //auto-select the driver based on the printer's name. docArcPressPrinter.AutoSelectDriverByName(ArcMap.ThisApplication.Paper.PrinterName); //if the printer cannot be auto-selected, exit. if (docArcPressPrinter.SelectedDriverId == null) { MessageBox.Show("Could not auto-select ArcPress driver for printer"); return; } //transfer the ArcPress printer properties into docPrinter docPrinter = (IPrinter)docArcPressPrinter; //the paper should be the same as the application's paper. docPrinter.Paper = ArcMap.ThisApplication.Paper; //make sure the paper orientation is set to the orientation matching the current view. docPrinter.Paper.Orientation = ArcMap.Document.PageLayout.Page.Orientation; //set the spool filename (this is the job name that shows up in the print queue) docPrinter.SpoolFileName = sNameRoot; // Find out how many printer pages the output will cover. iNumPages will always be 1 // unless the user explicitly sets the tiling options in the file->Print dialog. if (ArcMap.Document.ActiveView is IPageLayout) { ArcMap.Document.PageLayout.Page.PrinterPageCount(docPrinter, 0, out iNumPages); } else { iNumPages = 1; } for (short lCurrentPageNum = 1; lCurrentPageNum <= iNumPages; lCurrentPageNum++) { //the StepProgressor is what creates the bar graph of the print's progress. docPrinter.StepProgressor = ArcMap.Application.StatusBar.ProgressBar; try { PrintAndExport.Print(ArcMap.Document.ActiveView, docPrinter, ArcMap.Document.PageLayout.Page, lCurrentPageNum, iResampleRatio, null); } catch { MessageBox.Show("Error printing page " + lCurrentPageNum); } } } catch { MessageBox.Show("Could not auto-select ArcPress driver for this printer"); } }
private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType, string sOutputDir, Boolean bClipToGraphicsExtent) { /* EXPORT PARAMETER: (iOutputResolution) the resolution requested. * EXPORT PARAMETER: (lResampleRatio) 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" * EXPORT PARAMETER: (ExportType) a string which contains the export type to create. * EXPORT PARAMETER: (sOutputDir) a string which contains the directory to output to. * EXPORT PARAMETER: (bClipToGraphicsExtent) Assign True or False to determine if export image will be clipped to the graphic * extent of layout elements. This value is ignored for data view exports */ /* Exports the Active View of the document to selected output format. */ // using predefined static member IActiveView docActiveView = ArcMap.Document.ActiveView; IExport docExport; IPrintAndExport docPrintExport; IOutputRasterSettings RasterSettings; string sNameRoot; bool bReenable = false; if (GetFontSmoothing()) { /* font smoothing is on, disable it and set the flag to reenable it later. */ bReenable = true; DisableFontSmoothing(); if (GetFontSmoothing()) { //font smoothing is NOT successfully disabled, error out. return; } //else font smoothing was successfully disabled. } // The Export*Class() type initializes a new export class of the desired type. if (ExportType == "PDF") { docExport = new ExportPDFClass(); } else if (ExportType == "EPS") { docExport = new ExportPSClass(); } else if (ExportType == "AI") { docExport = new ExportAIClass(); } else if (ExportType == "BMP") { docExport = new ExportBMPClass(); } else if (ExportType == "TIFF") { docExport = new ExportTIFFClass(); } else if (ExportType == "SVG") { docExport = new ExportSVGClass(); } else if (ExportType == "PNG") { docExport = new ExportPNGClass(); } else if (ExportType == "GIF") { docExport = new ExportGIFClass(); } else if (ExportType == "EMF") { docExport = new ExportEMFClass(); } else if (ExportType == "JPEG") { docExport = new ExportJPEGClass(); } else { MessageBox.Show("Unsupported export type " + ExportType + ", defaulting to EMF."); ExportType = "EMF"; docExport = new ExportEMFClass(); } docPrintExport = new PrintAndExportClass(); //set the name root for the export sNameRoot = "ExportActiveViewSampleOutput"; //set the export filename (which is the nameroot + the appropriate file extension) docExport.ExportFileName = sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0]; //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 = (int)lResampleRatio; // 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 } docPrintExport.Export(docActiveView, docExport, iOutputResolution, bClipToGraphicsExtent, null); MessageBox.Show("Finished exporting " + sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "Export Active View Sample"); if (bReenable) { /* reenable font smoothing if we disabled it before */ EnableFontSmoothing(); bReenable = false; if (!GetFontSmoothing()) { //error: cannot reenable font smoothing. MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error"); } } }
public void ExportActiveViewParameterized(IActiveView docActiveView, long iOutputResolution, long lResampleRatio, string ExportType, string sOutputName, Boolean bClipToGraphicsExtent) { /* EXPORT PARAMETER: (iOutputResolution) the resolution requested. * EXPORT PARAMETER: (lResampleRatio) 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" * EXPORT PARAMETER: (ExportType) a string which contains the export type to create. * EXPORT PARAMETER: (sOutputDir) a string which contains the directory to output to. * EXPORT PARAMETER: (bClipToGraphicsExtent) Assign True or False to determine if export image will be clipped to the graphic * extent of layout elements. This value is ignored for data view exports */ /* Exports the Active View of the document to selected output format. */ // using predefined static member IExport docExport; IPrintAndExport docPrintExport; IOutputRasterSettings RasterSettings; string sNameRoot; bool bReenable = false; if (GetFontSmoothing()) { /* font smoothing is on, disable it and set the flag to reenable it later. */ bReenable = true; DisableFontSmoothing(); if (GetFontSmoothing()) { //font smoothing is NOT successfully disabled, error out. return; } //else font smoothing was successfully disabled. } // The Export*Class() type initializes a new export class of the desired type. if (ExportType == "PDF") { docExport = new ExportPDFClass(); } else if (ExportType == "EPS") { docExport = new ExportPSClass(); } else if (ExportType == "AI") { docExport = new ExportAIClass(); } else if (ExportType == "BMP") { docExport = new ExportBMPClass(); } else if (ExportType == "TIFF") { docExport = new ExportTIFFClass(); } else if (ExportType == "SVG") { docExport = new ExportSVGClass(); } else if (ExportType == "PNG") { docExport = new ExportPNGClass(); } else if (ExportType == "GIF") { docExport = new ExportGIFClass(); } else if (ExportType == "EMF") { docExport = new ExportEMFClass(); } else if (ExportType == "JPEG") { docExport = new ExportJPEGClass(); } else { MessageBox.Show("Unsupported export type " + ExportType + ", defaulting to EMF."); ExportType = "EMF"; docExport = new ExportEMFClass(); } docPrintExport = new PrintAndExportClass(); //set the name root for the export sNameRoot = "ExportActiveViewSampleOutput"; //set the export filename (which is the nameroot + the appropriate file extension) //docExport.ExportFileName = sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0]; docExport.ExportFileName = sOutputName; //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 = (int)lResampleRatio; // 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 } docPrintExport.Export(docActiveView, docExport, iOutputResolution, bClipToGraphicsExtent, null); //MessageBox.Show("Finished exporting " + sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "Export Active View Sample"); if (bReenable) { /* reenable font smoothing if we disabled it before */ EnableFontSmoothing(); bReenable = false; if (!GetFontSmoothing()) { //error: cannot reenable font smoothing. MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error"); } } }
private void mapOutPutToolStripMenuItem_Click(object sender, EventArgs e) { IActiveView docActiveView; IExport docExport; IPrintAndExport docPrintExport; //设置图片分辨率,下方注释掉的代码为根据监听当前窗口的分辨率来设置分辨率 //经测试发现将分辨率直接设置为300的情况下导出地图更清晰 int iOutputResolution = 300; //double iOutputResolution = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.Resolution; if (pageLayout.Checked == true)//输出pagelayout { docActiveView = axMapControl1.ActiveView; } else //输出mapview { docActiveView = axPageLayoutControl2.ActiveView; } // docExport = new ExportJPEGClass(); //docPrintExport = new PrintAndExportClass(); //设置输出的文件名 //选择保存格式,可以保存为jpg,png和pdf SaveFileDialog savefiledialog1 = new SaveFileDialog(); savefiledialog1.DefaultExt = ".jpg"; savefiledialog1.Filter = "JPG Documents (*.jpg)|*.jpg|PDF Documents(*.pdf)|*.pdf|PNG Documents(*.png)|*.png"; savefiledialog1.ShowDialog(); docExport = new ExportJPEGClass(); //设置保存的文件名 string Outpath = savefiledialog1.FileName; //得到输出文件的扩展名 string fileExtName = Outpath.Substring(Outpath.LastIndexOf(".") + 1).ToString(); if (fileExtName != "") { switch (fileExtName) { case "jpg": docExport = new ExportJPEGClass(); break; case "pdf": docExport = new ExportPDFClass(); break; case "png": docExport = new ExportPNGClass(); break; default: MessageBox.Show("只能保存为: jpg,pdf,png 格式"); break; } } docPrintExport = new PrintAndExportClass(); docExport.ExportFileName = Outpath; //输出当前视图到输出文件 docPrintExport.Export(docActiveView, docExport, iOutputResolution, true, null); }
//pagelayout不能设置图片大小,不能指定输出范围,由Page范围决定 //map必须设置图片大小,结合dpi决定输出的比例尺 private void Export10Plus(IActiveView docActiveView, string filename, int iDPI, int iWidth, int iHeight, IEnvelope pOutExtent) { IPrintAndExport docPrintExport = new PrintAndExportClass(); IExport docExport = CreateExport(filename, 1); if (docActiveView is IMap) { int iWidth_96 = (int)(iWidth * (96.0 / (double)iDPI)); int iHeight_96 = (int)(iHeight * (96.0 / (double)iDPI)); tagRECT pDeviceFrame = new tagRECT(); pDeviceFrame.top = 0; pDeviceFrame.left = 0; pDeviceFrame.right = iWidth_96; pDeviceFrame.bottom = iHeight_96; docActiveView.ScreenDisplay.DisplayTransformation.set_DeviceFrame(ref pDeviceFrame); } IEnvelope o_Env = null; if (pOutExtent != null) { o_Env = docActiveView.Extent.Envelope; docActiveView.Extent = pOutExtent; } docPrintExport.Export(docActiveView, docExport, iDPI, false, null); if (o_Env != null) docActiveView.Extent = o_Env; docExport.Cleanup(); }
public void PrintActiveViewParameterized(int iResampleRatio) { /* Prints the Active View of the document to selected output format. */ // IActiveView docActiveView = ArcMap.Document.ActiveView; IPrinter docPrinter; IPrintAndExport PrintAndExport = new PrintAndExportClass(); IPaper docPaper; /* printdocument is from the .NET assembly system.drawing.printing */ System.Drawing.Printing.PrintDocument sysPrintDocumentDocument; short iNumPages; /* Now we need to get the default printer name. Since this is a generic command, * we can't use the printername property of the document. So instead, we use the * System.Drawing.Printing objects to find the default printer. */ docPrinter = new EmfPrinterClass(); sysPrintDocumentDocument = new System.Drawing.Printing.PrintDocument(); docPaper = new PaperClass(); /* testing to see if printer instantiated in sysPrintDocumentDocument is the * default printer. It SHOULD be, but this is just a reality check. */ bool isDefault = sysPrintDocumentDocument.PrinterSettings.IsDefaultPrinter; if (isDefault) { //Set docPaper's printername to the printername of the default printer docPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName; } else { //if we get an unexpected result, return. MessageBox.Show("Error getting default printer info, exiting..."); return; } //make sure the paper orientation is set to the orientation matching the current view. docPaper.Orientation = ArcMap.Document.PageLayout.Page.Orientation; /* Now assign docPrinter the paper and with it the printername. This process is two steps * because you cannot change an IPrinter's printer except by passing it as a part of * the IPaper. That's why we setup docPrinter.Paper.PrinterName first. */ docPrinter.Paper = docPaper; //set the spoolfilename (this is the job name that shows up in the print queue) docPrinter.SpoolFileName = "PrintActiveViewSample"; // Find out how many printer pages the output will cover. if (ArcMap.Document.ActiveView is IPageLayout) { ArcMap.Document.PageLayout.Page.PrinterPageCount (docPrinter, 0, out iNumPages); } else { iNumPages = 1; } for (short lCurrentPageNum = 1; lCurrentPageNum <= iNumPages; lCurrentPageNum++) { try { PrintAndExport.Print(ArcMap.Document.ActiveView, docPrinter, ArcMap.Document.PageLayout.Page, lCurrentPageNum, iResampleRatio, null); } catch { //need to catch exceptions in PrintAndExport.Print - for instance if the job is cancelled. MessageBox.Show("An error has occurred."); } } }
public bool Export(ExportMapInfo info, out string outmsg) { bool result = false; bool hasright = true; outmsg = string.Empty; //hasright = InitialApp(out outmsg); if (hasright) { #region 地图元素参数设定 PageSize currentPageSize = PageSize.A4; PageOrientation currentPageOri = PageOrientation.Portrait; currentPageSize = (PageSize)int.Parse(info.PageSize); currentPageOri = (PageOrientation)int.Parse(info.PageOri); double left = 0, bottom = 0, right = 0, top = 0; double outlineoffset = 0; string[] margins = info.PageMargin.Split(','); if (margins.Length == 4) { left = double.Parse(margins[0]) + outlineoffset; bottom = double.Parse(margins[3]) + outlineoffset; top = double.Parse(margins[1]) + outlineoffset; right = double.Parse(margins[2]) + outlineoffset; } #endregion #region 根据mxd获取相关信息。 /// <summary> /// mxd文档 /// </summary> IMapDocument pMapDocument; IMapFrame pPageMapFrame; /// <summary> /// 制图接口 /// </summary> IPageLayout pPageLayout; /// <summary> /// 页面 /// </summary> IPage pPage; /// <summary> /// 当前地图 /// </summary> IMap pMap; /// <summary> /// 当前数据窗口 /// </summary> IActiveView pDataAV; /// <summary> /// 当前制图窗口 /// </summary> IActiveView pPageAV; IGraphicsContainer pGraphicsContainer; IGraphicsContainerSelect pGrapSel; IExport docExport; IPrintAndExport docPrintExport; pMapDocument = new MapDocumentClass(); info.MxdPath = printPath + "\\Mxds\\"; string mxdfile = info.MxdPath + (info.TemplateName.ToUpper().EndsWith(".MXD") ? info.TemplateName : info.TemplateName + ".mxd"); if (File.Exists(mxdfile)) { pMapDocument.Open(mxdfile, ""); pPageLayout = pMapDocument.PageLayout; pPage = pPageLayout.Page; pPageAV = pPageLayout as IActiveView; pDataAV = pPageAV.FocusMap as IActiveView; pMap = pPageAV.FocusMap; pGraphicsContainer = pPageLayout as IGraphicsContainer; pPageMapFrame = pGraphicsContainer.FindFrame(pPageAV.FocusMap) as IMapFrame; pGrapSel = pMapDocument.ActiveView as IGraphicsContainerSelect; docExport = new ExportPDFClass(); docPrintExport = new PrintAndExportClass(); try { //处理所见所得 if (mxdfile.ToUpper().EndsWith("TEMP.MXD")) { ////处理坐标系 //PageUtility.ReplaceSR(pPageControl, info.Wkid); //加载要打印的图层 if (info.Lyrs != null) { foreach (string lyr in info.Lyrs) { IMapDocument pLyrDocument = new MapDocumentClass(); pLyrDocument.Open(info.LyrPath + lyr, ""); pMap.AddLayer(pLyrDocument.get_Map(0).get_Layer(0)); //针对所见即所得,如果加载的是影像,现状,规划等大数据量的数据,则需要延时8s处理 Delay(10); pPageAV.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null); } } } IGeometry dataCenterGeo = EsriWktConverter.ConvertWKTToGeometry(info.DataCenter); IPoint dataCenter = dataCenterGeo as IPoint; PageSizeUtility.SetCenterAndScale(pPageLayout, dataCenter, info.Scale); SetPageTemplate(pPageLayout, dataCenter, left, right, top, bottom, currentPageSize, currentPageOri, info); //业务几何图形处理 if (info.BusinessShapes != null && info.BusinessShapes.Count > 0) { foreach (string str in info.BusinessShapes) { string[] strs = str.Split(';'); IGeometry shapeGeometry = EsriWktConverter.ConvertWKTToGeometry(strs[0]); IPolygon pPolygon = shapeGeometry as IPolygon; if (pPolygon != null) { //地块样式 IRgbColor shapeFillRgbColor = new RgbColorClass(); shapeFillRgbColor.NullColor = true; IRgbColor shapeBorderRGBColor = new RgbColorClass(); shapeBorderRGBColor.Red = 255; shapeBorderRGBColor.Green = 0; shapeBorderRGBColor.Blue = 0; double shapeBorderWidth = 1.5; // 颜色组织 a,r,g,b // 业务数据 shapewkt;bordercolor;fillcolor;borderthickness if (strs.Length == 4) { string[] bordercolorargb = strs[1].Split(','); if (bordercolorargb.Length == 4) { int ba = 255, br = 255, bg = 0, bb = 0; int.TryParse(bordercolorargb[0], out ba); int.TryParse(bordercolorargb[1], out br); int.TryParse(bordercolorargb[2], out bg); int.TryParse(bordercolorargb[3], out bb); shapeBorderRGBColor.Red = br; shapeBorderRGBColor.Green = bg; shapeBorderRGBColor.Blue = bb; shapeBorderRGBColor.Transparency = (byte)ba; } string[] fillcolorargb = strs[2].Split(','); if (fillcolorargb.Length == 4) { int fa = 0, fr = 255, fg = 0, fb = 0; int.TryParse(fillcolorargb[0], out fa); int.TryParse(fillcolorargb[1], out fr); int.TryParse(fillcolorargb[2], out fg); int.TryParse(fillcolorargb[3], out fb); shapeFillRgbColor.Red = fr; shapeFillRgbColor.Green = fg; shapeFillRgbColor.Blue = fb; shapeFillRgbColor.Transparency = (byte)fa; } string borderwidth = strs[3]; double.TryParse(borderwidth, out shapeBorderWidth); } PageElementUtility.AddPolygonElement(pMapDocument, pPolygon, shapeBorderWidth, shapeFillRgbColor, shapeBorderRGBColor); } } } //标注处理 if (info.Labels != null && info.Labels.Count > 0) { foreach (string str in info.Labels) { string[] strs = str.Split(';'); string name = strs[0]; string labelxywkt = strs[1]; string labelwkt = strs[2]; //注记数据 name;labelxywkt;labelwkt;fontname;fontsize;fontcolor;labelbordercolor;labelfillcolor;labelborderthikness IRgbColor labelFontColor = new RgbColorClass(); IRgbColor labelBorderColor = new RgbColorClass(); IRgbColor labelFillColor = new RgbColorClass(); double labelBorderWidth = 1; int fontSize = 14; string fontName = "宋体"; if (strs.Length == 9) { fontName = string.IsNullOrEmpty(strs[3]) ? "宋体" : strs[3]; int.TryParse(strs[4], out fontSize); string[] fontcolorargb = strs[5].Split(','); if (fontcolorargb.Length == 4) { int fa = 0, fr = 255, fg = 0, fb = 0; int.TryParse(fontcolorargb[0], out fa); int.TryParse(fontcolorargb[1], out fr); int.TryParse(fontcolorargb[2], out fg); int.TryParse(fontcolorargb[3], out fb); labelFontColor.Red = fr; labelFontColor.Green = fg; labelFontColor.Blue = fb; labelFontColor.Transparency = (byte)fa; } string[] labelborderargb = strs[6].Split(','); if (labelborderargb.Length == 4) { int ba = 0, br = 255, bg = 0, bb = 0; int.TryParse(labelborderargb[0], out ba); int.TryParse(labelborderargb[1], out br); int.TryParse(labelborderargb[2], out bg); int.TryParse(labelborderargb[3], out bb); labelBorderColor.Red = br; labelBorderColor.Green = bg; labelBorderColor.Blue = bb; labelBorderColor.Transparency = (byte)ba; } string[] labelfillargb = strs[7].Split(','); if (labelfillargb.Length == 4) { int lfa = 0, lfr = 255, lfg = 0, lfb = 0; int.TryParse(labelfillargb[0], out lfa); int.TryParse(labelfillargb[1], out lfr); int.TryParse(labelfillargb[2], out lfg); int.TryParse(labelfillargb[3], out lfb); labelFillColor.Red = lfr; labelFillColor.Green = lfg; labelFillColor.Blue = lfb; labelFillColor.Transparency = (byte)lfa; } double.TryParse(strs[8], out labelBorderWidth); } IGeometry labelxyGeometry = EsriWktConverter.ConvertWKTToGeometry(labelxywkt); IPoint pLabelXY = labelxyGeometry as IPoint; double labelX = pLabelXY.X; double labelY = pLabelXY.Y; IGeometry labelGeometry = EsriWktConverter.ConvertWKTToGeometry(labelwkt); IPolygon pLabelPolygon = labelGeometry as IPolygon; PageElementUtility.AddPolygonElement(pMapDocument, pLabelPolygon, labelBorderWidth, labelFillColor, labelBorderColor); PageElementUtility.AddTextElement(pMapDocument, labelX, labelY, name, fontSize, fontName, labelFontColor); } } info.OutPath = printPath + "\\LocalFiles\\"; try { foreach (string tmpPath in info.AdditionalImages) { PageElementUtility.AddImageElement(pPageLayout , info.OutPath + tmpPath , Guid.NewGuid().ToString() , ElementPosition.DBL , 0.05 , 0.05); } } catch { } string tmpfilename = (info.TemplateName.ToUpper().EndsWith(".MXD") ? info.TemplateName.Substring(0, info.TemplateName.Length - 4) : info.TemplateName) + Guid.NewGuid().ToString() + ".pdf"; info.OutPath += tmpfilename; switch (info.ExportFormat.Trim().ToUpper()) { case "PDF": docExport = new ExportPDFClass(); break; case "BMP": docExport = new ExportBMPClass(); info.OutPath = info.OutPath.Replace(".pdf", ".bmp"); break; case "JPG": docExport = new ExportJPEGClass(); info.OutPath = info.OutPath.Replace(".pdf", ".jpg"); break; default: docExport = new ExportPDFClass(); break; } docExport.ExportFileName = info.OutPath; docPrintExport.Export(pPageAV, docExport, info.DPI, false, null); outmsg = printIISRoot + tmpfilename; result = true; } catch (Exception ex) { result = false; outmsg = string.Format("制图错误:坐标系是否一致——{0}", ex.Message); } finally { ReleaseObject(pMapDocument); ReleaseObject(docExport); ReleaseObject(docPrintExport); } } else { result = false; outmsg = "制图模板:" + info.MxdPath + GetFilePath() + "未找到!"; } #endregion } else { result = hasright; } return(result); }
//Function: Export map //Date: 2019/4/3 public void ExportMap(int pOutputResolution, string pExportFileName, bool pWriteWorldFile, double pWidth, double pHeight) { IActiveView docActiveView; IExport docExport; IPrintAndExport docPrintExport; IWorldFileSettings pWorldFile = null; ESRI.ArcGIS.esriSystem.tagRECT userRECT = new ESRI.ArcGIS.esriSystem.tagRECT(); IEnvelope pEnv = new EnvelopeClass(); string pFileType; int pFileNameLength = pExportFileName.Length; if (pFileNameLength > 3) { pFileType = pExportFileName.Substring(pFileNameLength - 3, 3); } else { pFileType = pExportFileName; } switch (pFileType) { case "jpg": docExport = new ExportJPEGClass(); break; case "png": docExport = new ExportPNGClass(); break; case "tif": docExport = new ExportTIFFClass(); break; default: docExport = new ExportJPEGClass(); break; } if (miLayoutView.Checked) { docActiveView = axPageLayoutControl1.ActiveView; } else { docActiveView = axMapControl1.ActiveView; } pEnv = docActiveView.Extent; pWorldFile = (IWorldFileSettings)docExport; pWorldFile.MapExtent = pEnv; pWorldFile.OutputWorldFile = pWriteWorldFile; userRECT.left = 0; userRECT.top = 0; userRECT.right = Convert.ToInt32(pWidth); userRECT.bottom = Convert.ToInt32(pHeight); IEnvelope pDriverBounds = new EnvelopeClass(); pDriverBounds.PutCoords(userRECT.top, userRECT.bottom, userRECT.right, userRECT.top); docExport.PixelBounds = pDriverBounds; docPrintExport = new PrintAndExportClass(); docExport.ExportFileName = pExportFileName; docPrintExport.Export(docActiveView, docExport, pOutputResolution, true, null); }
public void exportMapa(string ExportType, long iOutputResolution, long lResampleRatio, Boolean bClipToGraphicsExtent, string nombreArchivo,string sOutputDir) { IActiveView docActiveView = ArcMap.Document.ActiveView; IExport docExport; IPrintAndExport docPrintExport; IOutputRasterSettings RasterSettings; bool bReenable = false; if (GetFontSmoothing()) { /* font smoothing is on, disable it and set the flag to reenable it later. */ bReenable = true; DisableFontSmoothing(); if (GetFontSmoothing()) return; } // The Export*Class() type initializes a new export class of the desired type. if (ExportType == "PDF") { docExport = new ExportPDFClass(); } else if (ExportType == "EPS") { docExport = new ExportPSClass(); } else if (ExportType == "AI") { docExport = new ExportAIClass(); } else if (ExportType == "BMP") { docExport = new ExportBMPClass(); } else if (ExportType == "TIFF") { docExport = new ExportTIFFClass(); } else if (ExportType == "SVG") { docExport = new ExportSVGClass(); } else if (ExportType == "PNG") { docExport = new ExportPNGClass(); } else if (ExportType == "GIF") { docExport = new ExportGIFClass(); } else if (ExportType == "EMF") { docExport = new ExportEMFClass(); } else if (ExportType == "JPEG") { docExport = new ExportJPEGClass(); } else { MessageBox.Show("Unsupported export type " + ExportType + ", defaulting to EMF."); ExportType = "EMF"; docExport = new ExportEMFClass(); } docPrintExport = new PrintAndExportClass(); //set the export filename (which is the nameroot + the appropriate file extension) docExport.ExportFileName = sOutputDir + nombreArchivo + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0]; if (docExport is IOutputRasterSettings){ RasterSettings = (IOutputRasterSettings)docExport; RasterSettings.ResampleRatio = (int)lResampleRatio; } docPrintExport.Export(docActiveView, docExport, iOutputResolution, bClipToGraphicsExtent, null); if (bReenable) { /* reenable font smoothing if we disabled it before */ EnableFontSmoothing(); bReenable = false; if (!GetFontSmoothing()) MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error"); } }
public void PrintActiveViewParameterized(int iResampleRatio) { /* Prints the Active View of the document to selected output format. */ // IActiveView docActiveView = ArcMap.Document.ActiveView; IPrinter docPrinter; IPrintAndExport PrintAndExport = new PrintAndExportClass(); IPaper docPaper; /* printdocument is from the .NET assembly system.drawing.printing */ System.Drawing.Printing.PrintDocument sysPrintDocumentDocument; short iNumPages; /* Now we need to get the default printer name. Since this is a generic command, * we can't use the printername property of the document. So instead, we use the * System.Drawing.Printing objects to find the default printer. */ docPrinter = new EmfPrinterClass(); sysPrintDocumentDocument = new System.Drawing.Printing.PrintDocument(); docPaper = new PaperClass(); /* testing to see if printer instantiated in sysPrintDocumentDocument is the * default printer. It SHOULD be, but this is just a reality check. */ bool isDefault = sysPrintDocumentDocument.PrinterSettings.IsDefaultPrinter; if (isDefault) { //Set docPaper's printername to the printername of the default printer docPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName; } else { //if we get an unexpected result, return. MessageBox.Show("Error getting default printer info, exiting..."); return; } //make sure the paper orientation is set to the orientation matching the current view. docPaper.Orientation = ArcMap.Document.PageLayout.Page.Orientation; /* Now assign docPrinter the paper and with it the printername. This process is two steps * because you cannot change an IPrinter's printer except by passing it as a part of * the IPaper. That's why we setup docPrinter.Paper.PrinterName first. */ docPrinter.Paper = docPaper; //set the spoolfilename (this is the job name that shows up in the print queue) docPrinter.SpoolFileName = "PrintActiveViewSample"; // Find out how many printer pages the output will cover. if (ArcMap.Document.ActiveView is IPageLayout) { ArcMap.Document.PageLayout.Page.PrinterPageCount(docPrinter, 0, out iNumPages); } else { iNumPages = 1; } for (short lCurrentPageNum = 1; lCurrentPageNum <= iNumPages; lCurrentPageNum++) { try { PrintAndExport.Print(ArcMap.Document.ActiveView, docPrinter, ArcMap.Document.PageLayout.Page, lCurrentPageNum, iResampleRatio, null); } catch { //need to catch exceptions in PrintAndExport.Print - for instance if the job is cancelled. MessageBox.Show("An error has occurred."); } } }