PDF Viewer Control

Posted by: utkarsha.rukade on 14 May 2020, 10:45 pm EST

    • Post Options:
    • Link

    Posted 14 May 2020, 10:45 pm EST - Updated 3 October 2022, 11:51 pm EST

    I have one query related to the toolbar view of PDF Viewer control.

    If any user will purposely blank the pdf preview zoom percentage ,

    last valid value should be displayed in “pdf preview zoom percentage”

    e.g.

    1.1. If first user select pdf preview zoomed percentage as 100%

    2.1 User can able to see its pdf preview with 100%

    3.1 Now if user delete and set blank in pdf preview zoomed percentage , pdf preview zoomed percentage will be set as 100%

  • Posted 18 May 2020, 1:10 am EST

    Hi,

    The C1ComboBox displaying Zoom% options of C1PdfViewerToolbar is not directly bound with the C1PdfViewer Zoom property because it is not feasible to add every percent value as ComboBoxItem. Therefore setting this combobox’s value to null won’t revert it back to the previous valid zoom% value.

    However, when the C1ComboBox selected item becomes null the C1PdfViewer still have the last Zoom value which can be used to restore the selected item of C1ComboBox.

    You may use the the C1ComboBox’s LostFocus event to restore the selected item as follows:

    XAML

    <Window.Resources>
            <Style TargetType="c1:C1ComboBox">
                <EventSetter Event="LostFocus" Handler="ZoomComboBoxLostFocus"></EventSetter>
            </Style>
    </Window.Resources>
     <Grid>
            <c1:C1PdfViewer x:Name="_pdfViewer"></c1:C1PdfViewer>
     </Grid>
    

    C#

    private void ZoomComboBoxLostFocus(object sender, RoutedEventArgs e)
    {
         if((sender as C1ComboBox).SelectedItem == null && (sender as C1ComboBox).TemplatedParent is C1PdfViewerToolbar)
         {
              (sender as C1ComboBox).SelectedItem = _pdfViewer.Zoom;
         }
    }
    

    Best Regards,

    Basant

  • Posted 19 May 2020, 9:11 pm EST

    Hello,

    Thank You.

    Given solution is good.

    But having two observations :

    1. If we set zoom percentage “One Page” and again make it blank - On its lost focus it shown me 46%.
    2. Same for “Fit Width” On its lost focus it shown me 74%.

    We want that lost focus on “Fit Width” should be Fit width only

    and “One Page” should be One page only.

  • Posted 19 May 2020, 11:55 pm EST

    Hi,

    You can check the C1PdfViewer.ViewMode while updating SelectedItem for target combobox as follows:

    private void ZoomComboBoxLostFocus(object sender, RoutedEventArgs e)
    {
         if((sender as C1ComboBox).SelectedItem == null && (sender as C1ComboBox).TemplatedParent is C1PdfViewerToolbar)
          {
                if (_pdfViewer.ViewMode != ViewMode.Normal)
                     (sender as C1ComboBox).SelectedItem = _pdfViewer.ViewMode;
                else
                     (sender as C1ComboBox).SelectedItem = _pdfViewer.Zoom;
          }
    }
    

    Regards,

    Basant

  • Posted 20 May 2020, 4:34 am EST

    Hello,

    It works properly.

    Thank you so much.

  • Posted 21 May 2020, 12:40 am EST

    Hello,

    If I set Zoom Percentage e.g. 100% and delete or making it blank

    then press ‘Enter’ key it doesn’t return previously set value i.e. 100%

  • Posted 21 May 2020, 2:21 pm EST

    Hello,

    Is there any update on above issue.

    We are waiting for reply.

  • Posted 21 May 2020, 4:26 pm EST

    Hi Utkarsha,

    Sorry to make you wait. The delay might be because of difference in working hours.

    Now, please let me correct myself. Since our motive is to revert the selection to previous valid selection when Null/Empty is selected. So, Instead of handling LostFocus, we should handle the SelectedItemChanged event on zoom combobox:

    private void C1ComboBox_SelectedItemChanged(object sender, PropertyChangedEventArgs<object> e)
    {
     if ((sender as C1ComboBox).SelectedItem == null)
     {
      if (c1PdfViewer1.ViewMode != ViewMode.Normal)
       (sender as C1ComboBox).SelectedItem = c1PdfViewer1.ViewMode;
      else
       (sender as C1ComboBox).SelectedItem = c1PdfViewer1.Zoom;
     }
    }
    
    private void C1ComboBox_Loaded(object sender, RoutedEventArgs e)
    {
     (sender as C1ComboBox).SelectedItemChanged += C1ComboBox_SelectedItemChanged;
    }
    

    XAML:

    <c1:C1PdfViewer Name="c1PdfViewer1" Grid.Row="1">
     <c1:C1PdfViewer.Resources>
      <Style TargetType="c1:C1ComboBox">
       <EventSetter Event="Loaded" Handler="C1ComboBox_Loaded"></EventSetter>
      </Style>
     </c1:C1PdfViewer.Resources>
    </c1:C1PdfViewer>
    

    Regards,

    Basant

  • Posted 21 May 2020, 8:18 pm EST

    Hello,

    Thank you.

    Similarly if I enter value in Page Number text box e.g. 5 and delete or making it blank

    then press ‘Enter’ key (from keyboard) it doesn’t return previously set value i.e. 5.

  • Posted 21 May 2020, 9:03 pm EST

    Utkarsha,

    Just like we handled the zoom combobox selection as per our requirement, we can handle the KeyDown (for Enter) on PageNumber textbox as follows:

            private void C1TextBoxBase_Loaded(object sender, RoutedEventArgs e)
            {
                var tb = sender as C1TextBoxBase;
                if(tb.Name == "PageNumber")
                {
                    tb.KeyDown += (s,eArgs)=>
                    {
                        int num;
                        if (eArgs.Key == Key.Enter && (!int.TryParse(tb.Text, out num) || num < 1 || num > c1PdfViewer1.PageCount))
                        {
                            tb.Text = c1PdfViewer1.PageNumber.ToString();
                        }
                    };
                }
            }
    

    XAML:

                    <Style TargetType="c1:C1TextBoxBase">
                        <EventSetter Event="Loaded" Handler="C1TextBoxBase_Loaded"></EventSetter>
                    </Style>
    

    ~Basant

  • Posted 14 June 2020, 3:07 pm EST

    Hello,

    Thank You!

    Above solution is working properly.

  • Posted 14 June 2020, 3:26 pm EST

    Dear Team,

    I have one query related to the toolbar view of PDF Viewer control.

    We have shortcut keys for PDF Viewer.

    1. ALT+S" (Search)
    2. Shift+ALP+P" (Page Number)
    3. ALT+ Right Arrow" (Goto Last Page Option)

      If I click on that page then shortcut keys are working.

    Until and unless we cannot click on that page, these shortcut keys are not working.

    We want that shortcut keys are working directly without clicking on page(PDF preview generated page).

  • Posted 14 June 2020, 5:48 pm EST

    Hi Utkarsha,

    In order to execute shortcut key operations, The control needs to be in focused state. Therefore when you click on the page it gets focused and that’s why shortcut keys work.

    So, you can call Focus method for PDF Viewer inside its Loaded event as follows:

    private void PDFViewerLoaded(object sender, RoutedEventArgs e)
    {
          _pdfViewer.Focus();
    }
    

    Also, please create a new thread for a new, different query even if it is for the same control as it is good for the clarity of the associated thread.

    Best Regards,

    Basant

  • Posted 25 June 2020, 11:37 pm EST

    Dear Team,

    I have used above solution.

    However if I press Alt + S (Search) then immediately pressing Shift+ALT+P" (Page Number).

    In that case focus is not shifted to Page Number.

    Focus gets block on Search box.

    We want that Shortcut-Keys working smoothly.

    I am continuing on this page because reference of this question has mentioned above.

    Will definitely create new thread for next question.

    Thanks,

    Utkarsha

  • Posted 28 June 2020, 3:37 pm EST

    Dear Team,

    Is there any update.

    We are waiting for reply.

  • Posted 28 June 2020, 8:41 pm EST

    Hi Utkarsha,

    Sorry for the delay due to weekend off.

    Regarding the issue, there is no built-in search command associated with C1PdfViewer. Can you please tell us how you are creating a search shortcut/command so that we can assist accordingly?

    Regards,

    Basant

  • Posted 28 June 2020, 11:12 pm EST - Updated 3 October 2022, 11:51 pm EST

    Dear Team,

    I would like to share Screenshot:

    Only for search and Page Number we get this issue.

    Other shortcut keys are working properly(sync).

    We want to know is it limitation?

    Thanks,

    Utkarsha

  • Posted 29 June 2020, 4:50 pm EST

    Hi Utkarsha,

    Thanks for the code snippet. From your code snippet it seems like you are handling KeyDown/PreviewKeyDown event for PdfViewer. The same code is working fine at my end as whenever the PdfViewer or its child elements have focus the shortcut key combinations will work because of the bubbling(KeyDown) and tunneling(PreviewKeyDown) routing strategy. So, could you please confirm that the subscribed events are not getting blocked for some reason?

    Also, you can verify the same with the attached sample. Please correct me if I misinterpreted anything.

    Best Regards,

    Basant

    PdfViewerShortcut.zip

  • Posted 1 July 2020, 9:28 pm EST

    Dear Basant,

    Thanks for support and reply.

    I have two more observations :

    1. If we select Zoom combo box via Tab key while traversing through the control the value of zoom combo box will be automatically set to 100 % .

      Note :

      Initially when we open PDF Viewer zoom combo box percentage is Fit To Text.

      2)Percentage value of PDF zoom combo box is not set properly for 502% , 506% and 510 %.

      If we enter these values (502,506 and 510),it will set the value to 501,505,509 respectively.

    Please let me know the solution ASAP.

  • Posted 2 July 2020, 1:06 am EST - Updated 3 October 2022, 11:51 pm EST

    Hi Utkarsha,

    > If we select Zoom combo box via Tab key while traversing through the control



    Hi the same is working fine at my end. Zoom value remains the same while traversing through Tab key. We tested it with the latest version (4.5.2020v1). Could you please provide a stripped down sample replicating the issue?



    >Percentage value of PDF zoom combo box is not set properly for 502% , 506% and 510 %



    This seems like a bug and we have escalated it to the devs (TFS ID: 443937). I will inform you when I have any update.

    Regards,

    Basant

  • Posted 3 July 2020, 1:32 am EST

    Hi Utkarsha,

    Here’s the response from devs:

    PdfViewer is an old control, we don’t actively fix bug for it anymore. If possible customer can use FlexViewer - a modern control with much more features than PdfViewer and is still maintain regularly

    We are sorry for the inconvenience. Could you replace PdfViewer with FlexViewer as devs suggested?

    Thanks

  • Posted 8 July 2020, 3:54 pm EST

    Dear Basant,

    Thanks for the update.

    I am asking question on behalf of Utkarsha.

    There are issues which are raised by our Japanese testing team.

    I am sharing the excel sheet.

    Please let me know if you don’t understand the points in the sheet.

    If yes, Please let me know how much time it will take to resolve the defects.

    BR,

    Amit Ghanekar

  • Posted 8 July 2020, 3:59 pm EST

  • Posted 8 July 2020, 9:30 pm EST

    Hi Amit,

    Thanks for sharing the detailed sheet. Please find the answers below:

    1) #120624 Other functions may be affected when the full screen is displayed.

    This issue does not seem due to the PdfViewer and might be dependent on your parent window and taskbar settings.

    With no specific settings for parent window and having taskbar in locked state I could’t observe this behavior.

    2) #120625 The tab order is invalid.

    You can prevent the Tab navigation from going on to pdf preview by using KeyboardNavigation.SetTabNavigation method inside PdfViewer Loaded event as follows:

    private void _pdfViewer_Loaded(object sender, RoutedEventArgs e)
    {
           // Stopping Tab navigation on pages
           var c1ListViewer = _pdfViewer.Template.FindName("PageList", _pdfViewer) as C1ListViewer;
           KeyboardNavigation.SetTabNavigation(c1ListViewer, KeyboardNavigationMode.None);
    }
    
    

    3) #120634 The starting focus surrounds the entire screen.

    Focus moves from parent to child elements by default while navigating through tab.

    And the most outer parent is the border of the control so it gets focused first. If required then you may change the focus to the desired element using Loaded event as follows:

    private void _pdfViewer_Loaded(object sender, RoutedEventArgs e)
    {
          var pdfViewerToolbar = _pdfViewer.Template.FindName("4_T", _pdfViewer) as C1PdfViewerToolbar;
          // Focuses the first item in toolbar when pdfViewer is loaded.
          (pdfViewerToolbar.Template.FindName("4_T", pdfViewerToolbar) as StackPanel).Children[0].Focus();
    }
    

    4) Regarding #120627 and #120633 :

    These two issues has already been replied in this thread above along with a sample. Please check them once and let us know in case we need to do something specific.

    Best Regards,

    Basant

  • Posted 16 August 2020, 10:10 pm EST

    Dear Basant,

    I have one question regarding PDF Viewer.

    1. Can we disable the Search box in existing PDF Viewer control ? If yes please send the sample code ?

    I have two questions regarding Flex viewer:

    1. You had suggested to use Flex viewer control as PDF viewer is old control. I hope it supports all the features supported in PDF viewer as we are using digital signature feature of PDF Viewer and also placing an image in PDF file. Kindly let me know about it ?

      2)I also want to know Flex viewer control support period and if there are any known issues.

    Best Regards

    Amit Ghanekar

  • Posted 18 August 2020, 12:06 am EST

    Hi Amit,

    Regarding PDFViewer question:

    Yes, you can disable the search box by using the PdfViewer’s Loaded event as follows:

    private void PdfViewerLoaded(object sender, RoutedEventArgs e)
    {
          var pdfViewerToolbar = pdfViewer.Template.FindName("4_T", pdfViewer) as C1PdfViewerToolbar;
          var findTextBox = pdfViewerToolbar.Template.FindName("Find", pdfViewerToolbar) as C1TextBoxBase;
          findTextBox.IsEnabled = false;
    }
    

    Regarding FlexViewer questions:

    1) Yes, it supports all the features of C1PdfViewer as it can also use the C1PdfDocument object. And also it provides you more access to the UI part than PdfViewer.

    Please refer to the sample attached to see how to load C1PdfDocument in C1FlexViewer.

    You can also refer to the ComponentOne Samples\WPF\v4.5.2\C1.WPF.Document\CS\PdfView sample for displaying Pdf’s in FlexViewer.

    2) FlexViewer is under active development mode and currently we don’t have any plan to put it in maintenance mode. And also there are no known issues regarding the features you are using.

    Regards,

    Basant

    PDFViewerSearchDisabled.zip

  • Posted 18 August 2020, 2:27 am EST

    Dear Basant,

    Thanks for answer.

    Sorry , I posted it wrong.

    We want the PDF Viewer Search control not visible.

    BR,

    Amit Ghanekar

  • Posted 18 August 2020, 6:03 pm EST

    Hi Amit,

    In that case, You can set the Visibility property of Find TextBox instead of IsEnabled property as follows:

    findTextBox.Visibility = Visibility.Collapsed;
    

    ~ Basant

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels