明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 6934|回复: 22

[打印] 在调用cad的.net api打印pdf文件效率很低

[复制链接]
发表于 2016-3-1 10:30 | 显示全部楼层 |阅读模式
大神们,你们好,我在调用cad的.net api生成pdf文档的时候,效率很低
具体需求
比如在一张图纸上我指定了4个区域,我想把这4个区域打印成4个pdf文件,如文件1,文件2,文件3,和文件4,生成这4个文件一般需要6分钟左右,效率很低下,测试的cad图纸不复杂,请问大神我问题出在哪,

下面贴上我的打印代码

Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            Transaction acTrans = acCurDb.TransactionManager.StartTransaction();

            try
            {
                using (acTrans)
                {
                    int flag = 0;
                    //获取当前布局管理器变量
                    LayoutManager acLayoutMgr = LayoutManager.Current;
                    //获取当前布局变量
                    Layout acLayout = (Layout)acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForRead);
                    //Layout acLayout = (Layout)acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite);
                    //获取当前布局的打印信息
                    PlotInfo acPlInfo = new PlotInfo()
                    {
                        Layout = acLayout.ObjectId
                    };

                    PlotSettings acPlSet = new PlotSettings(acLayout.ModelType);
                    acPlSet.CopyFrom(acLayout);
                    //着色打印选项,设置按线框进行打印
                    acPlSet.ShadePlot = PlotSettingsShadePlotType.Wireframe;
                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                    //打印比例
                    //用户标准打印
                    acPlSetVdr.SetUseStandardScale(acPlSet, true);
                    acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);

                    //居中打印
                    acPlSetVdr.SetPlotCentered(acPlSet, true);
                    //调用GetPlotStyleSheetList之后才可以使用SetCurrentStyleSheet
                    System.Collections.Specialized.StringCollection sc = acPlSetVdr.GetPlotStyleSheetList();
                    //设置打印样式表
                    acPlSetVdr.SetCurrentStyleSheet(acPlSet, "测试打印样式1.ctb");
                    PlotProgressDialog acPlProgDlg = new PlotProgressDialog(false, entitylist.Count, true);
                    foreach (FrameAttributeExtend frame in entitylist)
                    {
                        if (!Directory.Exists(directory))
                            Directory.CreateDirectory(directory);
                        flag++;
                        //比例
                        string entityscale = frame.Scale;
                        //横竖
                        string vertial = frame.IsVertial;
                        //图片索引
                        string picindex = frame.ImageIndex;
                        string imagename = "";
                        if (frame.ImageType == 0)
                        {
                            imagename = string.Format("1-{0}-{1}-{2}.pdf", entityscale, vertial, picindex);
                            totalflatimage = directory + imagename;
                        }
                        else
                        {
                            imagename = string.Format("2-{0}-{1}-{2}.pdf", entityscale, vertial, picindex);
                            imagelist.Add(directory + imagename);
                        }

                        //打印设备和图纸
                        if (vertial == "0")
                        {
                            //横向
                            acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ISO_expand_A4_(297.00_x_210.00_mm)");
                            acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000);
                        }
                        else
                        {
                            //竖向
                            acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ISO_expand_A4_(210.00_x_297.00_mm)");
                            acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000);
                        }
                        //设置是否使用打印样式
                        acPlSet.ShowPlotStyles = true;
                        //设置打印区域
                        Extents3d extents3d = frame.Extent;
                        //单位是米时
                        double h = double.Parse(entityscale) * 6;
                        double x = extents3d.MinPoint.X + unit * 2;
                        double y = extents3d.MaxPoint.Y + h + unit;
                        if (unit == 1)
                        {
                            x = extents3d.MinPoint.X + unit * 1;
                            y = extents3d.MaxPoint.Y + double.Parse(entityscale) / 250 + unit * 2;
                        }
                        Extents2d E2d = new Extents2d(x, extents3d.MinPoint.Y, extents3d.MaxPoint.X, y);
                        acPlSetVdr.SetPlotWindowArea(acPlSet, E2d);
                        acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
                        //重载和保存打印信息
                        acPlInfo.OverrideSettings = acPlSet;
                        //验证打印信息设置,看是否有误
                        PlotInfoValidator acPlInfoVdr = new PlotInfoValidator();
                        acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                        acPlInfoVdr.Validate(acPlInfo);

                        while (PlotFactory.ProcessPlotState != Autodesk.AutoCAD.PlottingServices.ProcessPlotState.NotPlotting)
                            continue;


                        PlotEngine acPlEng = PlotFactory.CreatePublishEngine();

                            #region BackUpCode

                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle, "图片输出");
                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "取消输出");
                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "输出进度");
                                acPlProgDlg.LowerPlotProgressRange = 0;
                                acPlProgDlg.UpperPlotProgressRange = 100;
                                acPlProgDlg.PlotProgressPos = 0;
                                acPlProgDlg.OnBeginPlot();
                                acPlProgDlg.IsVisible = true;
                                acPlEng.BeginPlot(acPlProgDlg, null);
                                acPlEng.BeginDocument(acPlInfo, "", null, 1, true, directory + imagename);
                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status, string.Format("正在输出第{0}张", flag.ToString()));
                                acPlProgDlg.OnBeginSheet();
                                acPlProgDlg.LowerSheetProgressRange = 0;
                                acPlProgDlg.UpperSheetProgressRange = 100;
                                acPlProgDlg.SheetProgressPos = 0;
                                PlotPageInfo acPlPageInfo = new PlotPageInfo();
                                acPlEng.BeginPage(acPlPageInfo, acPlInfo, true, null);
                                acPlEng.BeginGenerateGraphics(null);
                                acPlEng.EndGenerateGraphics(null);
                                acPlEng.EndPage(null);
                                acPlProgDlg.SheetProgressPos = 100;
                                acPlProgDlg.OnEndSheet();
                                acPlEng.EndDocument(null);
                                acPlProgDlg.PlotProgressPos = 100;
                                acPlProgDlg.OnEndPlot();
                                acPlEng.EndPlot(null);
                        acPlEng.Dispose();
                        acPlEng.Destroy();

                            #endregion
                        //}

                    }
                    acPlProgDlg.Dispose();
                    acPlProgDlg.Destroy();
                }
                while (PlotFactory.ProcessPlotState != Autodesk.AutoCAD.PlottingServices.ProcessPlotState.NotPlotting)
                    continue;
                //MessageBox.Show("打印完成!");
                在while循环中,等待的时间最久,似乎一直在等cad的打印机工作状态重置,另外,能不能把这4页生成到1个pdf文件里面呢,这样是否能够对效率做一些优化?

