PDFViewer WPF

Posted by: mayur.purandare on 28 August 2019, 8:12 pm EST

    • Post Options:
    • Link

    Posted 28 August 2019, 8:12 pm EST

    HI,

    Query 1:

    Is there any way to bind stream as input to PDFViewer. Is there any property to which i can bind my stream data to display contents.

    I know about source property but takes uri and not stream data. I don’t have URI becz i am preparing data and want to view it.

    Instead of using LoadDocument method as we want to follow MVVM pattern.

    Query 2:

    I would like to show the C1PDFViewer Toolbar, but hide the save button.

    I have instantiated the viewer in XAML as below:

    <c1:C1PdfViewer Name=“C1PDFViewerControl” />

    When i look to access the properties in C# code behind, all i can find is C1PDFViewerControl.ToolbarVisibility which either shows or hides the whole toolbar.

    Is there a way to show the toolbar but hide the save button in C# please?

  • Posted 29 August 2019, 7:30 pm EST

    Hello Mayur,

    Sorry to mention that it is not possible to load stream into PDFViewer through the property. You need to use the “LoadDocument” method as given in your other query:

    https://www.grapecity.com/forums/wpf-edition/pdf-viewer_1

    Is there a way to show the toolbar but hide the save button in C# please?

    Yes, you can use the following code to hide the save button.

    
     public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
            {
                if (depObj != null)
                {
                    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                    {
                        DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                        if (child != null && child is T)
                        {
                            yield return (T)child;
                        }
    
                        foreach (T childOfChild in FindVisualChildren<T>(child))
                        {
                            yield return childOfChild;
                        }
                    }
                }
            }
            int i = 0;
            private void Window_ContentRendered(object sender, EventArgs e)
            {
                foreach (StackPanel item in FindVisualChildren<StackPanel>(test))
                {
                    if(i==0)
                    item.Children[1].Visibility = Visibility.Collapsed;
    
                    i++;
                }
            }
    
    

    Also, please refer to the attached sample for implementing the same.

    Thanks.

    PDFViewer.zip

  • Posted 22 September 2019, 5:57 pm EST

    Hello, Thanks for the reply.

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

    Is there any way to bind short cut keys to buttons. For example next page, last page , previous page, etc.

  • Posted 22 September 2019, 9:16 pm EST

    Hello,

    You can use the KeyDown event of the viewer to achieve your requirement as follow:

     public MainWindow()
            {
                InitializeComponent();
                test.PreviewKeyUp += Test_PreviewKeyUp;            
            }
    
            private void Test_PreviewKeyUp(object sender, KeyEventArgs e)
            {
                if(e.Key== Key.F7)
                {
                    test.OpenCommand.Execute(test);
                }
            }
    
    

    Hope it helps.

    Thanks,

    Mohit

  • Posted 3 October 2019, 9:40 pm EST

    Hi,

    Thank you.

    Is there any sample application which I can refer to implement short cut keys.

    If yes please share it with me.

  • Posted 3 October 2019, 10:13 pm EST

    Hello,

    Please refer to the attached application.

    Thanks,

    Mohit

    PDfViewertest (2).zip

  • Posted 11 October 2019, 6:16 pm EST

    Hello,

    Thanks for the solution.

    I have implemented it successfully.

    Now I have 2 short cut keys for different function. Could you please let me know how to achieve this.

    When I pressed Alt + S then find textbox should be focused so that i can type string and search it.

    Similarly when I pressed Shift+Alt+P then PageNumber textbox should be focused so that i can type any page no and press enter.

    How to achieve this, is it possible to set focus on these textboxes.

  • Posted 14 October 2019, 4:26 pm EST

    Hello,

    Please use the following lines of code to achieve your requirement:

    
    public static T FindChild<T>(DependencyObject parent, string childName)
        where T : DependencyObject
        {
          // Confirm parent and childName are valid. 
          if (parent == null) return null;
          T foundChild = null;
          int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
          for (int i = 0; i < childrenCount; i++)
          {
            var child = VisualTreeHelper.GetChild(parent, i);
            // If the child is not of the request child type child
            T childType = child as T;
            if (childType == null)
            {
              // recursively drill down the tree
              foundChild = FindChild<T>(child, childName);
              // If the child is found, break so we do not overwrite the found child. 
              if (foundChild != null) break;
            }
            else if (!string.IsNullOrEmpty(childName))
            {
              var frameworkElement = child as FrameworkElement;
              // If the child's name is set for search
              if (frameworkElement != null && frameworkElement.Name == childName)
              {
                // if the child's name is of the request name
                foundChild = (T)child;
                break;
              }
            }
            else
            {
              // child element found.
              foundChild = (T)child;
              break;
            }
          }
          return foundChild;
        }
        private void Test_PreviewKeyUp(object sender, KeyEventArgs e)
            {
          if ( Keyboard.IsKeyDown(Key.RightAlt) && e.SystemKey == Key.S)
              {
            C1.WPF.C1TextBoxBase item = FindChild<C1.WPF.C1TextBoxBase>(Viewer1, "Find");
            item.Focus();
               }
    
              else if ( Keyboard.IsKeyDown(Key.RightAlt) && e.SystemKey == Key.P)
          {
           
              C1.WPF.C1TextBoxBase item = FindChild<C1.WPF.C1TextBoxBase>(Viewer1, "PageNumber");
              item.Focus();
           
              
          }
            }
        }
    
    

    Thanks,

    Mohit

  • Posted 4 December 2019, 9:29 pm EST

    Dear Team,

    For C1PdfViewer, when I am keeping view mode as OnePage or FitWidth, it is getting displayed properly but One page or FitWidth buttons are not check.

    When the display setting of PDF Preview is default(Fit Width), this icon(Fit Width) is not selected.

  • Posted 8 December 2019, 5:33 pm EST

    Hello,

    Please change the ViewMode in the ContentRendered event of the MainWindow to achieve your requirements.

    private void Window_ContentRendered(object sender, EventArgs e)
            {
                pdfViewer.ViewMode = C1.WPF.PdfViewer.ViewMode.OnePage;
             
            }
    

    Thanks,

    Mohit

  • Posted 8 December 2019, 8:53 pm EST

    Thanks for the reply.

    It is working as per requirement.

    I have one more issue in this view.

    When the combo box/edit control(Search box or page no. control) of PDF Preview is selected and the short cut key is pressed, the page is moved.

    When editable controls are focused, short cut keys should not be allowed.

  • Posted 9 December 2019, 3:50 pm EST

    Hello,

    Please use the following modified method:

    
     private void Test_PreviewKeyUp(object sender, KeyEventArgs e)
            {
                C1.WPF.C1TextBoxBase find = FindChild<C1.WPF.C1TextBoxBase>(test, "Find");
                C1.WPF.C1TextBoxBase pageNumber = FindChild<C1.WPF.C1TextBoxBase>(test, "PageNumber");
    
                if (Keyboard.IsKeyDown(Key.RightAlt) && e.SystemKey == Key.S)
                    {
                    if(!pageNumber.IsFocused)
                    find.Focus();
                    }
    
                    else if (Keyboard.IsKeyDown(Key.RightAlt) && e.SystemKey == Key.P)
                    {
    
                    if (!find.IsFocused)
                        pageNumber.Focus();
                    }
            }
    
    

    Hope it helps.

    Thanks,

    Mohit

  • Posted 5 March 2020, 9:50 pm EST - Updated 3 October 2022, 10:53 pm EST

    Hello,

    I have created one C1PdfDocument object to create PDF repots.

    I am using same object for displaying PDF preview of same report.

    While displaying PDF preview sometimes lines in grid are bit distorted but correct in actual PDF file if opened via Acrobat Reader.

    Please find an attachment for same.

  • Posted 5 March 2020, 9:54 pm EST

    Please find an attachment for report.

  • Posted 5 March 2020, 10:00 pm EST

  • Posted 8 March 2020, 5:36 pm EST

    Hello,

    It is related to the Font problem. Could you please share which Font are you using at your end. At my end “‚l‚rƒSƒVƒbƒN” font is showed but I can’t find the same name of Font on the web.

    Thanks,

    Mohit

  • Posted 8 March 2020, 6:34 pm EST

    Hello,

    We are using “MS Gothic” font with font style as Regular.

    Font font = new Font(“MS Gothic”, 9, FontStyle.Regular);

  • Posted 10 March 2020, 9:39 pm EST

    Hello,

    Is there any update on this.

  • Posted 11 March 2020, 9:02 pm EST

    Hello,

    Could you please share the code which you are using to generate the PDF. As I have unable to open the PDF using Adobe Reader. I also have MsGothic font on my system. There is something problem in the generated PDF. Please share the code so that I can look into the issue in more detail.

    Thanks,

    Mohit

  • Posted 16 March 2020, 4:04 pm EST

    Hello,

    I am using adobe reader only to open this file.

    I may not be able to share the whole code. But one observation is when we are changing the current UI culture to Japanese language, this issue is coming, for English UI culture this issue is not coming.

  • Posted 17 March 2020, 10:17 pm EST

    Hello,

    Could you please modify the attached application at that I can replicate the issue at my end. We can’t send the issue to our development team without replicating the issue at our end. Also, It is very hard for a developer also to investigate the issue without this.

    Thanks,

    Mohit

    PdfAcroform.zip

  • Posted 29 March 2020, 1:42 am EST

    Dear Team,

    Is there any work going on above issue.

    Is there any update on this.

  • Posted 29 March 2020, 6:56 pm EST

    Hello Mayur,

    I had sent you the application in my last reply so that you can modify the sample at your end and give back to me to replicate the issue at my end.

    Could you please provide the sample so that we can work on this asap.

    Thanks,

    Mohit

Need extra support?

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

Learn More

Forum Channels