批量打印文件和打印到文件

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

public bool DwgTopdf(string filePath, string strPrintName, string strSize, int number, string strDir, int DwgCount, string strStyle, bool bPrintToFile, string strModeleName)
{
try
{
yout.PlotType = mon.AcPlotType.acExtents; //定义打印范围为自动延伸全图纸
yout.ConfigName = strPrintName; //选定打印机
yout.CanonicalMediaName = strSize; //设置图幅
doc.Plot.NumberOfCopies = number; //打印份数
AcadLayout layout = doc.ActiveLayout;
String MediaName = layout.CanonicalMediaName;
if (MediaName.Equals(""))
{
MessageBox.Show("There is no media set for the active layout.");
return false;
}
else
{
AcadPlotConfiguration oplot = doc.PlotConfigurations.Add(strPrintName, layout.ModelType);
oplot.PaperUnits = AcPlotPaperUnits.acMillimeters;
oplot.StyleSheet = strStyle;
oplot.PlotWithPlotStyles = true;
oplot.ConfigName = strPrintName;
eStandardScale = true;
oplot.StandardScale = AcPlotScale.acScaleToFit;
oplot.PlotType = AcPlotType.acExtents;
oplot.CenterPlot = true;
Object oMediaNames = layout.GetCanonicalMediaNames();
ArrayList mediaNames = new ArrayList((string[])oMediaNames);

foreach (String sName in mediaNames)
{
if (sName.Contains(MediaName))
{
oplot.CanonicalMediaName = sName;
layout.CopyFrom(oplot);
if (strDir == "横向")
{
layout.PlotRotation = AcPlotRotation.ac0degrees;
}
else if (strDir == "纵向")
{
layout.PlotRotation = AcPlotRotation.ac90degrees;
}
//else if (strDir == "反向")
//{
// layout.PlotRotation = AcPlotRotation.ac180degrees;
//}
layout.RefreshPlotDeviceInfo();

doc.SetVariable("BACKGROUNDPLOT", 0);
doc.Plot.QuietErrorMode = true;
if (bPrintToFile == true)
{
string strFileName = Path.GetFileNameWithoutExtension(filePath);

int tempCount = 0;
for (int i = 0; i < strFileName.Length; i++)
{
if (strFileName[i] == '.')
{
tempCount++;
}
}
if (tempCount > 0)
strFileName = strFileName.Replace('.', '-');
doc.Plot.PlotToFile(strFileName, strPrintName);
}
else
doc.Plot.PlotToDevice(strPrintName);
oplot.Delete();
oplot = null;
CloseDwg();
break;
}
}
}
}
catch (Exception ex)
{
WriteLog.WriteLog.WriteLogInfor(strModeleName, "打印结束!错误原因:" + ex.Message);
CloseDwg();
return false;
}
return true;
}

相关文档
最新文档