求大神指导,谢谢了!




发表于 2017-10-20 14:41 | 显示全部楼层
本帖最后由 mkhsj928 于 2017-10-20 15:13 编辑
  1. /// <summary>
  2.         /// 多页打印/预览函数
  3.         /// </summary>
  4.         /// <param name="pe"></param>
  5.         /// <param name="isPreview"></param>
  6.         /// <param name="plotList"></param>
  7.         /// <param name="sheetNumIfPreview"></param>
  8.         /// <param name="layoutCount"></param>
  9.         /// <param name="plotDevice"></param>
  10.         /// <param name="plotCanonicalMeida"></param>
  11.         /// <param name="plotStyle"></param>
  12.         /// <param name="saveFileName"></param>
  13.         /// <returns></returns>
  14.         private static PreviewEndPlotStatus MultiPlotOrPreview(
  15.         PlotEngine pe,
  16.         bool isPreview,
  17.         Dictionary<Extents2d, ObjectId> plotList,
  18.         int sheetNumIfPreview,
  19.         int layoutCount,//布局总数
  20.         string plotDevice,
  21.         string plotCanonicalMeida,
  22.         string plotStyle,
  23.         string saveFileName
  24.         )
  25.         {
  26.             PreviewEndPlotStatus ret = PreviewEndPlotStatus.Cancel;

  27.             string DocName = mCommands.Doc.Name;
  28.             DocName = DocName.Substring(DocName.LastIndexOf("\") + 1);
  29.             DocName = DocName.Substring(0, DocName.LastIndexOf("."));

  30.             #region 准备打印区域列表plotAreaList
  31.             Dictionary<Extents2d, ObjectId> plotAreaList = new Dictionary<Extents2d, ObjectId>();
  32.             if (isPreview && sheetNumIfPreview >= 0)
  33.             {
  34.                 KeyValuePair<Extents2d, ObjectId> kv = plotList.ElementAt(sheetNumIfPreview);
  35.                 plotAreaList.Add(kv.Key, kv.Value);//预览只能一个区域
  36.             }
  37.             else
  38.             {
  39.                 plotAreaList = plotList;//打印全部区域
  40.             }
  41.             #endregion

  42.             using (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
  43.             {
  44.                 try
  45.                 {
  46.                     using (PlotProgressDialog ppd = new PlotProgressDialog(isPreview, plotAreaList.Count, false))
  47.                     {
  48.                         #region 设置进度条显示信息                                    
  49.                         ppd.set_PlotMsgString(PlotMessageIndex.DialogTitle, "转换进度");
  50.                         ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "本布局转换进度:__/__");
  51.                         ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "总转换进度: __/__");

  52.                         ppd.LowerPlotProgressRange = 0;
  53.                         ppd.UpperPlotProgressRange = plotAreaList.Count;

  54.                         //显示进度条对话框
  55.                         ppd.OnBeginPlot();
  56.                         ppd.IsVisible = true;
  57.                         #endregion

  58.                         int pageNum = 0;//布局打印页计数
  59.                         int layoutPageNum = 0;//当前布局总打印页数(区域数)
  60.                         int sheetNum = 0;//所有打印页计数(打印总区域数)
  61.                         ObjectId layoutId = ObjectId.Null;//当前布局Id
  62.                         
  63.                         Layout lo = null;
  64.                         foreach (KeyValuePair<Extents2d, ObjectId> kv in plotAreaList)
  65.                         {
  66.                             if (kv.Value != layoutId)
  67.                             {
  68.                                 layoutId = kv.Value;

  69.                                 lo = mFun.m_OpenEntity(layoutId) as Layout;
  70.                                 LayoutManager.Current.CurrentLayout = lo.LayoutName;//切换为当前布局,是否必须?!!

  71.                                 pageNum=0;//重置布局页计数

  72.                                 layoutPageNum = plotAreaList.Count(a => a.Value == layoutId);

  73.                                 ppd.LowerSheetProgressRange = 0;
  74.                                 ppd.UpperSheetProgressRange = layoutPageNum;
  75.                             }

  76.                             pageNum++;//布局页计数+1
  77.                             sheetNum++;//总打印区域计数+1                    

  78.                             ppd.set_PlotMsgString(PlotMessageIndex.SheetName, $"{DocName}-{lo.LayoutName}");//打印文件名-布局名

  79.                             //设置打印配置参数
  80.                             PlotInfo pi = SetPlotInfo(lo, kv.Key, plotDevice, plotCanonicalMeida, plotStyle,isPreview);

  81.                             #region 启动打印
  82.                             if (sheetNum == 1)
  83.                             {
  84.                                 pe.BeginPlot(ppd, null);

  85.                                 pe.BeginDocument(
  86.                                     pi,                                     //打印信息
  87.                                     mCommands.Doc.Name,                     //当前图纸名
  88.                                     null,
  89.                                     1,                                      //打印份数
  90.                                     !isPreview,                             //是否打印至文件
  91.                                     isPreview ? "" : saveFileName           //保存文件名
  92.                                     );
  93.                             }
  94.                             #endregion

  95.                             #region 开始打印
  96.                             ppd.OnBeginSheet();                           

  97.                             ppd.SheetProgressPos = pageNum;
  98.                             ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, $"本布局转换进度:{pageNum}/{layoutPageNum}");

  99.                             ppd.PlotProgressPos = sheetNum;
  100.                             ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, $"总转换进度:sheetNum}/{plotAreaList.Count}");

  101.                             pe.BeginPage(
  102.                                 new PlotPageInfo(),
  103.                                 pi,                                 //打印信息
  104.                                 sheetNum == plotAreaList.Count,     //是否最后一页
  105.                                 null
  106.                                 );

  107.                             pe.BeginGenerateGraphics(null);
  108.                             pe.EndGenerateGraphics(null);

  109.                             PreviewEndPlotInfo pepi = new PreviewEndPlotInfo();
  110.                             pe.EndPage(pepi);//结束本页打印,返回预览状态
  111.                             ret = pepi.Status;
  112.                             #endregion
  113.                         }

  114.                         #region 结束打印
  115.                         ppd.OnEndSheet();
  116.                         pe.EndDocument(null);

  117.                         ppd.OnEndPlot();
  118.                         pe.EndPlot(null);
  119.                         #endregion
  120.                     }
  121.                 }
  122.                 catch (Autodesk.AutoCAD.Runtime.Exception e)
  123.                 {
  124.                     MessageBox.Show($"转换为单个PDF文档出错: {e.Message}!\n请选择【单幅分别保存】进行转换。", "转换出错", MessageBoxButtons.OK, MessageBoxIcon.Error);

  125.                     ret = PreviewEndPlotStatus.Cancel;
  126.                 }
  127.             }

  128.             return ret;
  129.         }
