我们可以使用 C#以编程方式打印VSDX、DWG、VDW、VSTX等图表文档。Aspose.Diagram for .NET API 可以集成到基于 .NET 的应用程序中,以处理 Microsoft Visio 文件。请参考以下用例打印图表文档:
- 使用 C# 以编程方式使用 XpsPrint 打印 Visio 文档
- 在 C# 中以编程方式将 Visio 图表打印到默认打印机
- 使用 C# 以编程方式将 Visio 图表打印到特定打印机
我们可以使用Aspose.Diagram for .NET以 VSD、VSDX、DWG 和许多其他支持的文件格式打印 Visio 形状和图表。下载最新版Aspose.Diagram
使用 C# 以编程方式使用 XpsPrint 打印 Visio 文档
XpsPrint 类对于在服务器端应用程序上打印图表文件非常有用,因为服务不支持使用 .NET Framework 打印类。以下步骤解释了如何使用 C# 以编程方式使用 XpsPrint 打印 Visio 文档:
- 使用 Aspose.Diagram 将文档转换为 XPS 并将其存储在内存流中。
- 使用 XpsPrint API 将图表文档发送到打印机。
以下代码显示了如何通过使用 XpsPrint API 将 Visio 文档发送到打印机来打印它:
public static void Print(Diagram diagram, string printerName, string jobName, bool isWait)
{
if (diagram == null)
throw new ArgumentNullException("document");
// Use Aspose.Diagram to convert the document to XPS and store in a memory stream.
MemoryStream stream = new MemoryStream();
diagram.Save(stream, SaveFileFormat.XPS);
stream.Position = 0;
// Send a Diagram document to a printer using the XpsPrint API
Print(stream, printerName, jobName, isWait);
}
在 C# 中以编程方式将 Visio 图表打印到默认打印机
可以使用 C# 以编程方式打印 Visio 图表文件,例如 VSDX、DWG、VST 等。请按照以下步骤操作:
- 创建Diagram类的实例以加载要打印的图表。
- 调用不带任何参数或参数的Print方法。
下面的代码解释了如何使用 C# 以编程方式将 Microsoft Diagram 文件打印到默认打印机:
// Load source Visio VSD or VSDX diagram
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
// Call the print method to print whole Diagram using the default printer
diagram.Print();
使用 C# 以编程方式将 Visio 图表打印到特定打印机
您可以使用以下步骤将包含不同形状的 Visio 图表打印到特定打印机:
- 使用Diagram类加载输入图表文件
- 指定打印机名称和作业名称并调用Print()方法。
以下代码详细说明了如何在 C# 中将 Diagram 文件打印到特定打印机:
// Load source Visio diagram
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
// Call the print method to print whole Diagram using the printer name and set document name in the print job
diagram.Print("LaserJet1100", "Test Job");
如果您有任何疑问或需求,请随时加入Aspose技术交流群(761297826),很高兴为您提供查询和咨询。