public static void Run()
        {
            try
            {
                //ExStart:ExportDGNToPdf
                // The path to the documents directory.
                string MyDir          = RunExamples.GetDataDir_ExportingDGN();
                string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
                // Load an existing DGN file as CadImage.
                using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
                {
                    // Create an object of CadRasterizationOptions class and define/set different properties
                    Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
                    rasterizationOptions.PageWidth               = 600;
                    rasterizationOptions.PageHeight              = 300;
                    rasterizationOptions.CenterDrawing           = true;
                    rasterizationOptions.ScaleMethod             = Aspose.CAD.FileFormats.Cad.ScaleType.None;
                    rasterizationOptions.AutomaticLayoutsScaling = true;

                    // Create an object of PdfOptions class as we are converting the image to PDF format and assign CadRasterizationOptions object to it.
                    Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
                    pdfOptions.VectorRasterizationOptions = rasterizationOptions;

                    // Call the save method of the CadImage class object.
                    cadImage.Save(MyDir + "ExportDGNToPdf_out.pdf", pdfOptions);
                }
                //ExEnd:ExportDGNToPdf
                Console.WriteLine("\nThe DGN file exported successfully to PDF.\nFile saved at " + MyDir);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Please use valid input file." + ex.Message);
            }
        }
Beispiel #2
0
        public static void Run()
        {
            //ExStart:AccessingUnderlayFlagsofDWG

            // Input file name and path
            string fileName = "BlockRefDgn.dwg";

            // Load an existing DWG file and convert it into CadImage
            using (Aspose.CAD.FileFormats.Cad.CadImage image = (Aspose.CAD.FileFormats.Cad.CadImage)Image.Load(fileName))
            {
                // Go through each entity inside the DWG file
                foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadBaseEntity entity in image.Entities)
                {
                    // Check if entity is of CadDgnUnderlay type
                    if (entity is Aspose.CAD.FileFormats.Cad.CadObjects.CadDgnUnderlay)
                    {
                        // Access different underlay flags
                        Aspose.CAD.FileFormats.Cad.CadObjects.CadUnderlay underlay = entity as Aspose.CAD.FileFormats.Cad.CadObjects.CadUnderlay;
                        Console.WriteLine(underlay.UnderlayPath);
                        Console.WriteLine(underlay.UnderlayName);
                        Console.WriteLine(underlay.InsertionPoint.X);
                        Console.WriteLine(underlay.InsertionPoint.Y);
                        Console.WriteLine(underlay.RotationAngle);
                        Console.WriteLine(underlay.ScaleX);
                        Console.WriteLine(underlay.ScaleY);
                        Console.WriteLine(underlay.ScaleZ);
                        Console.WriteLine((underlay.Flags & Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.UnderlayIsOn) == Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.UnderlayIsOn);
                        Console.WriteLine((underlay.Flags & Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.ClippingIsOn) == Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.ClippingIsOn);
                        Console.WriteLine((underlay.Flags & Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.Monochrome) != Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.Monochrome);
                        break;
                    }
                }
            }
            //ExEnd:AccessingUnderlayFlagsofDWG
        }
        public static void Run()
        {
            try
            {
                //ExStart:ExportDGNAsPartofDWG

                // Input and Output file paths
                string fileName = "BlockRefDgn.dwg";
                string outPath  = fileName + ".pdf";

                // Create an instance of PdfOptions class as we are exporting the DWG file to PDF format
                Aspose.CAD.ImageOptions.PdfOptions exportOptions = new Aspose.CAD.ImageOptions.PdfOptions();

                // Load any existing DWG file as image and convert it to CadImage type
                using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Image.Load(fileName))
                {
                    // Go through each entity inside the DWG file
                    foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadBaseEntity baseEntity in cadImage.Entities)
                    {
                        // Check if entity is an image definition
                        if (baseEntity.TypeName == Aspose.CAD.FileFormats.Cad.CadConsts.CadEntityTypeName.DGNUNDERLAY)
                        {
                            Aspose.CAD.FileFormats.Cad.CadObjects.CadDgnUnderlay dgnFile = (Aspose.CAD.FileFormats.Cad.CadObjects.CadDgnUnderlay)baseEntity;

                            // Get external reference to object
                            System.Console.WriteLine(dgnFile.UnderlayPath);
                        }
                    }

                    // Define settings for CadRasterizationOptions object
                    exportOptions.VectorRasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
                    {
                        PageWidth  = 1600,
                        PageHeight = 1600,
                        //CenterDrawing = true,
                        Layouts = new string[] { "Model" },
                        AutomaticLayoutsScaling = false,
                        NoScaling       = true,
                        BackgroundColor = Color.Black,
                        DrawType        = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor
                    };

                    //Export the DWG to PDF by calling Save method
                    cadImage.Save(outPath, exportOptions);
                }
                //ExEnd:ExportDGNAsPartofDWG
            }
            catch (Exception ex)
            {
                Console.WriteLine("Please use valid input file." + ex.Message);
            }
        }
        public static void Run()
        {
            //ExStart:GetBlockAttributeValue
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_DWGDrawings();
            string sourceFilePath = MyDir + "sample.dwg";

            // Load an existing DWG file as CadImage.
            using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
            {
                System.Console.WriteLine(cadImage.BlockEntities["*MODEL_SPACE"].XRefPathName);
            }
            //ExEnd:GetBlockAttributeValue
        }
        public static void SubstitutingFontByName()
        {
            //ExStart:SubstitutingFontByName
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_ConvertingCAD();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";

            // Load a CAD drawing in an instance of CadImage
            using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
            {
                // Specify the font for one particular style
                cadImage.Styles["Roman"].PrimaryFontName = "Arial";
            }
            //ExEnd:SubstitutingFontByName
        }
        public static void Run()
        {
            //ExStart:ListLayouts
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_ConvertingCAD();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";

            using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
            {
                Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)image;

                Aspose.CAD.FileFormats.Cad.CadLayoutDictionary layouts = cadImage.Layouts;
                foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadLayout layout in layouts.Values)
                {
                    Console.WriteLine("Layout " + layout.LayoutName);
                }
            }
            //ExEnd:ListLayouts
        }
        public static void Run()
        {
            //ExStart:SubstitutingFonts
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_ConvertingCAD();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";

            // Load a CAD drawing  in an instance of CadImage
            using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
            {
                // Iterate over the items of CadStyleDictionary
                foreach (var style in cadImage.Styles.ValuesTyped)
                {
                    // Set the font name
                    style.PrimaryFontName = "Arial";
                }
            }
            //ExEnd:SubstitutingFonts
            Console.WriteLine("\nFont changed successfully.");
        }
        public static void SubstitutingFontByName()
        {
            //ExStart:SubstitutingFontByName
            // The path to the documents directory.
            string MyDir          = RunExamples.GetDataDir_ConvertingCAD();
            string sourceFilePath = MyDir + "conic_pyramid.dxf";

            // Load a CAD drawing in an instance of CadImage
            using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
            {
                // Iterate over the items of CadStyleDictionary
                foreach (CadStyleTableObject style in cadImage.Styles)
                {
                    if (style.StyleName == "Roman")
                    {
                        // Specify the font for one particular style
                        style.PrimaryFontName = "Arial";
                    }
                }
            }
        }
      public static void Run()
      {
          //ExStart:SearchText
          // The path to the documents directory.
          string MyDir          = RunExamples.GetDataDir_DWGDrawings();
          string sourceFilePath = MyDir + "sample.dwg";

          // Load an existing DWG file as CadImage.
          using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
          {
              // Search for text in the file
              foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadBaseEntity entity in cadImage.Entities)
              {
                  // Please, note: we iterate through CadText entities here, but some other entities may contain text also, e.g. CadMText and others
                  if (entity.GetType() == typeof(Aspose.CAD.FileFormats.Cad.CadObjects.CadText))
                  {
                      Aspose.CAD.FileFormats.Cad.CadObjects.CadText text = (Aspose.CAD.FileFormats.Cad.CadObjects.CadText)entity;
                      System.Console.WriteLine(text.DefaultValue);
                  }
              }

              // Search for text on specific layout get all layout names and link each layout with corresponding block with entities
              Aspose.CAD.FileFormats.Cad.CadLayoutDictionary layouts = cadImage.Layouts;
              string[] layoutNames = new string[layouts.Count];
              int      i           = 0;
              foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadLayout layout in layouts.Values)
              {
                  layoutNames[i++] = layout.LayoutName;
                  System.Console.WriteLine("Layout " + layout.LayoutName + " is found");

                  // Find block, applicable for DWG only
                  Aspose.CAD.FileFormats.Cad.CadTables.CadBlockTableObject blockTableObjectReference = null;
                  foreach (Aspose.CAD.FileFormats.Cad.CadTables.CadBlockTableObject tableObject in cadImage.BlocksTables)
                  {
                      if (string.Equals(tableObject.HardPointerToLayout, layout.ObjectHandle))
                      {
                          blockTableObjectReference = tableObject;
                          break;
                      }
                  }

                  // Collection cadBlockEntity.Entities contains information about all entities on specific layout if this collection has no elements it means layout is a copy of Model layout and contains the same entities
                  Aspose.CAD.FileFormats.Cad.CadObjects.CadBlockEntity cadBlockEntity = cadImage.BlockEntities[blockTableObjectReference.BlockName];
              }

              // Export to pdf
              Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
              rasterizationOptions.PageWidth  = 1600;
              rasterizationOptions.PageHeight = 1600;
              rasterizationOptions.AutomaticLayoutsScaling = true;
              rasterizationOptions.CenterDrawing           = true;

              // Please, note: if cadBlockEntity collection mentioned above (for dwg) for selected layout or entitiesOnLayouts collection by layout's BlockTableRecordHandle (for dxf) is empty - export result file will be empty and you should draw Model layout instead
              rasterizationOptions.Layouts = new[] { "Layout1" };

              Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();

              pdfOptions.VectorRasterizationOptions = rasterizationOptions;
              cadImage.Save(MyDir + "SearchText_out_.pdf", pdfOptions);
          }
          //ExEnd:SearchText
      }
        private List <string> GetDocumentPages(string file, string folderName, int currentPage)
        {
            List <string> lstOutput   = new List <string>();
            string        outfileName = "page_{0}";
            string        outPath     = Config.Configuration.OutputDirectory + folderName + "/" + outfileName;

            currentPage = currentPage - 1;
            Directory.CreateDirectory(Config.Configuration.OutputDirectory + folderName);
            string imagePath = string.Format(outPath, currentPage) + ".jpeg";

            if (System.IO.File.Exists(imagePath) && currentPage > 0)
            {
                lstOutput.Add(imagePath);
                return(lstOutput);
            }

            int i = currentPage;

            var filename = System.IO.File.Exists(Config.Configuration.WorkingDirectory + folderName + "/" + file)
                                ? Config.Configuration.WorkingDirectory + folderName + "/" + file
                                : Config.Configuration.OutputDirectory + folderName + "/" + file;

            using (FilePathLock.Use(filename))
            {
                try
                {
                    Aspose.CAD.Live.Demos.UI.Models.License.SetAsposeCADLicense();


                    // Load an existing CAD document
                    Aspose.CAD.FileFormats.Cad.CadImage image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(filename);

                    // Create an instance of CadRasterizationOptions
                    Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();

                    // Set image width & height
                    rasterizationOptions.PageWidth  = 1024;
                    rasterizationOptions.PageHeight = 1024;
                    // Set the drawing to render at the center of image
                    //rasterizationOptions.CenterDrawing = true;
                    //rasterizationOptions.TypeOfEntities = Aspose.CAD.ImageOptions.TypeOfEntities.Entities3D;

                    rasterizationOptions.AutomaticLayoutsScaling = true;
                    rasterizationOptions.NoScaling       = false;
                    rasterizationOptions.ContentAsBitmap = true;

                    // Set Graphics options
                    rasterizationOptions.GraphicsOptions.SmoothingMode     = Aspose.CAD.SmoothingMode.HighQuality;
                    rasterizationOptions.GraphicsOptions.TextRenderingHint = Aspose.CAD.TextRenderingHint.AntiAliasGridFit;
                    rasterizationOptions.GraphicsOptions.InterpolationMode = Aspose.CAD.InterpolationMode.HighQualityBicubic;


                    // Get the layers in an instance of CadLayersDictionary
                    var layersList = image.Layers;
                    lstOutput.Add(layersList.Count.ToString());
                    i = 0;
                    // Iterate over the layers
                    foreach (var layerName in layersList.GetLayersNames())
                    {
                        if (i == currentPage)
                        {
                            // Add the layer name to the CadRasterizationOptions's layer list
                            rasterizationOptions.Layers[i] = layerName;

                            // Create an instance of PngOptions for the resultant image
                            Aspose.CAD.ImageOptions.JpegOptions options = new Aspose.CAD.ImageOptions.JpegOptions();

                            // Set rasterization options
                            options.VectorRasterizationOptions = rasterizationOptions;
                            image.Save(imagePath, options);
                            lstOutput.Add(imagePath);
                            image.Dispose();
                            break;
                        }
                        i++;
                    }
                    if (!image.Disposed)
                    {
                        image.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return(lstOutput);
            }
        }