发表于 2017-10-20 14:40 | 显示全部楼层
  1. /// <summary>
  2.         /// 打印预览
  3.         /// </summary>
  4.         /// <returns></returns>
  5.         public static bool Preview(
  6.             Dictionary<ObjectId, List<Extents2d>> plotAreaDict,
  7.             string plotDevice,
  8.             string plotCanonicalMeida,
  9.             string plotStyle,
  10.             string saveFileName,
  11.             bool isPlotSingle//是否每页单独保存
  12.             )
  13.         {
  14.             bool ret = false;

  15.             if (plotAreaDict.Count == 0) return true;

  16.             #region 准备打印区域列表 PlotList
  17.             Dictionary<Extents2d, ObjectId> PlotList = new Dictionary<Extents2d, ObjectId>();
  18.             foreach (KeyValuePair<ObjectId, List<Extents2d>> kv in plotAreaDict)
  19.             {
  20.                 foreach (Extents2d plotArea in kv.Value)
  21.                 {
  22.                     PlotList.Add(plotArea, kv.Key);
  23.                 }
  24.             }
  25.             #endregion

  26.             if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
  27.             {
  28.                 #region 设置为前台打印
  29.                 object BackGroundPlotVar = mFun.m_GetSystemVar("BACKGROUNDPLOT");
  30.                 mFun.m_SetSystemVar("BACKGROUNDPLOT", 0);//一定要设置成0(前台打印),否则保存PDF文件中一个布局只会有一张图!!!!
  31.                 #endregion

  32.                 int sheetNum = 0;
  33.                 bool isFinished = false;//预览是否结束
  34.                 bool isReadyForPlot = false;//是否准备好打印

  35.                 while (!isFinished)
  36.                 {
  37.                     PreviewEngineFlags flags = PreviewEngineFlags.Plot;
  38.                     if (sheetNum > 0)
  39.                         flags |= PreviewEngineFlags.PreviousSheet;
  40.                     if (sheetNum < PlotList.Count - 1)
  41.                         flags |= PreviewEngineFlags.NextSheet;

  42.                     using (PlotEngine pe = PlotFactory.CreatePreviewEngine((int)flags))
  43.                     {
  44.                         PreviewEndPlotStatus stat = MultiPlotOrPreview(
  45.                             pe, true, PlotList, sheetNum, plotAreaDict.Count,
  46.                             plotDevice, plotCanonicalMeida, plotStyle, saveFileName
  47.                             );

  48.                         if (stat == PreviewEndPlotStatus.Next)
  49.                         {
  50.                             sheetNum++;
  51.                         }
  52.                         else if (stat == PreviewEndPlotStatus.Previous)
  53.                         {
  54.                             sheetNum--;
  55.                         }
  56.                         else if (stat == PreviewEndPlotStatus.Normal ||
  57.                                 stat == PreviewEndPlotStatus.Cancel)
  58.                         {
  59.                             isFinished = true;
  60.                         }
  61.                         else if (stat == PreviewEndPlotStatus.Plot)
  62.                         {
  63.                             isFinished = true;
  64.                             isReadyForPlot = true;

  65.                             ret = true;//结束
  66.                         }
  67.                     }
  68.                 }

  69.                 // If the plot button was used to exit the preview...

  70.                 if (isReadyForPlot)
  71.                 {
  72.                     if (!isPlotSingle)
  73.                     {
  74.                         using (PlotEngine pe = PlotFactory.CreatePublishEngine())
  75.                         {
  76.                             PreviewEndPlotStatus stat = MultiPlotOrPreview(
  77.                                 pe, false, PlotList, -1, plotAreaDict.Count,
  78.                                 plotDevice, plotCanonicalMeida, plotStyle, saveFileName
  79.                               );

  80.                             ret = stat == PreviewEndPlotStatus.Cancel ? false : true;
  81.                         }
  82.                     }
  83.                     else
  84.                     {
  85.                         #region 每页打印成一个PDF文件
  86.                         foreach (KeyValuePair<ObjectId, List<Extents2d>> kv in plotAreaDict)
  87.                         {
  88.                             int i = 1;
  89.                             foreach (Extents2d plotArea in kv.Value)
  90.                             {
  91.                                 MYAPP.mPlot.PlotSinglePage(
  92.                                     kv.Key, plotArea, plotDevice, plotCanonicalMeida, plotStyle,
  93.                                     string.Format("{0}-{1}({2})", saveFileName,mLayout.GetLayoutName(kv.Key), i++));
  94.                             }
  95.                         }
  96.                         #endregion
  97.                     }
  98.                 }

  99.                 //恢复变量
  100.                 mFun.m_SetSystemVar("BACKGROUNDPLOT", BackGroundPlotVar);
  101.             }
  102.             else
  103.             {
  104.                 mCommands.m_ed.WriteMessage("\n其他打印正在进行中!");
  105.             }

  106.             return ret;
  107.         }
