How export Grids to PDF in VB.Net

9 posts, 0 answers
  1. Jason
    Jason avatar
    14 posts
    Member since:
    Nov 2012

    Posted 18 Jan 2013 Link to this post

    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)
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 18 Jan 2013 Link to this post

    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.

  3. DevCraft banner
  4. Jason
    Jason avatar
    14 posts
    Member since:
    Nov 2012

    Posted 18 Jan 2013 Link to this post

    Thanks, but that's .cs and I'm looking for .vb code.
  5. Jason
    Jason avatar
    14 posts
    Member since:
    Nov 2012

    Posted 22 Jan 2013 Link to this post

    Can anyone help? Thanks.
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 22 Jan 2013 Link to this post

    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.

  7. Jason
    Jason avatar
    14 posts
    Member since:
    Nov 2012

    Posted 22 Jan 2013 Link to this post

    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.
  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 22 Jan 2013 Link to this post

    Hi,

     You've missed to copy all code. 

    Kind regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  9. Jason
    Jason avatar
    14 posts
    Member since:
    Nov 2012

    Posted 22 Jan 2013 Link to this post

    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.
  10. Dt
    Dt avatar
    3 posts
    Member since:
    May 2016

    Posted 24 May in reply to Vlad Link to this post

    *Deleted by administrator*
Back to Top
DevCraft banner