/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add ControlsExportMapCommandClass.OnClick implementation if (m_hookHelper == null) return; try { SaveFileDialog saveFileDlg = new SaveFileDialog(); saveFileDlg.Filter = "(*jpeg)|*jpeg|(*.tif)|*tif|(*.pdf)|*.pdf|(*.bmp)|*.bmp|(*.gif)|*.gif|(*.png)|*.png"; if (saveFileDlg.ShowDialog() == DialogResult.OK) { IExport export = null; if (1 == saveFileDlg.FilterIndex) { export = new ExportJPEGClass(); export.ExportFileName = saveFileDlg.FileName + ".jpeg"; } else if (2 == saveFileDlg.FilterIndex) { export = new ExportTIFFClass(); export.ExportFileName = saveFileDlg.FileName + ".tif"; } else if (3 == saveFileDlg.FilterIndex) { export = new ExportPDFClass(); export.ExportFileName = saveFileDlg.FileName/* + ".pdf"*/; } else if (4 == saveFileDlg.FilterIndex) { export = new ExportBMPClass(); export.ExportFileName = saveFileDlg.FileName/* + ".bmp"*/; } else if (5 == saveFileDlg.FilterIndex) { export = new ExportGIFClass(); export.ExportFileName = saveFileDlg.FileName/* + ".gif"*/; } else if (6 == saveFileDlg.FilterIndex) { export = new ExportPNGClass(); export.ExportFileName = saveFileDlg.FileName/* + ".png"*/; } int res = 96; export.Resolution = res; tagRECT exportRECT = (m_hookHelper.Hook as IMapControl3).ActiveView.ExportFrame; IEnvelope pENV = new EnvelopeClass(); pENV.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); export.PixelBounds = pENV; int Hdc = export.StartExporting(); IEnvelope pVisibleBounds = null; ITrackCancel pTrack = null; (m_hookHelper.Hook as IMapControl3).ActiveView.Output(Hdc, (int)export.Resolution, ref exportRECT, pVisibleBounds, pTrack); Application.DoEvents(); export.FinishExporting(); export.Cleanup(); } } catch { } }
private IExport CreateExport(string PathName, int iResampleRatio) { IExport docExport; string sExtionsName = PathName.Substring(PathName.LastIndexOf(".") + 1); sExtionsName = sExtionsName.ToUpper(); switch (sExtionsName) { case "PDF": docExport = new ExportPDFClass(); break; case "EPS": docExport = new ExportPSClass(); break; case "AI": docExport = new ExportAIClass(); break; case "BMP": docExport = new ExportBMPClass(); break; case "TIFF": docExport = new ExportTIFFClass(); break; case "TIF": docExport = new ExportTIFFClass(); break; case "SVG": docExport = new ExportSVGClass(); break; case "PNG": docExport = new ExportPNGClass(); break; case "GIF": docExport = new ExportGIFClass(); break; case "EMF": docExport = new ExportEMFClass(); break; case "JPEG": docExport = new ExportJPEGClass(); break; case "JPG": docExport = new ExportJPEGClass(); break; default: docExport = new ExportJPEGClass(); break; } if (docExport is IOutputRasterSettings) { if (iResampleRatio < 1) iResampleRatio = 1; if (iResampleRatio > 5) iResampleRatio = 5; IOutputRasterSettings RasterSettings = (IOutputRasterSettings)docExport; RasterSettings.ResampleRatio = iResampleRatio; } docExport.ExportFileName = PathName; return docExport; }
/// <summary>Exports the page layout to a file.</summary> /// <param name="pageLayout">The page layout.</param> /// <param name="exportPath">The name of the output file.</param> /// <param name="exportFormat">The format of the output.</param> /// <param name="dpi">The resolution of the output files.</param> void ExportPageLayoutToFile(IPageLayout pageLayout, string exportPath, long dpi, ExportFormat exportFormat) { IExport export = null; // Get the color of the backgrounds for formats that support transparent backgrounds. IColor bgColor = null; switch (exportFormat) { case ExportFormat.GIF: case ExportFormat.PNG: IPage page = pageLayout.Page; bgColor = page.BackgroundColor; break; } // Set "export" to the proper type of Export*Class, and set parameters specific to that image type. switch (exportFormat) { case ExportFormat.AI: export = new ExportAIClass(); var ai = export as IExportAI2; //ai.EmbedFonts = true; break; case ExportFormat.EMF: export = new ExportEMFClass(); var xEmf = export as IExportEMF; //xEmf.Description = break; case ExportFormat.PS: export = new ExportPSClass(); var xPs = export as IExportPS; xPs.EmbedFonts = true; //xPs.Emulsion = //xPs.Image = //xPs.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone //xPs.LanguageLevel = esriExportPSLanguageLevel.esriExportPSLevel3 break; case ExportFormat.SVG: export = new ExportSVGClass(); var xSvg = export as IExportSVG; //xSvg.Compressed = true; //xSvg.EmbedFonts = true; break; case ExportFormat.PDF: export = new ExportPDFClass(); var xPdf = export as IExportPDF; //xPdf.Compressed = true; //xPdf.EmbedFonts = true; //xPdf.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone break; case ExportFormat.GIF: export = new ExportGIFClass(); IExportGIF xGif = export as IExportGIF; xGif.TransparentColor = bgColor; //xGif.BiLevelThreshold = //xGif.CompressionType = esriGIFCompression.esriGIFCompressionNone; //xGif.InterlaceMode = false; break; case ExportFormat.PNG: export = new ExportPNGClass(); IExportPNG xPng = export as IExportPNG; //xPng.BiLevelThreshold = //xPng.InterlaceMode = false; xPng.TransparentColor = bgColor; break; case ExportFormat.BMP: export = new ExportBMPClass(); IExportBMP xBmp = export as IExportBMP; //xBmp.BiLevelThreshold = //xBmp.RLECompression = true; break; case ExportFormat.JPEG: export = new ExportJPEGClass(); IExportJPEG xJpg = export as IExportJPEG; //xJpg.ProgressiveMode = false; //xJpg.Quality = 80; //The JPEG compression / image quality. Range (0..100). Default is 100 (no compression / best quality). break; case ExportFormat.TIFF: export = new ExportTIFFClass(); IExportTIFF xTif = export as IExportTIFF; //xTif.BiLevelThreshold = //xTif.CompressionType = //xTif.GeoTiff = true; //The JPEG or Deflate (depending on the Compression type) compression / image quality. Range (0..100). Default is 100 (no compression / best quality). //xTif.JPEGOrDeflateQuality = 100; break; default: const string MSG_FMT = "Support for \"{0}\" export is not yet implemented."; string message = string.Format(MSG_FMT, Enum.GetName(typeof(ExportFormat), exportFormat)); throw new NotImplementedException(message); } IEnvelope pixelEnv = new EnvelopeClass(); IEnvelope pageExt = GetPageExtent(pageLayout); IPoint upperRight = pageExt.UpperRight; pixelEnv.PutCoords(0, 0, dpi * upperRight.X, dpi * upperRight.Y); export.PixelBounds = pixelEnv; export.Resolution = dpi; export.ExportFileName = exportPath; // //(device coordinates origin is upper left, ypositive is down) tagRECT expRect; expRect.left = (int)export.PixelBounds.LowerLeft.X; expRect.bottom = (int)export.PixelBounds.UpperRight.Y; expRect.right = (int)export.PixelBounds.UpperRight.X; expRect.top = (int)export.PixelBounds.LowerLeft.Y; _app.StatusBar.set_Message(0, string.Format("exporting \"{0}\"", exportPath)); long hdc = export.StartExporting(); IActiveView av = (IActiveView)pageLayout; av.Output((int)hdc, (int)dpi, ref expRect, null, null); export.FinishExporting(); export.Cleanup(); }
/// <summary> /// 输出图片 /// </summary> /// <param name="activeView"></param> /// <param name="filename"></param> /// <param name="format"></param> /// <param name="resolution"></param> public static void ExportRasterFile(IActiveView activeView, string filename, string format, double resolution) { if (activeView == null || filename.Length == 0) { return; } double screenResolution = resolution; double outputResolution = resolution; IExport export = null; switch (format) { case "PDF": export = new ExportPDFClass(); IExportVectorOptions exportVectorOptions = export as IExportVectorOptions; exportVectorOptions.PolygonizeMarkers = true; IExportPDF exportPDF = export as IExportPDF; exportPDF.EmbedFonts = true; break; case "BMP": export = new ExportBMPClass(); break; case "JPG": export = new ExportJPEGClass(); if (filename.IndexOf("彩信") != -1) { IExportJPEG exportJPEG = export as IExportJPEG; exportJPEG.Quality = 70; outputResolution = 70.0; } break; case "PNG": export = new ExportPNGClass(); break; case "TIF": export = new ExportTIFFClass(); break; case "GIF": export = new ExportGIFClass(); break; case "EMF": export = new ExportEMFClass(); break; case "SVG": export = new ExportSVGClass(); break; case "AI": export = new ExportAIClass(); break; case "EPS": export = new ExportPSClass(); break; } IGraphicsContainer docGraphicsContainer; IElement docElement; IOutputRasterSettings docOutputRasterSettings; IMapFrame docMapFrame; IActiveView tmpActiveView; IOutputRasterSettings doOutputRasterSettings; if (activeView is IMap) { doOutputRasterSettings = activeView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; doOutputRasterSettings.ResampleRatio = 3; } else if (activeView is IPageLayout) { doOutputRasterSettings = activeView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; doOutputRasterSettings.ResampleRatio = 4; //and assign ResampleRatio to the maps in the PageLayout. docGraphicsContainer = activeView as IGraphicsContainer; docGraphicsContainer.Reset(); docElement = docGraphicsContainer.Next(); int c = 0; while (docElement != null) { c += 1; 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; } else { docOutputRasterSettings = null; } //end export.ExportFileName = filename; export.Resolution = outputResolution; tagRECT exportRECT = activeView.ExportFrame; exportRECT.right = (int)(exportRECT.right * (outputResolution / screenResolution)); exportRECT.bottom = (int)(exportRECT.bottom * (outputResolution / screenResolution)); IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); export.PixelBounds = envelope; int hDC = export.StartExporting(); activeView.Output(hDC, Convert.ToInt32(export.Resolution), ref exportRECT, null, null); export.FinishExporting(); export.Cleanup(); }
/// <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; } }
//输出当前地图为图片 public static string ExportImage(IActiveView pActiveView) { if (pActiveView == null) { return(null); } try { SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Filter = "JPEG(*.jpg)|*.jpg|AI(*.ai)|*.ai|BMP(*.BMP)|*.bmp|EMF(*.emf)|*.emf|GIF(*.gif)|*.gif|PDF(*.pdf)|*.pdf|PNG(*.png)|*.png|EPS(*.eps)|*.eps|SVG(*.svg)|*.svg|TIFF(*.tif)|*.tif"; pSaveFileDialog.Title = "输出地图"; pSaveFileDialog.RestoreDirectory = true; pSaveFileDialog.FilterIndex = 1; if (pSaveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return(null); } string FileName = pSaveFileDialog.FileName; IExport pExporter = null; switch (pSaveFileDialog.FilterIndex) { case 1: pExporter = new ExportJPEGClass(); break; case 2: pExporter = new ExportBMPClass(); break; case 3: pExporter = new ExportEMFClass(); break; case 4: pExporter = new ExportGIFClass(); break; case 5: pExporter = new ExportAIClass(); break; case 6: pExporter = new ExportPDFClass(); break; case 7: pExporter = new ExportPNGClass(); break; case 8: pExporter = new ExportPSClass(); break; case 9: pExporter = new ExportSVGClass(); break; case 10: pExporter = new ExportTIFFClass(); break; default: MessageBox.Show("输出格式错误"); return(null); } IEnvelope pEnvelope = new EnvelopeClass(); ITrackCancel pTrackCancel = new CancelTrackerClass(); tagRECT ptagRECT; ptagRECT = pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame(); int pResolution = (int)(pActiveView.ScreenDisplay.DisplayTransformation.Resolution); pEnvelope.PutCoords(ptagRECT.left, ptagRECT.bottom, ptagRECT.right, ptagRECT.top); pExporter.Resolution = pResolution; pExporter.ExportFileName = FileName; pExporter.PixelBounds = pEnvelope; pActiveView.Output(pExporter.StartExporting(), pResolution, ref ptagRECT, pActiveView.Extent, pTrackCancel); pExporter.FinishExporting(); //释放资源 pSaveFileDialog.Dispose(); System.Runtime.InteropServices.Marshal.ReleaseComObject(pExporter); return(FileName); } catch { return(null); } }
private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType, string sOutputDir,string sOutputFileName, Boolean bClipToGraphicsExtent) { IActiveView docActiveView = m_hookHelper.ActiveView; IExport docExport; long iPrevOutputImageQuality; IOutputRasterSettings docOutputRasterSettings; IEnvelope PixelBoundsEnv; tagRECT exportRECT; tagRECT DisplayBounds; IDisplayTransformation docDisplayTransformation; IPageLayout docPageLayout; IEnvelope docMapExtEnv; long hdc; long tmpDC; long iScreenResolution; bool bReenable = false; IEnvelope docGraphicsExtentEnv; IUnitConverter pUnitConvertor; if (GetFontSmoothing()) { bReenable = true; DisableFontSmoothing(); if (GetFontSmoothing()) { return; } } 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("��֧�ֵ��������� " + ExportType + ", Ĭ�ϵ���ΪEMF��ʽ������"); ExportType = "EMF"; docExport = new ExportEMFClass(); } docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio; if (docExport is IExportImage) { SetOutputQuality(docActiveView, 1); } else { SetOutputQuality(docActiveView, lResampleRatio); } docExport.ExportFileName = sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0]; tmpDC = GetDC(0); iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X) ReleaseDC(0, (int)tmpDC); frmSetResolution mSetResolution = new frmSetResolution(iOutputResolution); mSetResolution.ShowDialog(); iOutputResolution = mSetResolution.m_Resolution ; docExport.Resolution = iOutputResolution; if (docActiveView is IPageLayout) { DisplayBounds = docActiveView.ExportFrame; docGraphicsExtentEnv = GetGraphicsExtent(docActiveView); } else { docDisplayTransformation = docActiveView.ScreenDisplay.DisplayTransformation; DisplayBounds = docDisplayTransformation.get_DeviceFrame(); } PixelBoundsEnv = new Envelope() as IEnvelope; if (bClipToGraphicsExtent && (docActiveView is IPageLayout)) { docGraphicsExtentEnv = GetGraphicsExtent(docActiveView); docPageLayout = docActiveView as PageLayout; pUnitConvertor = new UnitConverter(); PixelBoundsEnv.XMin = 0; PixelBoundsEnv.YMin = 0; PixelBoundsEnv.XMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution; PixelBoundsEnv.YMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution; exportRECT.bottom = (int)(PixelBoundsEnv.YMax) + 1; exportRECT.left = (int)(PixelBoundsEnv.XMin); exportRECT.top = (int)(PixelBoundsEnv.YMin); exportRECT.right = (int)(PixelBoundsEnv.XMax) + 1; docMapExtEnv = docGraphicsExtentEnv; } else { double tempratio = iOutputResolution / iScreenResolution; double tempbottom = DisplayBounds.bottom * tempratio; double tempright = DisplayBounds.right * tempratio; exportRECT.bottom = (int)Math.Truncate(tempbottom); exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = (int)Math.Truncate(tempright); PixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); docMapExtEnv = null; } docExport.PixelBounds = PixelBoundsEnv; try { hdc = docExport.StartExporting(); docActiveView.Output((int)hdc, (int)docExport.Resolution, ref exportRECT, docMapExtEnv, null); docExport.FinishExporting(); docExport.Cleanup(); MessageBox.Show("�ɹ����� " + sOutputDir + sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "�����ͼͼƬ", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("�����ͼͼƬ�����г������⣡", "�����ͼͼƬ", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { SetOutputQuality(docActiveView, iPrevOutputImageQuality); if (bReenable) { EnableFontSmoothing(); bReenable = false; if (!GetFontSmoothing()) { MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error"); } } docMapExtEnv = null; PixelBoundsEnv = null; } }
public static void ExportActiveView(IActiveView pView, long iOutputResolution, long lResampleRatio, string sExportType, string sOutputDir, string sOutputName, Boolean bClipToGraphicsExtent = true, IEnvelope pEnvelope = null) { //解决文件名错误 IActiveView docActiveView = pView; IExport docExport; long iPrevOutputImageQuality; IOutputRasterSettings docOutputRasterSettings; IEnvelope PixelBoundsEnv; tagRECT exportRECT; tagRECT DisplayBounds; IDisplayTransformation docDisplayTransformation; IPageLayout docPageLayout; IEnvelope docMapExtEnv; if (pEnvelope == null) pEnvelope = GetGraphicsExtent(pView); long hdc; long tmpDC; //string sNameRoot; long iScreenResolution; bool bReenable = false; IEnvelope docGraphicsExtentEnv; IUnitConverter pUnitConvertor; if (GetFontSmoothing()) { 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 (String.Compare(sExportType,"PDF",true) == 0) { docExport = new ExportPDFClass(); } else if (String.Compare(sExportType,"EPS",true) == 0) { docExport = new ExportPSClass(); } else if (String.Compare(sExportType,"AI",true) == 0) { docExport = new ExportAIClass(); } else if (String.Compare(sExportType,"BMP",true) == 0) { docExport = new ExportBMPClass(); } else if (String.Compare(sExportType,"TIFF",true) == 0) { docExport = new ExportTIFFClass(); } else if (String.Compare(sExportType,"SVG",true) == 0) { docExport = new ExportSVGClass(); } else if (String.Compare(sExportType,"PNG",true) == 0) { docExport = new ExportPNGClass(); } else if (String.Compare(sExportType,"GIF",true) == 0) { docExport = new ExportGIFClass(); } else if (String.Compare(sExportType,"EMF",true) == 0) { docExport = new ExportEMFClass(); } else if (String.Compare(sExportType,"JPEG",true) == 0 || String.Compare(sExportType,"JPG",true) == 0) { docExport = new ExportJPEGClass(); } else { MessageBox.Show("!!不支持的格式 " + sExportType + ", 默认导出 EMF."); sExportType = "EMF"; docExport = new ExportEMFClass(); } // save the previous output image quality, so that when the export is complete it will be set back. docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio; if (docExport is IExportImage) { // always set the output quality of the DISPLAY to 1 for image export formats SetOutputQuality(docActiveView, 1); } else { // for vector formats, assign the desired ResampleRatio to control drawing of raster layers at export time SetOutputQuality(docActiveView, lResampleRatio); } //set the name root for the export // sNameRoot = "ExportActiveViewSampleOutput"; //set the export filename (which is the nameroot + the appropriate file extension) docExport.ExportFileName = sOutputDir + "\\" + sOutputName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0]; tmpDC = GetDC(0); iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X) ReleaseDC(0, (int)tmpDC); docExport.Resolution = iOutputResolution; if (docActiveView is IPageLayout) { //get the bounds of the "exportframe" of the active view. DisplayBounds = docActiveView.ExportFrame; //set up pGraphicsExtent, used if clipping to graphics extent. docGraphicsExtentEnv = pEnvelope; } else { //Get the bounds of the deviceframe for the screen. docDisplayTransformation = docActiveView.ScreenDisplay.DisplayTransformation; DisplayBounds = docDisplayTransformation.get_DeviceFrame(); } PixelBoundsEnv = new Envelope() as IEnvelope; if (bClipToGraphicsExtent && (docActiveView is IPageLayout)) { docGraphicsExtentEnv = pEnvelope; docPageLayout = docActiveView as PageLayout; pUnitConvertor = new UnitConverter(); //assign the x and y values representing the clipped area to the PixelBounds envelope PixelBoundsEnv.XMin = 0; PixelBoundsEnv.YMin = 0; PixelBoundsEnv.XMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution; PixelBoundsEnv.YMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution; //'assign the x and y values representing the clipped export extent to the exportRECT exportRECT.bottom = (int)(PixelBoundsEnv.YMax) + 1; exportRECT.left = (int)(PixelBoundsEnv.XMin); exportRECT.top = (int)(PixelBoundsEnv.YMin); exportRECT.right = (int)(PixelBoundsEnv.XMax) + 1; //since we're clipping to graphics extent, set the visible bounds. docMapExtEnv = docGraphicsExtentEnv; } else { double tempratio = iOutputResolution / iScreenResolution; double tempbottom = DisplayBounds.bottom * tempratio; double tempright = DisplayBounds.right * tempratio; //'The values in the exportRECT tagRECT correspond to the width //and height to export, measured in pixels with an origin in the top left corner. exportRECT.bottom = (int)Math.Truncate(tempbottom); exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = (int)Math.Truncate(tempright); //populate the PixelBounds envelope with the values from exportRECT. // We need to do this because the exporter object requires an envelope object // instead of a tagRECT structure. PixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); //since it's a page layout or an unclipped page layout we don't need docMapExtEnv. docMapExtEnv = null; } // Assign the envelope object to the exporter object's PixelBounds property. The exporter object // will use these dimensions when allocating memory for the export file. docExport.PixelBounds = PixelBoundsEnv; // call the StartExporting method to tell docExport you're ready to start outputting. hdc = docExport.StartExporting(); // Redraw the active view, rendering it to the exporter object device context instead of the app display. // We pass the following values: // * hDC is the device context of the exporter object. // * exportRECT is the tagRECT structure that describes the dimensions of the view that will be rendered. // The values in exportRECT should match those held in the exporter object's PixelBounds property. // * docMapExtEnv is an envelope defining the section of the original image to draw into the export object. docActiveView.Output((int)hdc, (int)docExport.Resolution, ref exportRECT, docMapExtEnv, null); //finishexporting, then cleanup. docExport.FinishExporting(); docExport.Cleanup(); MessageBox.Show("成功导出地图: " + docExport.ExportFileName, "提示"); //set the output quality back to the previous value SetOutputQuality(docActiveView, iPrevOutputImageQuality); if (bReenable) { EnableFontSmoothing(); bReenable = false; if (!GetFontSmoothing()) { //error: cannot reenable font smoothing. MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error"); } } docMapExtEnv = null; PixelBoundsEnv = null; }
/// <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; } }
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"); } }
// Exports a given page layout or map frame to a variety of image formats, returns the image file path public static string exportImage(IMxDocument pMxDoc, string exportType, string dpi, string pathDocumentName, string mapFrameName) { // Define the activeView as either the page layout or the map frame // If the mapFrameName variable is null then the activeView is the page, otherwise it is set to the map frame name specified IMap pMap; IActiveView pActiveView = null; IMaps pMaps = pMxDoc.Maps; // Also construct output filename depending on the activeView / mapFrame input string pathFileName = string.Empty; if (mapFrameName == null) { pActiveView = pMxDoc.ActiveView; pathFileName = @pathDocumentName + "-" + dpi.ToString() + "dpi." + exportType; } else if (mapFrameName != null && LayoutElements.detectMapFrame(pMxDoc, mapFrameName)) { for (int i = 0; i <= pMaps.Count - 1; i++) { pMap = pMaps.get_Item(i); if (pMap.Name == mapFrameName) { pActiveView = pMap as IActiveView; } } pathFileName = @pathDocumentName + "-mapframe-" + dpi.ToString() + "dpi." + exportType; } else { return(null); } //Declare the export variable and set the file and path from the parameters IExport docExport; //parameter check if (pActiveView == null) { return(null); } // 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 { return(pathFileName); } docExport.ExportFileName = pathFileName; // Because we are exporting to a resolution that differs from screen // resolution, we should assign the two values to variables for use // in our sizing calculations System.Int32 screenResolution = 96; System.Int32 outputResolution = Convert.ToInt32(dpi); docExport.Resolution = outputResolution; // If input type is map frame calculate the export rectangle tagRECT exportRECT; // This is a structure exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = pActiveView.ExportFrame.right * (outputResolution / screenResolution); exportRECT.bottom = pActiveView.ExportFrame.bottom * (outputResolution / screenResolution); // Set up the PixelBounds envelope to match the exportRECT IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); docExport.PixelBounds = envelope; try { System.Int32 hDC = docExport.StartExporting(); pActiveView.Output(hDC, (System.Int16)docExport.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed docExport.FinishExporting(); docExport.Cleanup(); } catch (Exception e) { Debug.WriteLine("Error writing to file, probably a file permissions error. Check the exception message below for details."); Debug.WriteLine(e.Message); } //Return the path of the file return(pathFileName); }
private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType, string sOutputDir, string sNameRoot, Boolean bClipToGraphicsExtent, AxPageLayoutControl pageLayoutControl) { //解决文件名错误 sNameRoot = sNameRoot.Substring(1, sNameRoot.Length - 1); IActiveView docActiveView = pageLayoutControl.ActiveView; IExport docExport; long iPrevOutputImageQuality; IOutputRasterSettings docOutputRasterSettings; IEnvelope PixelBoundsEnv; tagRECT exportRECT; tagRECT DisplayBounds; IDisplayTransformation docDisplayTransformation; IPageLayout docPageLayout; IEnvelope docMapExtEnv; long hdc; long tmpDC; //string sNameRoot; long iScreenResolution; bool bReenable = false; IEnvelope docGraphicsExtentEnv; IUnitConverter pUnitConvertor; if (GetFontSmoothing()) { 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("!!不支持的格式 " + ExportType + ", 默认导出 EMF."); ExportType = "EMF"; docExport = new ExportEMFClass(); } // save the previous output image quality, so that when the export is complete it will be set back. docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio; if (docExport is IExportImage) { // always set the output quality of the DISPLAY to 1 for image export formats SetOutputQuality(docActiveView, 1); } else { // for vector formats, assign the desired ResampleRatio to control drawing of raster layers at export time SetOutputQuality(docActiveView, lResampleRatio); } //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]; tmpDC = GetDC(0); iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X) ReleaseDC(0, (int)tmpDC); docExport.Resolution = iOutputResolution; if (docActiveView is IPageLayout) { //get the bounds of the "exportframe" of the active view. DisplayBounds = docActiveView.ExportFrame; //set up pGraphicsExtent, used if clipping to graphics extent. docGraphicsExtentEnv = GetGraphicsExtent(docActiveView); } else { //Get the bounds of the deviceframe for the screen. docDisplayTransformation = docActiveView.ScreenDisplay.DisplayTransformation; DisplayBounds = docDisplayTransformation.get_DeviceFrame(); } PixelBoundsEnv = new Envelope() as IEnvelope; if (bClipToGraphicsExtent && (docActiveView is IPageLayout)) { docGraphicsExtentEnv = GetGraphicsExtent(docActiveView); docPageLayout = docActiveView as PageLayout; pUnitConvertor = new UnitConverter(); //assign the x and y values representing the clipped area to the PixelBounds envelope PixelBoundsEnv.XMin = 0; PixelBoundsEnv.YMin = 0; PixelBoundsEnv.XMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution; PixelBoundsEnv.YMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution; //'assign the x and y values representing the clipped export extent to the exportRECT exportRECT.bottom = (int)(PixelBoundsEnv.YMax) + 1; exportRECT.left = (int)(PixelBoundsEnv.XMin); exportRECT.top = (int)(PixelBoundsEnv.YMin); exportRECT.right = (int)(PixelBoundsEnv.XMax) + 1; //since we're clipping to graphics extent, set the visible bounds. docMapExtEnv = docGraphicsExtentEnv; } else { double tempratio = iOutputResolution / iScreenResolution; double tempbottom = DisplayBounds.bottom * tempratio; double tempright = DisplayBounds.right * tempratio; //'The values in the exportRECT tagRECT correspond to the width //and height to export, measured in pixels with an origin in the top left corner. exportRECT.bottom = (int)Math.Truncate(tempbottom); exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = (int)Math.Truncate(tempright); //populate the PixelBounds envelope with the values from exportRECT. // We need to do this because the exporter object requires an envelope object // instead of a tagRECT structure. PixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); //since it's a page layout or an unclipped page layout we don't need docMapExtEnv. docMapExtEnv = null; } // Assign the envelope object to the exporter object's PixelBounds property. The exporter object // will use these dimensions when allocating memory for the export file. docExport.PixelBounds = PixelBoundsEnv; // call the StartExporting method to tell docExport you're ready to start outputting. hdc = docExport.StartExporting(); // Redraw the active view, rendering it to the exporter object device context instead of the app display. // We pass the following values: // * hDC is the device context of the exporter object. // * exportRECT is the tagRECT structure that describes the dimensions of the view that will be rendered. // The values in exportRECT should match those held in the exporter object's PixelBounds property. // * docMapExtEnv is an envelope defining the section of the original image to draw into the export object. docActiveView.Output((int)hdc, (int)docExport.Resolution, ref exportRECT, docMapExtEnv, null); //finishexporting, then cleanup. docExport.FinishExporting(); docExport.Cleanup(); MessageBox.Show( "成功导出地图: " + sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "提示"); //set the output quality back to the previous value SetOutputQuality(docActiveView, iPrevOutputImageQuality); if (bReenable) { EnableFontSmoothing(); bReenable = false; if (!GetFontSmoothing()) { //error: cannot reenable font smoothing. MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error"); } } docMapExtEnv = null; PixelBoundsEnv = null; }
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; }
private void button2_Click(object sender, EventArgs e) { if (System.IO.File.Exists(textBoxFileName.Text.ToString()) == true) { MessageBox.Show("该文件已经存在,请重新命名!"); textBoxFileName.SelectAll(); } else { IExport pExport = null; IWorldFileSettings pWorldFile = null; IExportImage pExportType; IEnvelope pDriverBounds = null; ESRI.ArcGIS.esriSystem.tagRECT userRECT = new ESRI.ArcGIS.esriSystem.tagRECT(); IEnvelope pEnv = new EnvelopeClass(); string FilePath = this.m_strFileName; string[] strFileName = FilePath.Split('.'); string strFileType = strFileName[1]; switch (strFileType) { case "jpg": pExport = new ExportJPEGClass(); break; case "bmp": pExport = new ExportBMPClass(); break; case "gif": pExport = new ExportGIFClass(); break; case "tif": pExport = new ExportTIFFClass(); break; case "png": pExport = new ExportPNGClass(); break; case "emf": pExport = new ExportEMFClass(); break; case "pdf": pExport = new ExportPDFClass(); break; case ".ai": pExport = new ExportAIClass(); break; case "svg": pExport = new ExportSVGClass(); break; default: pExport = new ExportJPEGClass(); break; } pExport.ExportFileName = this.m_strFileName; pExport.Resolution = Convert.ToInt32(numUDresolution.Value); pExportType = pExport as IExportImage; pExportType.ImageType = esriExportImageType.esriExportImageTypeTrueColor; pEnv = m_pageLayoutControl.ActiveView.Extent; pWorldFile = (IWorldFileSettings)pExport; pWorldFile.MapExtent = pEnv; pWorldFile.OutputWorldFile = false; userRECT.top = 0; userRECT.left = 0; userRECT.right = Convert.ToInt32(txtBoxWidth.Text); userRECT.bottom = Convert.ToInt32(txtBoxHeight.Text); pDriverBounds = new EnvelopeClass(); pDriverBounds.PutCoords(userRECT.top, userRECT.bottom, userRECT.right, userRECT.top); pExport.PixelBounds = pDriverBounds; ITrackCancel pTrackCancel = new TrackCancelClass(); m_pageLayoutControl.ActiveView.Output(pExport.StartExporting(), Convert.ToInt32(numUDresolution.Value), ref userRECT, m_pageLayoutControl.ActiveView.Extent, pTrackCancel); pExport.FinishExporting(); MessageBox.Show("打印图片保存成功!", "保存", MessageBoxButtons.OK); this.Close(); } }
private void btnPrint_Click(object sender, EventArgs e) { //创建保存文件对话框的实例 SaveFileDialog SaveFile = new SaveFileDialog(); //根据掩码文本框对对话框初始化 switch (comboBox1.SelectedIndex) { case 0: SaveFile.Filter = "bmp文件(*.bmp)|*.bmp"; SaveFile.Title = "保存bmb文件"; break; case 1: SaveFile.Filter = "emf文件(*.emf)|*.emf"; SaveFile.Title = "保存emp文件"; break; case 2: SaveFile.Filter = "gif文件(*.gif)|*.gif"; SaveFile.Title = "保存gif文件"; break; case 3: SaveFile.Filter = "jpg文件(*.jpeg)|*.jpeg"; SaveFile.Title = "保存jpg文件"; break; case 4: SaveFile.Filter = "PNG文件(*.png)|*.png"; SaveFile.Title = "保存png文件"; break; case 5: SaveFile.Filter = "TIFF文件(*.TIFF)|*.TIFF"; SaveFile.Title = "保存tiff文件"; break; case 6: SaveFile.Filter = "PDF文件(*.PDF)|*.pdf"; SaveFile.Title = "保存pdf文件"; break; } if (SaveFile.ShowDialog() == DialogResult.OK) { //打开保存文件对话框 并选择路径和文件名 SaveFile.AddExtension = true; //设置为自动补充文件扩展名 IExport pExport; switch (comboBox1.SelectedIndex) //根据掩码文本框的索引值穿件不同的pExport实例并调用Export方法 { case 0: pExport = new ExportBMPClass(); Export(pExport, SaveFile.FileName); break; case 1: pExport = new ExportEMFClass(); Export(pExport, SaveFile.FileName); break; case 2: pExport = new ExportGIFClass(); Export(pExport, SaveFile.FileName); break; case 3: pExport = new ExportJPEGClass(); Export(pExport, SaveFile.FileName); break; case 4: pExport = new ExportPNGClass(); Export(pExport, SaveFile.FileName); break; case 5: pExport = new ExportTIFFClass(); Export(pExport, SaveFile.FileName); break; case 6: pExport = new ExportPDFClass(); Export(pExport, SaveFile.FileName); break; } } }
private void ExportPDF(IActiveView activeView, string pathFileName) { IExport export = new ExportPDFClass(); export.ExportFileName = pathFileName; // Microsoft Windows default DPI resolution export.Resolution = 96; tagRECT exportRECT = activeView.ExportFrame; ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass(); envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); export.PixelBounds = envelope; System.Int32 hDC = export.StartExporting(); activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Finish writing the export file and cleanup any intermediate files export.FinishExporting(); export.Cleanup(); }
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); }
/// <summary> /// 导出视图为图片 /// </summary> /// <param name="activeView">地图视图</param> /// <param name="pathFileName">导出文件名称</param> /// <param name="bUseHiDpi">是否使用高分辨率,默认为true</param> public static void ExportActiveView(IActiveView activeView, string pathFileName, bool bUseHiDpi = true) { if (activeView == null || string.IsNullOrEmpty(pathFileName)) { return; } IExport export = null; if (pathFileName.EndsWith(".jpg")) { export = new ExportJPEGClass(); } else if (pathFileName.EndsWith(".tiff")) { export = new ExportTIFFClass(); } else if (pathFileName.EndsWith(".bmp")) { export = new ExportBMPClass(); } else if (pathFileName.EndsWith(".emf")) { export = new ExportEMFClass(); } else if (pathFileName.EndsWith(".png")) { export = new ExportPNGClass(); } else if (pathFileName.EndsWith(".gif")) { export = new ExportGIFClass(); } else if (pathFileName.EndsWith(".pdf")) { export = new ExportPDFClass(); } //DateTime dt = DateTime.Now; //string strTime = string.Format("{0:yyyyMMddHHmmss}", dt); //string fileName = System.IO.Path.GetFileNameWithoutExtension(pathFileName); //string mergeStr = string.Format(System.IO.Path.GetDirectoryName(pathFileName) + "\\" + fileName + strTime+System.IO.Path.GetExtension(pathFileName)); export.ExportFileName = pathFileName; // Because we are exporting to a resolution that differs from screen // resolution, we should assign the two values to variables for use // in our sizing calculations System.Int32 screenResolution = 96; System.Int32 outputResolution = bUseHiDpi ? 300 : 96; export.Resolution = outputResolution; tagRECT exportRECT; // This is a structure exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = activeView.ExportFrame.right * (outputResolution / screenResolution); exportRECT.bottom = activeView.ExportFrame.bottom * (outputResolution / screenResolution); // Set up the PixelBounds envelope to match the exportRECT IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); export.PixelBounds = envelope; int hDC = export.StartExporting(); activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed export.FinishExporting(); export.Cleanup(); }
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 static string ExportImage(IActiveView pActiveView) { if (pActiveView == null) { return null; } try { SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Filter = "JPEG(*.jpg)|*.jpg|AI(*.ai)|*.ai|BMP(*.BMP)|*.bmp|EMF(*.emf)|*.emf|GIF(*.gif)|*.gif|PDF(*.pdf)|*.pdf|PNG(*.png)|*.png|EPS(*.eps)|*.eps|SVG(*.svg)|*.svg|TIFF(*.tif)|*.tif"; pSaveFileDialog.Title = "输出地图"; pSaveFileDialog.RestoreDirectory = true; pSaveFileDialog.FilterIndex = 1; if (pSaveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return null; } string FileName = pSaveFileDialog.FileName; IExport pExporter = null; switch (pSaveFileDialog.FilterIndex) { case 1: pExporter = new ExportJPEGClass(); break; case 2: pExporter = new ExportBMPClass(); break; case 3: pExporter = new ExportEMFClass(); break; case 4: pExporter = new ExportGIFClass(); break; case 5: pExporter = new ExportAIClass(); break; case 6: pExporter = new ExportPDFClass(); break; case 7: pExporter = new ExportPNGClass(); break; case 8: pExporter = new ExportPSClass(); break; case 9: pExporter = new ExportSVGClass(); break; case 10: pExporter = new ExportTIFFClass(); break; default: MessageBox.Show("输出格式错误"); return null; } IEnvelope pEnvelope = new EnvelopeClass(); ITrackCancel pTrackCancel = new CancelTrackerClass(); tagRECT ptagRECT; ptagRECT = pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame(); int pResolution = (int)(pActiveView.ScreenDisplay.DisplayTransformation.Resolution); pEnvelope.PutCoords(ptagRECT.left, ptagRECT.bottom, ptagRECT.right, ptagRECT.top); pExporter.Resolution = pResolution; pExporter.ExportFileName = FileName; pExporter.PixelBounds = pEnvelope; pActiveView.Output(pExporter.StartExporting(), pResolution, ref ptagRECT, pActiveView.Extent, pTrackCancel); pExporter.FinishExporting(); //释放资源 pSaveFileDialog.Dispose(); System.Runtime.InteropServices.Marshal.ReleaseComObject(pExporter); return FileName; } catch { return null; } }
/// <summary> /// 导出PDF /// </summary> private void ExportPDF() { IActiveView pActiveView; pActiveView = axPageLayoutControl1.ActiveView; IEnvelope pEnv; pEnv = pActiveView.Extent; IExport pExport; pExport = new ExportPDFClass(); pExport.ExportFileName = @".\data\ExportPDF.pdf"; pExport.Resolution = 30; tagRECT exportRECT; exportRECT.top = 0; exportRECT.left = 0; exportRECT.right = (int)pEnv.Width; exportRECT.bottom = (int)pEnv.Height; IEnvelope pPixelBoundsEnv; pPixelBoundsEnv = new EnvelopeClass(); pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.bottom, exportRECT.right, exportRECT.top); pExport.PixelBounds = pPixelBoundsEnv; int hDC; hDC = pExport.StartExporting(); pActiveView.Output(hDC, (int)pExport.Resolution, ref exportRECT, null, null); pExport.FinishExporting(); pExport.Cleanup(); }