发表于 2017-10-20 14:40 | 显示全部楼层
  1. /// <summary>
  2.         /// 设置打印信息
  3.         /// </summary>
  4.         /// <param name="layoutId">布局ID</param>
  5.         /// <param name="plotArea">该布局中的一个区域</param>
  6.         /// <param name="plotDevice">打印设备名</param>
  7.         /// <param name="plotCanonicalMeida">标准打印介质名</param>
  8.         /// <param name="plotStyle">打印样式</param>
  9.         /// <param name="isSinglePage">是否只打印单页</param>
  10.         /// <returns></returns>
  11.         private static PlotInfo SetPlotInfo(Layout lo, Extents2d plotArea,
  12.             string plotDevice, string plotCanonicalMeida, string plotStyle,bool isSinglePage)
  13.         {
  14.             PlotInfo pi = new PlotInfo();
  15.             pi.Layout = lo.Id;

  16.             //获取当前布局的打印信息
  17.             PlotSettings ps = new PlotSettings(lo.ModelType);//是否模型空间
  18.             ps.CopyFrom(lo);

  19.             //着色打印选项,设置按线框进行打印
  20.             ps.ShadePlot = PlotSettingsShadePlotType.Wireframe;

  21.             //获取当前打印设置校验器
  22.             PlotSettingsValidator psv = PlotSettingsValidator.Current;

  23.             #region 以下这些设置请不要改变顺序!!!
  24.             //以下2句顺序不能换!
  25.             psv.SetPlotWindowArea(ps, plotArea);//设置打印区域            
  26.             psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);//设置为窗口打印模式

  27.             //设置布满图纸打印
  28.             psv.SetUseStandardScale(ps, true);//需要?
  29.             psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);//布满图纸

  30.             //设置居中打印
  31.             psv.SetPlotCentered(ps, true);

  32.             //设置打印样式
  33.             try
  34.             {
  35.                 psv.SetCurrentStyleSheet(ps, plotStyle);//设置打印样式(笔宽等)(为什么有时会出错?PS:不能与原样式形同?!!!)
  36.             }
  37.             catch (Autodesk.AutoCAD.Runtime.Exception e)
  38.             {
  39.                 MessageBox.Show(string.Format("{0}\n当前打印样式:{1}\n设置打印样式:{2}", e.Message, ps.CurrentStyleSheet, plotStyle), "设置打印样式出错");
  40.             }

  41.             //配置打印机和打印介质
  42.             psv.SetPlotConfigurationName(ps, plotDevice, plotCanonicalMeida);
  43.             psv.RefreshLists(ps);

  44.             //设置打印单位
  45.             try
  46.             {
  47.                 psv.SetPlotPaperUnits(ps, PlotPaperUnit.Millimeters);//(为什么有时会出错?)            
  48.             }
  49.             catch (Autodesk.AutoCAD.Runtime.Exception e)
  50.             {
  51.                 MessageBox.Show(string.Format("{0}\n当前尺寸单位:{1}\n设置单位:{2}", e.Message, ps.PlotPaperUnits, PlotPaperUnit.Millimeters), "设置尺寸单位出错");
  52.             }

  53.             //设置旋转角度(打印到同一文档时必须设置为同一旋转角)
  54.             if (isSinglePage)
  55.             {
  56.                 if ((plotArea.MaxPoint.X - plotArea.MinPoint.X) > (plotArea.MaxPoint.Y - plotArea.MinPoint.Y))
  57.                 {
  58.                     if (ps.PlotPaperSize.X > ps.PlotPaperSize.Y)
  59.                     {
  60.                         psv.SetPlotRotation(ps, PlotRotation.Degrees000);
  61.                     }
  62.                     else
  63.                     {
  64.                         psv.SetPlotRotation(ps, PlotRotation.Degrees090);
  65.                     }
  66.                 }
  67.                 else
  68.                 {
  69.                     if (ps.PlotPaperSize.X > ps.PlotPaperSize.Y)
  70.                     {
  71.                         psv.SetPlotRotation(ps, PlotRotation.Degrees090);
  72.                     }
  73.                     else
  74.                     {
  75.                         psv.SetPlotRotation(ps, PlotRotation.Degrees000);
  76.                     }
  77.                 }
  78.             }
  79.             else
  80.             {
  81.                 //多页打印必须设置为统一旋转角度(否则打印会出错,出错信息:eValidePlotInfo!特别注意!!!)
  82.                 psv.SetPlotRotation(ps, PlotRotation.Degrees000);
  83.             }
  84.             #endregion

  85.             pi.OverrideSettings = ps;//将PlotSetting与PlotInfo关联

  86.             PlotInfoValidator piv = new PlotInfoValidator();
  87.             piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
  88.             piv.Validate(pi);//激活打印设置

  89.             ps.Dispose();

  90.             return pi;
  91.         }
 楼主| 发表于 2016-3-1 10:32 | 显示全部楼层
