DXF Zeichnungen
Exportieren von DXF Zeichnungen nach PDF
Aspose.CAD bietet die Möglichkeit, AutoCAD DXF Zeichnungselemente zu laden und sie als gesamte Zeichnung im PDF-Format zu rendern. Der Ansatz für die DXF-zu-PDF-Konvertierung funktioniert wie folgt:
- Laden Sie die DXF-Zeichnungsdatei mit der Image.Load Fabrikmethode.
- Erstellen Sie ein Objekt der CadRasterizationOptions Klasse und setzen Sie die Eigenschaften PageHeight & PageWidth.
- Erstellen Sie ein Objekt der PdfOptions Klasse und setzen Sie die Eigenschaft VectorRasterizationOptions.
- Rufen Sie Image.Save auf und übergeben Sie ein Objekt der PdfOptions als zweiten Parameter.
Das folgende Code-Beispiel zeigt, wie man eine Datei mit den Standardeinstellungen konvertiert.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
rasterizationOptions.BackgroundColor = Aspose.CAD.Color.White; | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
// Create an instance of PdfOptions | |
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
MyDir = MyDir + "conic_pyramid_out.pdf"; | |
//Export the DXF to PDF | |
image.Save(MyDir, pdfOptions); | |
} |
Unterstützte Formate
Im Moment unterstützen wir voll zur AutoCAD DXF 2010-Dateiformate. Die vorherigen DXF-Versionen sind nicht garantiert 100% gültig. Wir planen, in zukünftigen Aspose.CAD-Versionen weitere Formate und Funktionen hinzuzufügen.
Unterstützte Elemente
Momentan unterstützen wir alle weit verbreiteten 2D-Elemente und ihre grundlegenden Standardparameter wie folgt:
- Ausgerichtete Dimension
- Winkelmaß
- Bogen
- Attribut
- Blockreferenz
- Kreis
- Durchmessermaß
- Ellipse
- Schraffur
- Linie
- Mehrzeiliger Text
- Ordinate
- Punkt
- Polyline
- Radialmaß
- Strahl
- Rotierte Dimension
- Tabelle
- Text
- Xline
Speicherverwaltung
Die Eigenschaft ExactReallocateOnly der Cache Klasse kann verwendet werden, um die Speicherneuzuweisung zu steuern. Eine Neuzuweisung erfolgt höchstwahrscheinlich für vorzugewiesene Caches. Dies kann geschehen, wenn das System erkennt, dass der zugewiesene Platz nicht ausreicht.
- Wenn ExactReallocateOnly auf den Standardwert, False, gesetzt ist, wird der Platz auf demselben Medium neu zugewiesen.
- Wenn es auf True gesetzt ist, darf die Neuzuweisung den maximal angegebenen Platz nicht überschreiten. In diesem Fall wird der vorhandene zugewiesene In-Memory-Cache (der eine Neuzuweisung erfordert) freigegeben und zusätzlicher Platz auf der Festplatte zugewiesen.
Exportieren einer bestimmten Ebene von DXF Zeichnungen nach PDF
Dieser Ansatz funktioniert wie folgt:
- Öffnen Sie eine DXF-Zeichnungsdatei mit der Image.Load Fabrikmethode.
- Erstellen Sie eine Instanz von CadRasterizationOptions und geben Sie die Eigenschaften PageWidth & PageHeight an.
- Fügen Sie Ebenen zum Objekt von CadRasterizationOptions hinzu.
- Erstellen Sie eine Instanz von PdfOptions und setzen Sie ihre VectorRasterizationOptions Eigenschaft.
- Rufen Sie die Image.Save Methode auf und übergeben Sie das Objekt von PdfOptions als zweiten Parameter.
Das folgende Code-Beispiel zeigt, wie man eine bestimmte Ebene von DXF nach PDF konvertiert.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
// Add desired layers | |
rasterizationOptions.Layers = new string[] { "LayerA" }; | |
// Create an instance of PdfOptions | |
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
MyDir = MyDir + "conic_pyramid_layer_out.pdf"; | |
//Export the DXF to PDF | |
image.Save(MyDir, pdfOptions); | |
} |
PDF-Dateien als Teil von DXF Zeichnungen rendern
Dieser Ansatz funktioniert wie folgt:
- Laden Sie die DXF-Zeichnungsdatei mit der Image.Load Fabrikmethode.
- Erstellen Sie ein Objekt der CadRasterizationOptions Klasse und laden Sie PDF-Dateien.
- Setzen Sie die Eigenschaften PageHeight & PageWidth.
- Rufen Sie Image.Save auf und speichern Sie die Datei.
Das folgende Code-Beispiel zeigt, wie man PDF-Dateien als Teil von DXF Zeichnungen rendert.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
// Specify desired layout name | |
rasterizationOptions.Layouts = new string[] { "Model" }; | |
// Create an instance of PdfOptions | |
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
MyDir = MyDir + "conic_pyramid_layout_out.pdf"; | |
//Export the DXF to PDF | |
image.Save(MyDir, pdfOptions); | |
} |
Exportieren des eingebetteten DGN-Unterlageformats für DXF
Aspose.CAD bietet die Möglichkeit, AutoCAD DXF-Dateien zu laden und eingebettete DGN-Unterlagen für DXF-Formate zu exportieren.
Das folgende Code-Beispiel zeigt, wie die spezifizierten Anforderungen erreicht werden.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath)) | |
{ | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.Layouts = new[] { "Model" }; | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
cadImage.Save(MyDir + "conic_pyramid.pdf", pdfOptions); | |
} |
Unterstützung für das Speichern von DXF-Dateien
Aspose.CAD bietet die Funktion, AutoCAD DXF-Dateien zu laden, Änderungen darin vorzunehmen und sie erneut als DXF-Datei zu speichern.
Das folgende Code-Beispiel zeigt, wie die spezifizierten Anforderungen erreicht werden.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath)) | |
{ | |
// any entities updates | |
cadImage.Save(MyDir+"conic.dxf"); | |
} | |
DXF in WMF exportieren
Dieser Ansatz funktioniert wie folgt:
- Laden Sie die DXF-Zeichnungsdatei mit der Image.Load Fabrikmethode.
- Erstellen Sie ein Objekt der CadRasterizationOptions Klasse und laden Sie PDF-Dateien.
- Setzen Sie die Eigenschaften PageHeight & PageWidth.
- Rufen Sie Image.Save auf und speichern Sie die Datei.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (var image = Image.Load("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn")) | |
{ | |
var vectorOptions = new CadRasterizationOptions(); | |
vectorOptions.AutomaticLayoutsScaling = true; | |
vectorOptions.BackgroundColor = Color.Black; | |
vectorOptions.PageWidth = 500; | |
vectorOptions.PageHeight = 500; | |
WmfOptions wmfOptions = new WmfOptions() | |
{ | |
VectorRasterizationOptions = vectorOptions | |
}; | |
image.Save("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn.wmf", wmfOptions); | |
} |
Exportieren einer bestimmten DXF-Anordnung nach PDF
Dieser Ansatz funktioniert wie folgt:
- Öffnen Sie eine DXF-Zeichnungsdatei mit der Image.Load Fabrikmethode.
- Erstellen Sie eine Instanz von CadRasterizationOptions und geben Sie die Eigenschaften PageWidth & PageHeight an.
- Geben Sie die gewünschten Layoutnamen mit der CadRasterizationOptions.Layouts Eigenschaft an.
- Erstellen Sie eine Instanz von PdfOptions und setzen Sie ihre VectorRasterizationOptions Eigenschaft.
- Exportieren Sie die Zeichnung nach PDF, indem Sie die Image.Save Methode aufrufen und das Objekt von PdfOptions als zweiten Parameter übergeben.
Das folgende Code-Beispiel zeigt, wie man eine bestimmte DXF-Anordnung nach PDF konvertiert.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
// Specify desired layout name | |
rasterizationOptions.Layouts = new string[] { "Model" }; | |
// Create an instance of PdfOptions | |
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
MyDir = MyDir + "conic_pyramid_layout_out.pdf"; | |
//Export the DXF to PDF | |
image.Save(MyDir, pdfOptions); | |
} |
Unterstützung von Block-Clipping
Aspose.CAD bietet die Funktion des Block-Clippings. Der Block-Clipping-Ansatz funktioniert wie folgt:
- Laden Sie die DXF-Zeichnungsdatei mit der Image.Load Fabrikmethode.
- Erstellen Sie ein Objekt der CadRasterizationOptions Klasse und laden Sie PDF-Dateien.
- Setzen Sie die gewünschten Eigenschaften von CadRasterizationOptions.
- Rufen Sie Image.Save auf und übergeben Sie ein Objekt von PdfOptions als zweiten Parameter und speichern Sie die Datei.
Das folgende Code-Beispiel zeigt, wie Block-Clipping funktioniert.
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string inputFile = MyDir + "SLS-CW-CD-CE001-R01_blockClip.dxf"; | |
string outputFile = MyDir + "SLS-CW-CD-CE001-R01_blockClip.pdf"; | |
using (CadImage cadImage = (CadImage)Image.Load(inputFile)) | |
{ | |
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions | |
{ | |
BackgroundColor = Aspose.CAD.Color.White, | |
DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor, | |
PageWidth = 1200, | |
PageHeight = 1600, | |
Margins = new Margins | |
{ | |
Top = 5, | |
Right = 30, | |
Bottom = 5, | |
Left = 30 | |
}, | |
Layouts = new string[] { "Model" } | |
}; | |
PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions | |
{ | |
VectorRasterizationOptions = rasterizationOptions | |
}; | |
cadImage.Save(outputFile, pdfOptions); |
Bilder in DXF exportieren
Mit Aspose.CAD können Sie Bilder im DXF-Format exportieren. Mit diesem Ansatz können Sie die folgenden Aktionen ausführen:
- Neue Schriftart festlegen
- Elemente ausblenden
- Text aktualisieren
Das folgende Code-Snippet zeigt Ihnen, wie Sie die oben genannten Aktionen ausführen.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
foreach (var file in new DirectoryInfo(MyDir).EnumerateFiles("*.dxf")) | |
{ | |
// **************************** | |
// Set new font per document | |
// **************************** | |
using (var cadImage = (CadImage)Image.Load(file.FullName)) | |
{ | |
// Iterate over the items of CadStyleTableObject | |
foreach (CadStyleTableObject style in cadImage.Styles) | |
{ | |
// Set font name | |
style.PrimaryFontName = "Broadway"; | |
} | |
cadImage.Save(file.FullName + "_font.dxf"); | |
} | |
// **************************** | |
// Hide all "straight" lines | |
// **************************** | |
using (var cadImage = (CadImage)Image.Load(file.FullName)) | |
{ | |
foreach (var entity in cadImage.Entities) | |
{ | |
// Make lines invisible | |
if (entity.TypeName == CadEntityTypeName.LINE) | |
{ | |
entity.Visible = 0; | |
} | |
} | |
cadImage.Save(file.FullName + "_lines.dxf"); | |
} | |
// **************************** | |
// Manipulations with text | |
// **************************** | |
using (var cadImage = (CadImage)Image.Load(file.FullName)) | |
{ | |
foreach (var entity in cadImage.Entities) | |
{ | |
if (entity.TypeName == CadEntityTypeName.TEXT) | |
{ | |
((CadText)entity).DefaultValue = "New text here!!! :)"; | |
break; | |
} | |
} | |
cadImage.Save(file.FullName + "_text.dxf"); | |
} | |
} | |
Exportieren einer bestimmten Ebene von DXF Zeichnungen nach Bild
Dieser Ansatz funktioniert wie folgt:
- Öffnen Sie eine DXF-Zeichnungsdatei mit der Image.Load Fabrikmethode.
- Erstellen Sie eine Instanz von CadRasterizationOptions und geben Sie die Eigenschaften PageWidth und PageHeight an.
- Fügen Sie Ebenen zum Objekt von CadRasterizationOptions hinzu.
- Erstellen Sie eine Instanz von JpegOptions und setzen Sie deren VectorRasterizationOptions Eigenschaft.
- Exportieren Sie die Zeichnung nach PDF mit der Image.Save Methode.
Das folgende Code-Beispiel zeigt, wie man eine bestimmte Ebene von DXF nach Bild konvertiert.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "for_layers_test.dwf"; | |
using (var image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions | |
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
// Set image width & height | |
rasterizationOptions.PageWidth = 500; | |
rasterizationOptions.PageHeight = 500; | |
// Set the drawing to render at the center of image | |
// rasterizationOptions.CenterDrawing = true; | |
// Get the layers in an instance of CadLayersDictionary | |
var layersList = image.Layers; | |
// Iterate over the layers | |
foreach (var layerName in layersList.GetLayersNames()) | |
{ | |
// Display layer name for tracking | |
Console.WriteLine("Start with " + layerName); | |
// Add the layer name to the CadRasterizationOptions's layer list | |
rasterizationOptions.Layers = new string[] { "LayerA" }; | |
// Create an instance of JpegOptions (or any ImageOptions for raster formats) | |
var options = new Aspose.CAD.ImageOptions.JpegOptions(); | |
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions | |
options.VectorRasterizationOptions = rasterizationOptions; | |
//Export each layer to Jpeg format | |
image.Save(layerName + "_out.jpg", options); | |
} | |
} |