C # Call the AutoCAD component to convert DWG to PDF

Source: Internet
Author: User

The following is a demo (I am currently in HIGER, so the copyright is it, huh, huh). The principle is to print DWG to a printer. To enable automatic printer, you must support automatic saving, the following parameter creator is supported.

If you want to debug it, just create a project and add a FORM ~~~~~~~~~~~

 

Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using Autodesk. AutoCAD. Interop;
Using System. IO;
 
Namespace WindowsFormsApplication1
{
Public partial class Form1: Form
{
AcadApplicationClass app; // resident application
 
Public Form1 ()
{
InitializeComponent ();
 
Try
{
App = new AcadApplicationClass ();
}
Catch
{
MessageBox. Show ("Start AutoCAD object failed! Installed? ");
Button1.Enabled = false;
Return;
}
}
 
Private void button#click (object sender, EventArgs e)
{
If (! File. Exists (textBox1.Text ))
{
MessageBox. Show ("File is not exists ");
Return;
}
 
AcadDocument doc;
Try
{
Doc = app. Documents. Open (textBox1.Text, null, null); // Open the file
}
Catch (Exception error)
{
MessageBox. Show ("Can't open the file." + error. Message );
Return;
}

Doc. ModelSpace. Layout. PlotType = Autodesk. AutoCAD. Interop. Common. AcPlotType. acExtents; // define the print range to automatically extend the whole Graph
Doc. ModelSpace. Layout. ConfigName = textBox3.Text; // select the printer
Doc. ModelSpace. Layout. CanonicalMediaName = comboBox1.Text; // you can specify the image size.
 
Doc. Plot. NumberOfCopies = 1; // number of copies printed
Try
{
Doc. Plot. PlotToDevice (null );
}
Catch (Exception error)
{
MessageBox. Show ("Send to printer failed." + error. Message );
Return;
}
Finally
{
Doc. Close (false, null );
}
}
 
Private void form=formclosing (object sender, FormClosingEventArgs e)
{
If (app! = Null)
Try
{
App. Quit ();
}
Catch {}
} Www.2cto.com
 
Private void button2_Click_1 (object sender, EventArgs e)
{
OpenFileDialog d = new OpenFileDialog ();
D. Filter = "AutoCAD Drawing (*. dwg) | *. dwg ";
If (d. ShowDialog () = DialogResult. OK)
{
TextBox1.Text = d. FileName;
}
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.