从 C# 中的 PDF 导入 3D 场景和内容

从受密码保护的 PDF 打开场景

Scene 类的 Open 方法允许从输入 PDF 文件加载 3D 场景。开发人员还可以使用 PdfLoadOptions 类为受保护的pdf应用密码,如以下 C# 代码示例所示:

// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
// Create a new scene
Scene scene = new Scene();
// Use loading options and apply password
PdfLoadOptions opt = new PdfLoadOptions() { Password = Encoding.UTF8.GetBytes("password") };
// Open scene
scene.Open("House_Design.pdf", opt);

从 PDF 中提取所有原始 3D 内容

PdfFormat 类的Extract方法允许从 PDF 文件中提取 3D 内容。开发人员可以遍历内容,并将它们保存到单独的文件中,如 C# 代码示例所示:

// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
// The path to the documents directory.
byte[] password = null;
// Extract 3D contents
List<byte[]> contents = FileFormat.PDF.Extract("House_Design.pdf", password);
int i = 1;
// Iterate through the contents and in separate 3D files
foreach (byte[] content in contents)
{
string fileName = "3d-" + (i++);
File.WriteAllBytes(fileName, content);
}

提取所有 3D 场景并将其保存为支持的 3D 格式

PdfFormat 类的 ExtractScene 方法允许从 PDF 文件中提取 3D 场景。开发人员可以遍历场景,并将它们保存为支持的 3D 文件格式,如以下 C# 代码示例所示:

// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
byte[] password = null;
List<Scene> scenes = FileFormat.PDF.ExtractScene("House_Design.pdf", password);
int i = 1;
// Iterate through the scenes and save in 3D files
foreach (Scene scene in scenes)
{
string fileName = "3d-" + (i++) + ".fbx";
scene.Save(RunExamples.GetOutputFilePath(fileName), FileFormat.FBX7400ASCII);
}