62,056
社区成员
发帖
与我相关
我的任务
分享
public string FoldPath = @"C:\Users\Administrator\Desktop\新建文件夹 (2)\";
public string targetPath = @"E:\znl\WebSite1\PDF\";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
if (this.TreeView1.SelectedNode.ChildNodes.Count < 1)
{
string filePath = FoldPath + TreeView1.SelectedNode.Value.Trim();
int fangxiang = 90;
if (System.IO.File.Exists(filePath))
{
try
{
string filename = Path.GetFileNameWithoutExtension(filePath);
string foloder = Path.GetDirectoryName(filePath);
string filesource = foloder + "\\" + filename + "-Model.pdf";
string filetarget = targetPath + filename + ".pdf";
AcadDocumentClass AcdDoc = new AcadDocumentClass();
AcadDocument docu = AcdDoc.Application.Documents.Open(filePath, true, null); //以只读方式打开该文件
docu.ActiveLayout.ConfigName = "DWG To PDF.pc3"; //定义打印机
docu.ActiveLayout.UseStandardScale = true;
docu.ActiveLayout.StandardScale = AutoCAD.AcPlotScale.acScaleToFit;
docu.ActiveLayout.PlotType = AutoCAD.AcPlotType.acExtents;
docu.ActiveLayout.CenterPlot = true;
if (fangxiang == 0)
{
docu.ActiveLayout.PlotRotation = AutoCAD.AcPlotRotation.ac0degrees;
}
else
{
docu.ActiveLayout.PlotRotation = AutoCAD.AcPlotRotation.ac90degrees;
}
//docu.ActiveLayout.CanonicalMediaName = "A0"; //定义打印纸张
docu.ActiveLayout.PlotType = AutoCAD.AcPlotType.acExtents; //定义打印范围
docu.Plot.PlotToDevice(null);
docu.Close(null, null);
AcdDoc.Close(null, null);
if (System.IO.Directory.Exists(targetPath))
{
while (true)
{
if (System.IO.File.Exists(filesource) && !(IsFileInUse(filesource)))
{
System.Threading.Thread.Sleep(2000);
System.IO.File.Copy(filesource, filetarget, true);
while (true)
{
if (System.IO.File.Exists(filetarget))
{
System.IO.File.Delete(filesource);
ShowPdf1.FilePath = "PDF/"+filename + ".pdf";
break;
}
System.Threading.Thread.Sleep(1000);
}
break;
}
System.Threading.Thread.Sleep(1000);
}
}
else
{
}
}
catch(Exception ex)
{
Console.WriteLine("Convert Failed!");
}
}
else
{
}
}
else
{ }
}