PDF Viewer

Posted by: mayur.purandare on 28 August 2019, 10:15 pm EST

    • Post Options:
    • Link

    Posted 28 August 2019, 10:15 pm EST

    I have created one C1PdfDocument Object to create pdf files.

    Now I am applying different settings to C1PdfDocument object to create customized pdf file like image, digital signature etc.

    I want to view this file before creation, because to verify how file looks after applying different settings.

    I came across PDFViewer control to view pdf file but it accepts file path means only created file can be viewed in that control.

    Is there any way to show C1PdfDocument object data in that PDFViewer window without creating file.

    Or is there any control available to fulfill my requirement?

  • Posted 29 August 2019, 3:58 pm EST

    Hello,

    You can use the LoadDocument method of PDFViewer which load the Pdf from the stream. Please refer to the following documentation link:

    https://help.grapecity.com/componentone/NetHelp/c1pdfviewerwpf/webframe.html#C1.WPF.PdfViewer.4~C1.WPF.PdfViewer.C1PdfViewer~LoadDocument(Stream,String).html

    Hope it helps.

    Thanks.

  • Posted 2 September 2019, 3:17 pm EST

    Yes. I know I can do it with LoadDocument Method.

    But my query is something different.

    I want to view the file before creation. I want to view C1PdfDocument Object in PDFViewer.

  • Posted 10 September 2019, 10:30 pm EST

    Hello,

    Sorry for the delay!

    You can load the stream into PDFViewer using LoadDocument method. Please refer to the following lines of code:

    
     C1PdfDocument pdf = new C1.WPF.Pdf.C1PdfDocument();
                System.Windows.Rect rect = pdf.PageRectangle;
                rect.Inflate(-72, -72);
               Font font = new Font("Arial", 12);
                pdf.DrawString("Hello World!", font,Color.FromRgb(0,0,0), rect);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                pdf.Save(ms);
                ms.Position = 0;
                Viewer1.LoadDocument(ms);
    
    

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

    Thanks,

    PDfViewertest.zip

  • Posted 29 March 2020, 6:16 pm EST

    Dear Team…

    I am using PDF viewer control to display PDF preview. In PDF Preview toolbar, ZoomInZoomOut combo box is present. In this combo box Fit Width to 800% values are present.

    When we click on Combo box drop down items from Fit width to 400% is displayed by default, but for only one remaining item 800% scrollbar is displayed.

    So is it possible to change default view such as fit with to 800% is displayed by default and no scrollbar is displayed.

    I tried to increase Dropdown height, but it is not working.

  • Posted 30 March 2020, 5:41 pm EST

    Hello,

    You can use the following lines of code to achieve your requirement:

    
      private void MainWindow_ContentRendered(object sender, EventArgs e)
            {
                C1.WPF.C1DropDown item = FindChild<C1.WPF.C1DropDown>(Viewer1, "DropDown");
                item.MaxDropDownHeight = 250;
            }
    
            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;
            }
    

    Thanks,

    Mohit

  • Posted 1 April 2020, 9:10 pm EST

    Thanks for the reply.

    It is working as expected.

    If we set any invalid value in ZoomInZoomOut box, then value automatically becomes 100. But if we set blank value and press enter 100 is not displayed. nothing is displayed.

    Is it PDF preview controls specification, that there is no impact when user sets blank value and press enter.

  • Posted 2 April 2020, 9:17 pm EST

    Hello,

    Is it PDF preview controls specification, that there is no impact when user sets blank value and press enter

    Currently, it is design behavior. Could you please share your requirement when user set the blank.

    Thanks,

  • Posted 3 April 2020, 2:16 am EST

    Dear Team,

    My requirement is similar to invalid value.

    Means we consider blank value as invalid value and when user sets blank value, it should change automatically to 100% as similar to invalid value case.

  • Posted 5 April 2020, 6:51 pm EST

    Hello,

    You can use the following lines of code:

    
     private void MainWindow_ContentRendered(object sender, EventArgs e)
            {
                C1.WPF.C1DropDown item = FindChild<C1.WPF.C1DropDown>(Viewer1, "DropDown");
                item.MaxDropDownHeight = 250;
                
    
                item.LostFocus += Item_LostFocus;
                       }
    
            
    
         
    
            private void Item_LostFocus(object sender, RoutedEventArgs e)
            {
               
                    C1.WPF.C1DropDown item = (C1.WPF.C1DropDown)sender;
                if(item.IsDropDownOpen!=true)
                {
                    foreach (TextBlock tb in FindVisualChildren<TextBlock>(item))
                    {
                        if (tb.Text == "" && Viewer1.Zoom != 1)
                        {
                            Viewer1.Zoom = 1;
    
    
                        }
                        break;
    
                    }
                }
                
                    
            }
    
         
            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;
                        }
                    }
                }
            }
            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;
            }
    
    

    Thanks,

    Mohit

  • Posted 7 April 2020, 6:16 pm EST

    Dear Team,

    I tried to use above code.

    It is changing blank value to 100% only when previous value is not 100%.

    Now if I keep zoom percentage as 100% and delete it to make blank and do lost focus then 100 is not displayed , it is still blank.

  • Posted 8 April 2020, 1:38 am EST

    Hello,

    Please try with the following lines of code:

    foreach (TextBlock tb in FindVisualChildren<TextBlock>(item))
                   {
                       if (tb.Text == "" )
                       {
                           
                           Viewer1.Zoom = 2;
                           Viewer1.Zoom = 1;
    
    
                       }
                       break;
    
                   }
    

    Thanks,

    Mohit

Need extra support?

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

Learn More

Forum Channels