This is a migrated thread and some comments may be shown as answers.

How export Grids to PDF in VB.Net

8 Answers 35 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 18 Jan 2013, 11:36 AM
I'm struggling to see how to export my output to PDF using VB.Net and Telerik Silverlight controls.

I have my LayoutRoot Grid that contains several other Grids, including a couple of RadChartView charts.

I would like a button that exports the whole LayoutRoot grid to PDF. (It is about 1100 pixels wide and 5000 pixels high).

Failing that, I could have separate buttons that export the sepaarte grids on an individual basis.

I really have no idea how to go about this. Does any one have any sample VB.Net code?

Thanks,

Jason.

(Using Silverlight 5, VB.Net and Telerik Silverlight Controls 2012 Q3)

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 18 Jan 2013, 11:40 AM
Hi,

 You can use similar to this demo approach to achieve your goal.

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Jason
Top achievements
Rank 1
answered on 18 Jan 2013, 12:07 PM
Thanks, but that's .cs and I'm looking for .vb code.
0
Jason
Top achievements
Rank 1
answered on 22 Jan 2013, 03:11 PM
Can anyone help? Thanks.
0
Vlad
Telerik team
answered on 22 Jan 2013, 03:12 PM
Hello,

 When you select the code file just click the VB.NET tab in the code viewer.

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Jason
Top achievements
Rank 1
answered on 22 Jan 2013, 04:06 PM
Thanks Vlad. I missed that. So where am I going wrong here?

XAML:

<UserControl x:Class="Grid2PDF.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid Height="88" HorizontalAlignment="Left" Margin="12,12,0,0" Name="Grid1" VerticalAlignment="Top" Width="376">
            <Grid.RowDefinitions>
                <RowDefinition Height="39*" />
                <RowDefinition Height="49*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="178*" />
                <ColumnDefinition Width="198*" />
            </Grid.ColumnDefinitions>
            <TextBlock Height="23" HorizontalAlignment="Left" Margin="60,6,0,0" Name="TextBlock1" Text="Row 0, Col 0" VerticalAlignment="Top" />
            <TextBlock Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="75,6,0,0" Name="TextBlock2" Text="Row 0, Col  1" VerticalAlignment="Top" />
            <TextBlock Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="60,20,0,0" Name="TextBlock3" Text="Row 1, Col 0" VerticalAlignment="Top" />
            <TextBlock Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="75,20,0,0" Name="TextBlock4" Text="Row 1, Col 1" VerticalAlignment="Top" />
        </Grid>
        <Button Content="Export" Height="23" HorizontalAlignment="Left" Margin="168,0,0,144" Name="Button1" VerticalAlignment="Bottom" Width="75" />
    </Grid>
</UserControl>

VB.Net:

Imports Telerik.Windows.Controls.Navigation
Imports Telerik.Windows.Data
Imports Telerik.Windows.Documents
Imports Telerik.Windows.Documents.FormatProviders.Pdf
Imports Telerik.Windows.Documents.Fixed
Imports Telerik.Windows.Documents.Model
Imports System.IO


Partial Public Class MainPage
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
    End Sub

    Public Sub Export(parameter As Object)
        Dim dialog As New SaveFileDialog()
        dialog.DefaultExt = "*.pdf"
        dialog.Filter = "Adobe PDF Document (*.pdf)|*.pdf"

        If dialog.ShowDialog() = True Then
            Dim document As RadDocument = CreateDocument(TryCast(parameter, LayoutRoot))

            document.LayoutMode = DocumentLayoutMode.Paged

            document.Measure(RadDocument.MAX_DOCUMENT_SIZE)
            document.Arrange(New RectangleF(PointF.Empty, document.DesiredSize))

            Dim provider As New PdfFormatProvider()

            Using output As Stream = dialog.OpenFile()
                provider.Export(document, output)
            End Using
        End If
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Call Export(Grid1)
    End Sub
End Class

Screenshot:

Attached.

Thanks.
0
Vlad
Telerik team
answered on 22 Jan 2013, 04:11 PM
Hi,

 You've missed to copy all code. 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Jason
Top achievements
Rank 1
answered on 22 Jan 2013, 04:30 PM
I'm not sure how much of the code I actually needed since my Grid is a simple regular Silverlight 5 grid rather than any sort of Telerik control.

Can you help?

Thanks.
0
Dt
Top achievements
Rank 1
answered on 25 May 2016, 02:14 AM
*Deleted by administrator*
Tags
General Discussions
Asked by
Jason
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Jason
Top achievements
Rank 1
Dt
Top achievements
Rank 1
Share this question
or