- Open the Default.aspx file, switch to Design view. Add an 'Export PDF' button to the Web Form.
- To specify the click event of the Layout button, do the following steps:
- In Design view, click the Layout button.
- In the Properties window, click the Events icon.
- In the Click event's field on the right, type in the name of button click event, in this case 'btnLayout_Click'. Press ENTER.
- Define the Export PDF button click event handler.
After clicking the button, the btnExportPdf_Click event is raised. This event is handled by using the PdfExporter on the server.
Add the following code in the btnExportPdf_Click event handler:
C#
Copy Code
|
---|
protected void btnExportPdf_Click(object sender, EventArgs e) { MindFusion.Diagramming.Export.PdfExporter pdf = new MindFusion.Diagramming.Export.PdfExporter();
string path = Server.MapPath(@"~\PDF\") + Session.SessionID + ".pdf"; pdf.Export(diagView.Diagram, path);
pdfURL.Value = "PDF/" + Session.SessionID + ".pdf"; } |
- The 'onLoad' function on the client opens the diagram from the PDF file if it is not an empty document.
JavaScript
Copy Code
|
---|
function onLoad() { var url = document.getElementById("pdfUrl"); if (url.value != "") { window.open(url.value); url.value = ""; } } |
The 'onLoad' function is contained in the Default.aspx file. It is assigned to the "onload" attribute of the <body> element.
Default.aspx
Copy Code
|
---|
<body onload="onLoad()"> ... |
- Click the Export PDF button.
The PdfExporter.Export method is performed and the diagram is exported as a PDF file.