DXF図面
PDFへのDXF図面のエクスポート
Aspose.CADは、AutoCAD DXF図面エンティティをロードし、それらをPDF形式で全体の図面としてレンダリングする機能を提供します。DXFからPDFへの変換手法は次のように機能します。
- Image.Load ファクトリーメソッドを使用してDXF図面ファイルをロードします。
- CadRasterizationOptions クラスのオブジェクトを作成し、PageHeight と PageWidth プロパティを設定します。
- PdfOptions クラスのオブジェクトを作成し、VectorRasterizationOptions プロパティを設定します。
- Image.Save を呼び出し、PdfOptions のオブジェクトを2番目のパラメーターとして渡します。
以下のコードサンプルは、デフォルト設定を使用してファイルを変換する方法を示しています。
// 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); | |
} |
対応フォーマット
現在、私たちはAutoCAD DXF 2010ファイルフォーマットを完全にサポートしています。以前のDXFバージョンは100%有効であることは保証されません。将来的なAspose.CADバージョンにおいて、さらに多くのフォーマットと機能を含める予定です。
サポートされているエンティティ
現在、私たちはすべての一般的な2Dエンティティとその基本的なデフォルトパラメーターをサポートしています:
- アライン寸法
- 角度寸法
- アーク
- 属性
- ブロック参照
- 円
- 直径寸法
- 楕円
- ハッチ
- 線
- マルチラインテキスト
- 座標寸法
- 点
- ポリライン
- 放射寸法
- 光線
- 回転寸法
- テーブル
- テキスト
- X線
メモリ管理
Cache クラスのプロパティ ExactReallocateOnly は、メモリの再割り当てを制御するために使用できます。再割り当ては、事前に割り当てられたキャッシュに対して最も頻繁に発生します。システムが割り当てられたスペースが不十分であることを確認すると発生する可能性があります。
- ExactReallocateOnly がデフォルト値である False に設定されている場合、スペースは同じ媒体に再割り当てされます。
- True に設定されている場合、再割り当ては指定された最大スペースを超えることができません。この場合、既存のメモリ内キャッシュは解放され、拡張されたスペースがディスクに割り当てられます。
特定のDXF図面のレイヤーをPDFにエクスポート
この手法は次のように機能します:
- Image.Load ファクトリーメソッドを使用してDXF図面ファイルを開きます。
- CadRasterizationOptions のインスタンスを作成し、PageWidth と PageHeight プロパティを指定します。
- CadRasterizationOptions のオブジェクトにレイヤーを追加します。
- PdfOptions のインスタンスを作成し、その VectorRasterizationOptions プロパティを設定します。
- Image.Save メソッドを呼び出し、PdfOptions のオブジェクトを2番目のパラメーターとして渡します。
以下のコードサンプルは、DXFの特定のレイヤーをPDFに変換する方法を示しています。
// 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); | |
} |
DXF図面の一部としてPDFファイルをレンダリング
この手法は次のように機能します:
- Image.Load ファクトリーメソッドを使用してDXF図面ファイルをロードします。
- CadRasterizationOptions クラスのオブジェクトを作成し、PDFファイルをロードします。
- PageHeight と PageWidth プロパティを設定します。
- Image.Save を呼び出してファイルを保存します。
以下のコードサンプルは、DXF図面の一部としてPDFファイルをレンダリングする方法を示しています。
// 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); | |
} |
DXF形式の埋め込みDGNアンダーレイをエクスポート
Aspose.CADは、AutoCAD DXFファイルをロードし、DXF形式の埋め込みDGNアンダーレイをエクスポートする機能を提供します。
以下のコードサンプルは、指定された要件を達成する方法を示しています。
// 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); | |
} |
DXFファイルの保存サポート
Aspose.CADは、AutoCAD DXFファイルをロードし、変更を加えて再度DXFファイルとして保存する機能を提供します。
以下のコードサンプルは、指定された要件を達成する方法を示しています。
// 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からWMFへのエクスポート
この手法は次のように機能します:
- Image.Load ファクトリーメソッドを使用してDXF図面ファイルをロードします。
- CadRasterizationOptions クラスのオブジェクトを作成し、PDFファイルをロードします。
- PageHeight と PageWidth プロパティを設定します。
- Image.Save を呼び出してファイルを保存します。
// 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); | |
} |
特定のDXFレイアウトをPDFにエクスポート
この手法は次のように機能します:
- Image.Load ファクトリーメソッドを使用してDXF図面ファイルを開きます。
- CadRasterizationOptions のインスタンスを作成し、PageWidth と PageHeight プロパティを指定します。
- CadRasterizationOptions.Layouts プロパティを使用して、希望するレイアウト名を指定します。
- PdfOptions のインスタンスを作成し、その VectorRasterizationOptions プロパティを設定します。
- Image.Save メソッドを呼び出して描画をPDFにエクスポートし、PdfOptions のオブジェクトを2番目のパラメーターとして渡します。
以下のコードサンプルは、DXFの特定のレイアウトをPDFに変換する方法を示しています。
// 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); | |
} |
ブロッククリッピングのサポート
Aspose.CADは、ブロッククリッピング機能を提供します。ブロッククリッピング手法は次のように機能します:
- Image.Load ファクトリーメソッドを使用してDXF図面ファイルをロードします。
- CadRasterizationOptions クラスのオブジェクトを作成し、PDFファイルをロードします。
- CadRasterizationOptions の希望するプロパティを設定します。
- Image.Save を呼び出し、PdfOptionsのオブジェクトを第二引数として渡し、ファイルを保存します。
以下のコードサンプルは、ブロッククリッピングがどのように機能するかを示しています。
// 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); |
DXFに画像をエクスポート
Aspose.CADを使用すると、画像をDXF形式にエクスポートできます。この手法を使用して、次のアクションを実行できます:
- 新しいフォントを設定
- エンティティを非表示にする
- テキストを更新
以下のコードスニペットは、上記のアクションを実行する方法を示しています。
// 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"); | |
} | |
} |
DXF図面の特定のレイヤーを画像にエクスポート
この手法は次のように機能します:
- Image.Load ファクトリーメソッドを使用してDXF図面ファイルを開きます。
- CadRasterizationOptions のインスタンスを作成し、PageWidth および PageHeight プロパティを指定します。
- CadRasterizationOptions のオブジェクトにレイヤーを追加します。
- JpegOptions のインスタンスを作成し、その VectorRasterizationOptions プロパティを設定します。
- Image.Save メソッドを使用して描画をPDFにエクスポートします。
以下のコードサンプルは、DXFの特定のレイヤーを画像に変換する方法を示しています。
// 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); | |
} | |
} |