moonpdf
moonpdf copied to clipboard
NullReferenceException when i call OpenFile method
Hi, a have a couples of issues regarding the OpenFile method calls, i create my component like this:
After that i call this method:
When the route of PDF on my computer and gives me NullReferenceException
Can you help me with this? Thanks!
@reliak can you help me please? Thanks a lot
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
@jlpuma24 Hi, how did you solve this problem?
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?
@reliak did you encounter this also?
@Minimum006 adding this.UpdateLayout() just before calling the OpenFile method does not help...
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
@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();
}
}
The author has not been active on github for several years, modify it yourself.
@netcore-jroger thank you for your message; I am already digging into it; not a clue yet where to fix it
@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
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.
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