Exporting the Chart Image to the PDF on the Client
To export the chart image to the PDF on the client, use the following code:
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim wb As New WriteableBitmap(chart, Nothing)
Dim doc As New C1PdfDocument()
doc.Compression = CompressionLevelEnum.BestSpeed
doc.DrawImage(wb, New Rect(New Point(), doc.PageSize), ContentAlignment.TopLeft, Stretch.None)
Dim sfd As New SaveFileDialog()
If sfd.ShowDialog() = True Then
Using stream = sfd.OpenFile()
doc.Save(stream)
End Using
End If
End Sub
•C#
private void Button_Click(object sender, RoutedEventArgs e)
{
WriteableBitmap wb = new WriteableBitmap(chart, null);
C1PdfDocument doc = new C1PdfDocument();
doc.Compression = CompressionLevelEnum.BestSpeed;
doc.DrawImage(wb, new Rect(new Point(),doc.PageSize), ContentAlignment.TopLeft, Stretch.None);
SaveFileDialog sfd = new SaveFileDialog()
{
DefaultExt = "pdf",
Filter = "Pdf files (*.pdf)|*.pdf",
};
if (sfd.ShowDialog() == true)
{
using (var stream = sfd.OpenFile())
{
doc.Save(stream);
}
}
}