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

PagesPerSheet does not working at the time of GridView Printing

3 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bharat Mendapara
Top achievements
Rank 1
Bharat Mendapara asked on 25 Mar 2014, 10:17 AM
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

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 26 Mar 2014, 04:07 PM
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.

 
0
Bharat Mendapara
Top achievements
Rank 1
answered on 08 Apr 2014, 06:03 AM
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
 
0
Petya
Telerik team
answered on 10 Apr 2014, 04:04 PM
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.

 
Tags
GridView
Asked by
Bharat Mendapara
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Bharat Mendapara
Top achievements
Rank 1
Petya
Telerik team
Share this question
or