PagesPerSheet does not working at the time of GridView Printing

4 posts, 0 answers
  1. Bharat Mendapara
    Bharat Mendapara avatar
    18 posts
    Member since:
    Sep 2013

    Posted 25 Mar 2014 Link to this post

    I want to print two pages per sheet .Because I have one GridView and only three columns are available in the GridView. So remaining part of the page are unuseful.
    so that I set  PrintDialog.PrintTicket.PagesPerSheet = 2 and PrintDialog.PrintQueue.DefaultPrintTicket.PagesPerSheet = 2. But its not working. And I am using following code for the Printing.

    public static void Print(this GridViewDataControl source, bool showDialog, bool p_IsLandscape = true)
            {
                try
                {
                    PrintDialog _PrintDialog = new PrintDialog();
                    _PrintDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
                    _PrintDialog.PrintTicket = _PrintDialog.PrintQueue.DefaultPrintTicket;
                  
                    if (p_IsLandscape)
                        _PrintDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
                    else
                    {
                        _PrintDialog.PrintTicket.PageOrientation = PageOrientation.Portrait;
                        _PrintDialog.PrintTicket.PagesPerSheet = 2;
                        _PrintDialog.PrintQueue.DefaultPrintTicket.PagesPerSheet = 2;
                    }

                    bool? dialogResult = showDialog ? _PrintDialog.ShowDialog() : true;

                    if (dialogResult == true)
                    {
                        DocumentViewer viewer = new DocumentViewer();
                        viewer.Document = ToFixedDocument(ToPrintFriendlyGrid(source), _PrintDialog);
                        _PrintDialog.PrintDocument(viewer.Document.DocumentPaginator, null);
                    }
                }
                catch
                {
                       throw _Exception;
                }
            }

    static FixedDocument ToFixedDocument(FrameworkElement element, PrintDialog dialog)
            {
                PrintCapabilities capabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket);
                FixedDocument fixedDocument = new FixedDocument();

                element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                Size pageSize = new Size(element.DesiredSize.Width, dialog.PrintableAreaHeight);
                Size extentSize = new Size(element.DesiredSize.Width, capabilities.PageImageableArea.ExtentHeight);

                double totalHeight = element.DesiredSize.Height;
                double totalWidth = element.DesiredSize.Width;
                double yOffset = 0d;

                if (totalWidth < dialog.PrintableAreaWidth)
                {
                    Size _Size = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
                    element.Arrange(new Rect(new Point(0, 0), _Size));
                }
                else
                {
                    element.Arrange(new Rect(new Point(0, 0), element.DesiredSize));
                }

                while (yOffset < totalHeight)
                {
                    VisualBrush brush = new VisualBrush(element);
                    brush.Stretch = Stretch.None;
                    brush.AlignmentX = AlignmentX.Left;
                    brush.AlignmentY = AlignmentY.Top;
                    brush.ViewboxUnits = BrushMappingMode.Absolute;
                    brush.TileMode = TileMode.None;
                    if (totalWidth < dialog.PrintableAreaWidth)
                        brush.Viewbox = new Rect(0, yOffset, dialog.PrintableAreaWidth, extentSize.Height);
                    else
                        brush.Viewbox = new Rect(0, yOffset, extentSize.Width, extentSize.Height);

                    PageContent pageContent = new PageContent();
                    FixedPage page = new FixedPage();
                    ((IAddChild)pageContent).AddChild(page);

                    fixedDocument.Pages.Add(pageContent);

                    if (totalWidth < dialog.PrintableAreaWidth)
                        page.Width = dialog.PrintableAreaWidth;
                    else
                        page.Width = totalWidth;

                    page.Height = pageSize.Height;

                    Canvas canvas = new Canvas();
                    FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
                    FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);

                    if (totalWidth < dialog.PrintableAreaWidth)
                        canvas.Width = dialog.PrintableAreaWidth;
                    else
                        canvas.Width = extentSize.Width;

                    canvas.Height = extentSize.Height;
                    canvas.Background = brush;

                    page.Children.Add(canvas);

                    yOffset += extentSize.Height;
                }
                return fixedDocument;
            }

    Can you help

    Thanks
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 26 Mar 2014 Link to this post

    Hi,

    You could pass the PrintDialog to the RadRichTextBox.
    For example:
    this.radRichTextBox.Print(PrintDialog printDialog, PrintSettings printSettings). 

    Please note this will only take effect if the printer allows pages per sheet. 

    Regards,
    Didie
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
  3. Bharat Mendapara
    Bharat Mendapara avatar
    18 posts
    Member since:
    Sep 2013

    Posted 08 Apr 2014 Link to this post

    Hi Didie,

    I have also tried this.radRichTextBox.Print(PrintDialog printDialog, PrintSettings printSettings) but it still not working
    and I also want to PrintPreview  for this print.

    Can you help me?

    Regards
    Bharat Mendapara
     
  4. Petya
    Admin
    Petya avatar
    990 posts

    Posted 10 Apr 2014 Link to this post

    Hello Bharat,

    As Didie said, as long as the printer you are using supports this you should be able to specify the pages per sheet property. This is how you can obtain the capabilities of your printer to see if this is supported:
    PrintCapabilities capabilities = printQueue.GetPrintCapabilities();

    I suggest you refer to the Print and Export with RadDocument example for RadGridView in the demos to see how print preview can be implemented. Additionally, this SDK example shows how you can print using RadRichTextBox's Print() overload which accepts PrintDialog as parameter.

    I hope this helps.

    Regards,
    Petya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top