大神们,你们在哪,求解答,谢谢啦!
发表于 2016-3-1 11:38 来自手机 | 显示全部楼层
4页生成一个文件的话 你可以考虑换个pdf打印机
我记得有个pdffac..(工厂?)
 楼主| 发表于 2016-3-1 16:23 | 显示全部楼层
雪山飞狐_lzh 发表于 2016-3-1 11:38
4页生成一个文件的话 你可以考虑换个pdf打印机
我记得有个pdffac..(工厂?)

PlotFactory么?
4页生不生成一个文件不是最重要的,我现在的问题是效率的问题
我用上面那个代码总共要花数分钟(取决于数量和图的负责度,比较简单的基本上都要上分钟了)
我的需求是把一个Extend2d范围内(即图框范围)内的东西打印到pdf图纸上
求大神指点,谢谢
发表于 2016-3-7 08:21 | 显示全部楼层
本帖最后由 ps122hb 于 2016-3-7 08:23 编辑
_wtf 发表于 2016-3-1 16:23
PlotFactory么?
4页生不生成一个文件不是最重要的,我现在的问题是效率的问题
我用上面那个代码总共要 ...


打印机 pdfFactory

你是在模型空间还是图纸空间打印?我的理解你好像在模型空间,但程序里应该是图纸空间,你再看看
 楼主| 发表于 2016-3-8 17:29 | 显示全部楼层
