reliak / moonpdf

Contains a WPF control for displaying PDF files and a sample PDF viewer, that uses this control
GNU General Public License v3.0
188 stars 90 forks source link

NullReferenceException when i call OpenFile method #19

Open jlpuma24 opened 6 years ago

jlpuma24 commented 6 years ago

Hi, a have a couples of issues regarding the OpenFile method calls, i create my component like this:

image

After that i call this method:

image

When the route of PDF on my computer and gives me NullReferenceException

Can you help me with this? Thanks!

jlpuma24 commented 6 years ago

@reliak can you help me please? Thanks a lot

Minimum006 commented 5 years ago

I guess you have opened your pdf file in Loaded event. Maybe you should use this.UpdateLayout() to force UI to update, so visualtree can find the scrollview which is the templatechild of inner panel

seahandsome commented 4 years ago

@jlpuma24 Hi, how did you solve this problem?

focussing commented 4 years ago

Hi, I have the same issue overhere, it already took me hours.

My application consists of tabPages, let's say a Base tab and a Manual tab for displaying PDF manual files. The first time I switch from BaseTab to ManualTab I get the exception, but when I switch back to BastTab and to ManualTab a second time, it displays the PDF beautifully!

Visual Studio 2015, .NET 4.5.2, WPF application.

Any idea what I am doing wrong?

focussing commented 4 years ago

@reliak did you encounter this also?

focussing commented 4 years ago

@Minimum006 adding this.UpdateLayout() just before calling the OpenFile method does not help...

focussing commented 4 years ago

For the record; this is the error message. System.NullReferenceException: Object reference not set to an instance of an object. at MoonPdfLib.ContinuousMoonPdfPanel.Load(IPdfSource source, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\ContinuousMoonPdfPanel.xaml.cs:line 65 at MoonPdfLib.MoonPdfPanel.LoadPdf(IPdfSource source, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\MoonPdfPanel.xaml.cs:line 232 at MoonPdfLib.MoonPdfPanel.Open(IPdfSource source, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\MoonPdfPanel.xaml.cs:line 207 at MoonPdfLib.MoonPdfPanel.OpenFile(String pdfFilename, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\MoonPdfPanel.xaml.cs:line 189

focussing commented 4 years ago

@Minimum006 I see in the debugger that the following code is causing the exception; this.virtualPanel and this.scrollViewer are null the first time this is called.


        {
            this.virtualPanel = VisualTreeHelperEx.FindChild<CustomVirtualizingPanel>(this);
            this.scrollViewer = VisualTreeHelperEx.FindChild<ScrollViewer>(this);
            this.virtualPanel.PageRowBounds = this.parent.PageRowBounds.Select(f => f.SizeIncludingOffset).ToArray();
            this.imageProvider = new PdfImageProvider(source, this.parent.TotalPages,
                                        new PageDisplaySettings(this.parent.GetPagesPerRow(), this.parent.ViewType, this.parent.HorizontalMargin, this.parent.Rotation),
                                        password: password);

            if (this.parent.ZoomType == ZoomType.Fixed)
                this.CreateNewItemsSource();
            else if (this.parent.ZoomType == ZoomType.FitToHeight)
                this.ZoomToHeight();
            else if (this.parent.ZoomType == ZoomType.FitToWidth)
                this.ZoomToWidth();

            if (this.scrollViewer != null)
            {
                this.scrollViewer.Visibility = System.Windows.Visibility.Visible;
                this.scrollViewer.ScrollToTop();
            }
        }
netcore-jroger commented 4 years ago

The author has not been active on github for several years, modify it yourself.

focussing commented 4 years ago

@netcore-jroger thank you for your message; I am already digging into it; not a clue yet where to fix it

netcore-jroger commented 4 years ago

@focussing You can look at the example. I used this component many years ago but did not encounter your problem.But I have no environment now

salzschneider commented 3 years ago

Hi,

I got this error message when I called the TogglePageDisplay function. The value of the PageRowDisplay attrib in the xaml was SinglePageRow. I changed the PageRowDisplay to ContinuousPageRows and removed the TogglePageDisplay call. It's just a workaround, of course, but it's working for me.

PineappleUFO commented 1 year ago

Hi, May help someone :) ran into the same problem, if you want to use PageRowDisplay="ContinuiusPageRows" and you get an error when opening the file, check that you don't use Visible="Collapsed" on the MoonPdfPanel element, use Hidden