Convert Visio to PDF format
Export to PDF
Aspose.Diagram for .NET directly writes the information about the API and Version Number in output documents. For example, upon rendering a Drawing to PDF, Aspose.Diagram for .NET populates Anwendung Feld mit dem Wert ‘Aspose.Diagram’ undPDF Producer Feld mit Wert, zB ‘Aspose.Diagram 17.9’.
Bitte beachten Sie, dass Sie Aspose.Diagram for .NET API nicht anweisen können, diese Informationen aus Ausgabedokumenten zu ändern oder zu entfernen.
This article explains how to export a Microsoft Visio diagram to PDF using Aspose.Diagram for .NET API.
Verwenden Sie dieDiagram -Klassenkonstruktor zum Lesen der diagram-Dateien und die Save-Methode zum Exportieren von diagram in ein beliebiges unterstütztes Bildformat.
The image below shows the VSD diagram that the code snippets below export PDF. You can use other diagram formats (VSS, VSSM, VDX, VST, VSTX, VDX, VTX or VSX) as well.
Die Quelldatei. |
---|
![]() |
To export VSD diagram to PDF:
- Erstellen Sie eine Instanz der Klasse Diagram.
- Call the Diagram classs Save method and set the output format to PDF.
Below is an image of the output PDF file.
Die Ausgabedatei PDF. |
---|
![]() |
Export Microsoft Visio Drawing to PDF
The code samples show how to export Microsoft Visio Drawing to PDF using C#.
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_LoadSaveConvert(); | |
// Call the diagram constructor to load a VSD diagram | |
Diagram diagram = new Diagram(dataDir + "ExportToPDF.vsd"); | |
MemoryStream pdfStream = new MemoryStream(); | |
// Save diagram | |
diagram.Save(pdfStream, SaveFileFormat.PDF); | |
// Create a PDF file | |
FileStream pdfFileStream = new FileStream(dataDir + "ExportToPDF_out.pdf", FileMode.Create, FileAccess.Write); | |
pdfStream.WriteTo(pdfFileStream); | |
pdfFileStream.Close(); | |
pdfStream.Close(); | |
// Display Status. | |
System.Console.WriteLine("Conversion from vsd to pdf performed successfully."); |
Mehrere Seiten aufteilen
Aspose.Diagram for .NET allows splitting multiple pages while converting the Microsoft Visio Diagram to PDF. The following code snippet shows the functionality.
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_LoadSaveConvert(); | |
// Call the diagram constructor to load diagram from a VSDX file | |
Diagram diagram = new Diagram(dataDir + "Network Diagram_start.vsdx"); | |
// Initialize PdfSaveOptions | |
Aspose.Diagram.Saving.PdfSaveOptions options = new Aspose.Diagram.Saving.PdfSaveOptions(); | |
// set SplitMultiPages option | |
options.SplitMultiPages = true; | |
// save in PDF format | |
diagram.Save(dataDir + "SplitMultiPages.pdf", options); |
Verwenden Sie den Seitenspeicher-Callback
In case you have multiple pages, Aspose.Diagram for .NET allows using page saving callback while converting the Microsoft Visio Diagram to PDF. The following code snippet shows the functionality.
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_LoadSaveConvert(); | |
// Call the diagram constructor to load diagram from a VSDX file | |
Diagram diagram = new Diagram(dataDir + "Network Diagram_start.vsdx"); | |
// Initialize PdfSaveOptions | |
Aspose.Diagram.Saving.PdfSaveOptions options = new Aspose.Diagram.Saving.PdfSaveOptions(); | |
// set PageSavingCallback option | |
options.PageSavingCallback = new TestDiagramPageSavingCallback(); | |
// save in PDF format | |
diagram.Save(dataDir + "PageSavingCallback.pdf", options); |
TestDiagramPageSavingCallback-Klasse
öffentliche Klasse TestDiagramPageSavingCallback : Aspose.Diagram.Saving.IPageSavingCallback
{
public void PageStartSaving(Aspose.Diagram.Saving.PageStartSavingArgs args)
{
Console.WriteLine("Start save diagram page {0} of pages {1}", args.PageIndex + 1, args.Page0Count);
{
}
public void PageEndSaving(Aspose.Diagram.Saving.PageEndSavingArgs args)
{
Console.WriteLine("Speicherung diagram Seite {0} von Seiten {1} beenden", args.PageIndex. + 1);
//don't output pages after page index 8.
if (args.PageIndex >= 8)
{
args.HasMorePages = false;
}
}
}