ps122hb 发表于 2016-3-7 08:21
打印机 pdfFactory

你是在模型空间还是图纸空间打印?我的理解你好像在模型空间,但程序里应该是图纸 ...

我是在图纸空间上打印的吧,取的是图纸上的坐标,然后按照区域来打印
pdffactory是必须要单独安装的吧
这样给客户相对来说不是特别方便
发表于 2017-9-3 23:10 | 显示全部楼层
我今天试着写打印也和你一样的情况,非常慢,如果是直接用CAD的打印则很快
发表于 2017-10-20 14:41 | 显示全部楼层
  1. /// <summary>
  2.         /// 打印
  3.         /// </summary>
  4.         /// <param name="plotAreaDict"></param>
  5.         /// <param name="plotDevice"></param>
  6.         /// <param name="plotCanonicalMeida"></param>
  7.         /// <param name="plotStyle"></param>
  8.         /// <param name="saveFileName"></param>
  9.         /// <returns></returns>
  10.         public static bool Plot(
  11.             Dictionary<ObjectId, List<Extents2d>> plotAreaDict,
  12.             string plotDevice,
  13.             string plotCanonicalMeida,
  14.             string plotStyle,
  15.             string saveFileName
  16.             )
  17.         {
  18.             bool ret = true;

  19.             if (plotAreaDict.Count == 0) return true;

  20.             #region 准备打印区域列表 PlotList
  21.             Dictionary<Extents2d, ObjectId> PlotList = new Dictionary<Extents2d, ObjectId>();
  22.             foreach (KeyValuePair<ObjectId, List<Extents2d>> kv in plotAreaDict)
  23.             {
  24.                 foreach (Extents2d plotArea in kv.Value)
  25.                 {
  26.                     PlotList.Add(plotArea, kv.Key);
  27.                 }
  28.             }
  29.             #endregion

  30.             if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
  31.             {
  32.                 #region 设置为前台打印
  33.                 object BackGroundPlotVar = mFun.m_GetSystemVar("BACKGROUNDPLOT");
  34.                 mFun.m_SetSystemVar("BACKGROUNDPLOT", 0);//一定要设置成0(前台打印),否则保存PDF文件中一个布局只会有一张图!!!!
  35.                 #endregion

  36.                 using (PlotEngine pe = PlotFactory.CreatePublishEngine())
  37.                 {
  38.                     PreviewEndPlotStatus stat = MultiPlotOrPreview(
  39.                         pe, false, PlotList, -1, plotAreaDict.Count,
  40.                         plotDevice, plotCanonicalMeida, plotStyle, saveFileName
  41.                       );

  42.                     ret = stat == PreviewEndPlotStatus.Cancel ? false : true;
  43.                 }

  44.                 mFun.m_SetSystemVar("BACKGROUNDPLOT", BackGroundPlotVar);
  45.             }
  46.             else
  47.             {
  48.                 mCommands.m_ed.WriteMessage("\n其他打印正在进行中!");
  49.             }

  50.             return ret;
  51.         }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 11:43 , Processed in 0.290647 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表