Teigha.NET V19 DWG/DXF转PDF

           

开发环境:

Visual Studio 2019

.NetFramework 4.6.1

Teigha.NET V19

using Teigha.DatabaseServices;
using Teigha.Geometry;
using Teigha.Export_Import;
using Teigha.GraphicsSystem;
using Teigha.Runtime;

//用户信息和授权信息只是示样,并不是真实的

Services.odActivate("IE5ldyBEaW1lbn22224gU3lzdGVtcyBDby4sIEx0YC4 = ",
                "vOYmrv6wnjrEzu0U62AjeMqchIXlglu6yZxFZB + 3X7lqx7Bqib7QCe / mDP0ADWp4b0yuAaq / EPwFZ40VC41D1iCXVjdZv / 5EIcBJGtiUDly3wJlBIwX2OgiwHhl + kqyfVybCnalk2DQiuZoMqMmEl4ly7k6mfmZPBo1Q8ULBy6WjuLzn3z2a4prGCX2WYBlqfTrlszp8NLvcwqI / lhmqLC0MZU + ObFLtlZnPSNRl95TiRwt9whgsziS6PMX3rNlW55555lM3elMlMYL2BA + Z1uGTxetaCnG + dTehusGy / ul3rFVjXzR + 9AEbTby5CQgFe5NLmvdJf9uWO9suzNy0XKa2EOqyHhUshljlrWz0HMXYYW6zosyb3WiQPMLmy1 + L6ELmtZyeNdsUExBHXsUAHb + k2arugOdDucFbib6YXwhsQyqPtMTg6fWdPW0CPVvmXpsPWxMm + b5n3MRgZ6tPAqhNLdNLYHWxRzWakVoVP2xt0FcHk3 / W + oiRtgIuy + TscOhT6gLT2rhLJ1DGus1SW28pvFuOwALkLGkRZkLjavfdp9Fdasmrz2daigi8ciK0XuqtYXovCuaaCx0AkhgnvU5 + NMXyijBmUqsVOl8u4UsuwjdGK3o4dDHGpK4XKcZG + gjnc6g7zvgw9uPGlFjDX367zTR / bIjHJZ5Ec3CrOw = "); // 激活码


        Teigha.Runtime.Services tdSrv = new Teigha.Runtime.Services();

            //tdSrv.AccessFileRead("input.dwg");
            Database db = new Database(false, false);
            //public void ReadDwgFile(string fileName, FileShare fileSharing, bool allowCPConversion, string password);
            //db.ReadDwgFile("input.dwg", System.IO.FileShare.Read, true, null);
            //db.ReadDwgFile("input.dwg", FileOpenMode.OpenForReadAndWriteNoShare, false, null, false);
            db.DxfIn("2.dxf", "2.dxf.log");

            //DwgDatabase = new Database(false, false);
            //db.ReadDwgFile("input.dwg", FileOpenMode.OpenForReadAndReadShare, false, "");

            Circle circle = new Circle();
            circle.Center = new Point3d(100, 100, 0);
            circle.Color = Teigha.Colors.Color.FromRgb(255, 0, 0);
            circle.Radius = 400;
            BlockTableRecord btr = (BlockTableRecord)db.CurrentSpaceId.Open(OpenMode.ForWrite);
            btr.AppendEntity(circle);
            db.SaveAs("d:\\test1.dwg", DwgVersion.Current);

            //Device dev = ImpDevice.Create();
            mPDFExportParams par = new mPDFExportParams();
            //par.BackgroundColor = Color.LightGray;
            par.BackgroundColor = Color.FromArgb(0,Color.White) ;

            StreamBuf buf;

            //public FileStreamBuf(string pcFilename, bool openForRead, FileShareMode nShareMode, FileCreationDisposition nCreationDisposition);
            FileStreamBuf fbuf = new FileStreamBuf("test.pdf",false,FileShareMode.DenyNo);
            buf = fbuf;
            //tdSrv.AccessFileRead("2018.dwg");
            par.Database = db;
            par.Author = "David Wu";
            par.Title = "BluePrint";
            par.Creator = "Jack";
            par.Versions = PDFExportVersions.PDFv1_4;
            //db.Filename;
            par.OutputStream = buf;
            //par.BackgroundColor = System.Drawing.Color.White;
            //db.Save();
            Export_Import.ExportPDF(par);

            par.Dispose();
            buf.Dispose();
            fbuf.Dispose();

使用dispose及时释放资源是必须的。

你可能感兴趣的:(图形学,.net,图形学)