Need help correcting top margin and border for PDFViewer

1 Answer 55 Views
PdfViewer and PdfViewerNavigator
Josh Fredrickson
Top achievements
Rank 1
Josh Fredrickson asked on 26 Jul 2023, 06:50 PM

I just started using RadPDFViewer and it works well but I have two things that are driving me crazy.

  1. How do I remove the white spacing at the top of the control between the pdf and top of the control.
  2. There is a black border around the PDF itself inside the control that I would like to remove.

1 Answer, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 31 Jul 2023, 10:07 AM

Hi, Josh,

You can eliminate the border around the RadPdfViewerElement by using the following line of code: 

   this.radPdfViewer1.PdfViewerElement.DrawBorder = false;

However, it seems that the border is inside the view area that renders the document. Please correct me if I am wrong.

I have prepared a sample code snippet how to hide the illustrated border:

        public RadForm1()
        {
            InitializeComponent();
            this.radPdfViewer1.PdfViewerElement.ViewElement.PropertyChanged += ViewElement_PropertyChanged;

            this.radPdfViewer1.LoadDocument(@"C:\Users\dyordano\Desktop\Lorem ipsum dolor sit amet.pdf");
        }
        private void ViewElement_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            foreach (var el in this.radPdfViewer1.PdfViewerElement.ViewElement.Children)
            {
                RadFixedPageElement pagedElement = el as RadFixedPageElement;
                if (pagedElement != null)
                {

                    pagedElement.DrawBorder = false;
                }
            }
        }

As to the spacing, you can fit to full page as it is demonstrated in the following article:

https://docs.telerik.com/devtools/winforms/controls/pdfviewer/ui/document-modes#single-page-mode-fit-full-page 

I believe it would fit your scenario.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Josh Fredrickson
Top achievements
Rank 1
commented on 31 Jul 2023, 01:00 PM

I think the internal border will fix the issue as you showed.

I did already set the view of the dogument to page width and full page and when it first displays it always show the padding at the top of the object.

The interesting thing is when I added the PDFNavigator as a toolbar above and used those buttons to switch to full page and then back to page width that padding space went away.  I assumed it was a bug but maybe the button is doing an additional step which is resolving the issue?

I'll post later on today after I get my main tasks done whether the internal border is fixed, and thanks for your help!  I appreciate it.

Josh Fredrickson
Top achievements
Rank 1
commented on 31 Jul 2023, 03:41 PM

I couldn't get the border to go away.

I didn't see a preloaded Event in the UI for ViewElementChanged, and I wasn't sure how to manually recreate the event.  Your code was in C# but the convertor from C to VB didn't seem to work for me in the designer or in the form load event.

Still no luck with setting page width, it still has the spacing at the top.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 02 Aug 2023, 02:23 PM

Hi, Josh,

I have prepared a sample project in VB.NET for your reference. Please give it a try and see how it works on your end. Note that the project uses the latest version of the Telerik UI for WinForms suite.

Should you have further questions please let me know.

Josh Fredrickson
Top achievements
Rank 1
commented on 02 Aug 2023, 04:56 PM

That worked, thanks so much for your help!

For anyone curious the reference code in VB was as follows:


Imports System.ComponentModel
Imports Telerik.WinControls.UI

Public Class RadForm1
    Public Sub New()
        InitializeComponent()
        AddHandler Me.RadPdfViewer1.PdfViewerElement.ViewElement.PropertyChanged, AddressOf ViewElement_PropertyChanged
        AddHandler Me.RadPdfViewer1.DocumentLoaded, AddressOf RadPdfViewer1_DocumentLoaded
        Me.RadPdfViewer1.LoadDocument("..\..\Lorem ipsum dolor sit amet.pdf")
    End Sub

    Private Sub RadPdfViewer1_DocumentLoaded(sender As Object, e As EventArgs)
        Me.RadPdfViewer1.FitToWidth = True
    End Sub

    Private Sub ViewElement_PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
        For Each el In Me.RadPdfViewer1.PdfViewerElement.ViewElement.Children
            Dim pagedElement As RadFixedPageElement = TryCast(el, RadFixedPageElement)

            If pagedElement IsNot Nothing Then
                pagedElement.DrawBorder = False
            End If
        Next
    End Sub
End Class

Tags
PdfViewer and PdfViewerNavigator
Asked by
Josh Fredrickson
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or