PDF Add Rectangle in viewer

2 posts, 0 answers
  1. Alexandru
    Alexandru avatar
    1 posts
    Member since:
    Oct 2014

    Posted 14 Oct 2014 Link to this post

    Hello,

    How can i add a rectangle (or a button) in the PDF viewer, only on the first page?

    Thank you
  2. Dess
    Admin
    Dess avatar
    1605 posts

    Posted 17 Oct 2014 Link to this post

    Hello Alexandru,

    Thank you for writing.

    The appropriate solution that I can suggest is to add a RadButton to the Form.Controls collection. However, you need to specify the RadButton.Location to match the RadPdfViewer location. Initially, the button will not be visible. When a document is loaded in the RadPdfViewer, the RadButton.Visible property will be set to true. Changing the pages via the vertical scroll bar will force the button to be hidden again if the current page is not the first one. Here is a sample implementation:
    RadButton btn = new RadButton();
     
    public Form1()
    {
        InitializeComponent();
     
        this.radPdfViewer1.DocumentLoaded += radPdfViewer1_DocumentLoaded;
        this.radPdfViewer1.PdfViewerElement.VScrollBar.ValueChanged += VScrollBar_ValueChanged;
       
        btn.Text = "Click";
        
        btn.Location = new Point(50, 50);
     
        btn.Visible = false;
        this.Controls.Add(btn);
        this.Controls.SetChildIndex(btn, 0);
    }
     
    private void VScrollBar_ValueChanged(object sender, EventArgs e)
    {
        if (this.radPdfViewer1.PdfViewerElement.Document.Pages.Count > 0 &&
            this.radPdfViewer1.PdfViewerElement.CurrentPage ==
            this.radPdfViewer1.PdfViewerElement.Document.Pages.First())
        {
            btn.Visible = true;
        }
        else
        {
            btn.Visible = false;
        }
    }
     
    private void radPdfViewer1_DocumentLoaded(object sender, EventArgs e)
    {
        btn.Visible = true;
    }

    Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it on a way which suits your requirement best.

    I hope this information helps. Should you have further questions, I would be glad to help.

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

     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top