Index out of range when Printing current Page

8 posts, 0 answers
  1. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 03 Apr 2014 Link to this post

    Hi!

    I'm using the following code to Print a PDF-Document from an Viewer with an external Button:

    1.Public Shared Sub printPdf(newPdfViewerNavigator As RadPdfViewerNavigator, newPdfViewer As RadPdfViewer, Optional landscape As Boolean = False, Optional silent As Boolean = False)
    2.    newPdfViewerNavigator.PrintDocument.DefaultPageSettings.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)
    3.    newPdfViewerNavigator.PrintDocument.Landscape = landscape
    4.    newPdfViewer.Print(True, newPdfViewerNavigator.PrintDocument)
    5.End Sub

    The main Problem is when selecting only the current page to print, an "index out of range" error occoured in line 4. Printing an selected Range (page 1-2, page2...) is working.

    I'm using Version 2013.1.321.40

    The second Problem is, that the print-button on the Printer-settings page has to be clicked twice to start printing. It looks like, that the first click focuses the form and the second initiates the click event...

    Please help.

    Best
    Willi
  2. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 03 Apr 2014 in reply to willi Link to this post

    Update: 
    Same in Version: 2014.1.226.40
  3. UI for WinForms is Visual Studio 2017 Ready
  4. George
    Admin
    George avatar
    500 posts

    Posted 08 Apr 2014 Link to this post

    Hi Wilfrid,

    Thank you for contacting us.

    I was not able to reproduce this behavior on my end. Could you please provide me with a sample where the problem is reproducible ? I think that the issue may come from the specific PDF document, so please make sure to attach it also.

    Moreover, it appeared that the Print button in the print settings was working fine, please provide me with detailed instructions on this matter too.

    Looking forward to your response.

    Regards,
    George
    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.

     
  5. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 10 Apr 2014 Link to this post

    So, as its not possible to attach an zip here, her you can download the Demosolution

    https://dl.dropboxusercontent.com/u/24065/TelerikDemo.zip

    Reproducing the error with the crash:
    1. Running the Solution (When running the Programm a Window with the PDF-Viewer opens and a PDF is loaded. )
    2. Press the Print Button on the right hand side
    3. In the Printer-Dialog select only printinaag the current Page
    4. Press Print - Programm crashes

    Reproducing the Focusing problem
    Step 1,2 from above
    3. Imidiatly press the Print Button (without clicking on the printerform) - Nothing happens - 
    4. "Press" button again the printing will be started

    best
    Willi














  6. George
    Admin
    George avatar
    500 posts

    Posted 15 Apr 2014 Link to this post

    Hello Wilfrid,

    Thank you for contacting us.

    I have identified the exception. The issue is logged in our Feedback Portal and can be found on the following url: http://feedback.telerik.com/Project/154/Feedback/Details/125972-fix-radpdfviewer-printing-by-calling-the-print-method-of-radpdfviewer-and-sele. For the time being due to the implementation of the printing mechanism the issue cannot be directly worked around. You can however, instead of selecting the CurrentPage to select the Pages button and specify the page to be printed.

    I have also logged your other report - http://feedback.telerik.com/Project/154/Feedback/Details/125981-fix-radpdfviewer-openning-the-printdialog-using-the-print-method-causes-the-di. Currently, this issue has no workaround since the dialog is a standard WinForms PrintDialog.

    I have updated your Telerik Points for bringing this to our attention. 

    Let me know if you have further questions.

    Regards,
    George
    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.

     
  7. Matthias
    Matthias avatar
    2 posts
    Member since:
    Jun 2013

    Posted 29 Apr 2014 in reply to George Link to this post

    Hey,
    i use this workaround:

    private void button2_Click(object sender, EventArgs e)
    {
            RadPrintDocument document = new RadPrintDocument();
            document.BeginPrint += document_BeginPrint;
            radPdfViewer1.Print(true,document);
    }

    void document_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
            {
                    if(((System.Drawing.Printing.PrintDocument)(sender)).PrinterSettings.FromPage==0 &&((System.Drawing.Printing.PrintDocument)(sender)).PrinterSettings.ToPage==0){
                   //Fix da aktuelle Seite nicht geht
                    ((System.Drawing.Printing.PrintDocument)(sender)).PrinterSettings.FromPage = int.Parse(this.radPdfViewerNavigator1.CurrentPageTextBox.Text);
                    ((System.Drawing.Printing.PrintDocument)(sender)).PrinterSettings.ToPage = int.Parse(this.radPdfViewerNavigator1.CurrentPageTextBox.Text);
                    ((System.Drawing.Printing.PrintDocument)(sender)).PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.SomePages;
            }
    }
  8. willi
    willi avatar
    22 posts
    Member since:
    Oct 2006

    Posted 29 Apr 2014 in reply to Matthias Link to this post

    Thanks Matthias, its working like a charm...
  9. George
    Admin
    George avatar
    500 posts

    Posted 30 Apr 2014 Link to this post

    Hi Guys,

    I am glad that you have found a solution to the issue.

    Do not hesitate to write back, should you have further questions.

    Regards,
    George
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
UI for WinForms is Visual Studio 2017 Ready