I have PDF files that contains of several pages but with only 2 MB more or less.
When the RadPdfViewer loads the document a OutOfMemoryException occured.
CallStack:
Insufficient memory to continue the execution of the program.
at System.Windows.Media.Imaging.WriteableBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette)
at Telerik.Windows.Media.Imaging.RadBitmap..ctor(Int32 width, Int32 height, Int32[] pixels)
at Telerik.Windows.Documents.Fixed.UI.UIElementsHelper.CreateImageSource(ResourceKey key, ImageSource source)
at Telerik.Windows.Documents.Fixed.UI.UIElementsHelper.ImageLoader_WorkCompleted(Object sender, WorkCompletedEventArgs e)
at Telerik.Windows.Documents.Core.Utils.ResourceLoader.OnWorkCompleted(WorkCompletedEventArgs args)
at Telerik.Windows.Documents.Core.Utils.ResourceLoader.Worker_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e)
at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
10 Answers, 1 is accepted
I suggest we continue the conversation in the support ticket that you opened on the topic, as attachments are not available in the public forums.
Regards,
Petya
Telerik
I would like to hoop up to this thread since I have quite a similar problem. The PDF in question is just 253kb in size, but grows up to approx. 300MB in memory, which, in some occasions, is a dead trap for some of our users with only 2GB of memory.
If needed, I can provide the PDF in question. Otherwise: Any general suggestions or options?
Cheers,
Frank
I would like to be a bit more precise, since I have examined the problem a bit further just now.
The PDF contains a couple of large monochrome images, here is the header of one of the images from the PDF:
<</Subtype/Image /Width 3150 /Height 2175 /BitsPerComponent 1 /ColorSpace/DeviceGray /Filter/CCITTFaxDecode /DecodeParms<</K -1/EndOfBlock false/Columns 3150>>
I assume that the RadPdfViewer is rendering the images in full size using RadBitmap - while using the internal 32 Bit ARGB Format.
If I am correct about that, I would like to write a custom filter for CCITT (which should be the TIFF filter).
Questions are:
1.) Am I correct about the issue that images are rendered in full size using RadBitmap in 32Bit?
2.) Is there any chance to use RadBitmap NOT using ARGB, but e.g. monochrome?
Cheers,
Frank
Thank you for your interest in RadPdfViewer.
You are correct, RadPdfViewer uses full size 32bit bitmap to store the decoded images. Your idea is interesting and we will definitely look into the possibility of implementing it the next time we schedule some memory optimizations, so thank you for the feedback. You can track the status of the issue through this item in the public portal.
Unfortunately at this point only ARGB format is supported and this cannot be changed by replacing the CCITTFaxDecode.
Hope this answers your questions.
Kammen
Telerik
thanks for the feedback. I checked it right after my last comment and also found out that this was impossible to solve via the decoder.
Anyway, it's good to see that the issue made it to the feedback portal and I hope that matter could be solved during your developers' next RadPdfViewer roundup.
Thanks again,
Frank
Please note the Page up and page down is also not working for me. Please let me know what wrong in my code.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<telerik:RadToolBar DataContext="{Binding ElementName=pdfViewer, Path=CommandDescriptors}">
<telerik:RadButton Command="{Binding OpenCommandDescriptor.Command}" Visibility="{Binding OpenCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
<ToolTipService.ToolTip>
<TextBlock Text="Open" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=open.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadButton>
<telerik:RadButton Command="{Binding PrintCommandDescriptor.Command}" Visibility="{Binding PrintCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
<ToolTipService.ToolTip>
<TextBlock Text="Print" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=printer.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadButton>
<telerik:RadToolBarSeparator/>
<telerik:RadButton x:Name="counterClockwiseButton"
Command="{Binding RotateCounterClockwiseCommandDescriptor.Command}"
Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
<ToolTipService.ToolTip>
<TextBlock Text="Rotate counterclockwise" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=rotate-counterclockwise.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadButton>
<telerik:RadButton x:Name="clockwiseButton"
Command="{Binding RotateClockwiseCommandDescriptor.Command}"
Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
<ToolTipService.ToolTip>
<TextBlock Text="Rotate clockwise" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=rotate-clockwise.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadButton>
<telerik:RadToolBarSeparator/>
<telerik:RadButton Command="{Binding PageUpCommandDescriptor.Command}" Visibility="{Binding PageUpCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
<ToolTipService.ToolTip>
<TextBlock Text="Previous page" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=previous.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadButton>
<telerik:RadButton Command="{Binding PageDownCommandDescriptor.Command}" Visibility="{Binding PageDownCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
<ToolTipService.ToolTip>
<TextBlock Text="Next page" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=next.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadButton>
<TextBox Width="45" Margin="2" Text="{Binding FixedDocumentViewer.CurrentPageNumber, Mode=TwoWay}" HorizontalContentAlignment="Center" x:Name="tbCurrentPage" KeyDown="tbCurrentPage_KeyDown"/>
<TextBlock VerticalAlignment="Center" Margin="2" Text="/" />
<TextBlock VerticalAlignment="Center" Margin="2" Text="{Binding FixedDocumentViewer.PagesCount}" />
<telerik:RadToolBarSeparator/>
<telerik:RadButton Command="{Binding ZoomInCommandDescriptor.Command}" Visibility="{Binding ZoomInCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
<ToolTipService.ToolTip>
<TextBlock Text="Zoom in" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=zoom-in.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadButton>
<telerik:RadButton x:Name="PART_btnZoomOut" Command="{Binding ZoomOutCommandDescriptor.Command}" Visibility="{Binding ZoomOutCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="2" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsBackgroundVisible="False">
<ToolTipService.ToolTip>
<TextBlock Text="Zoom out" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=zoom-out.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadButton>
<telerik:PercentComboBox Value="{Binding ElementName=pdfViewer, Path=ScaleFactor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
RadPdfViewer="{Binding ElementName=pdfViewer}"
Margin="2">
<telerik:PercentComboBox.PercentValues>
<telerik:Percent Value="10"/>
<telerik:Percent Value="25"/>
<telerik:Percent Value="50"/>
<telerik:Percent Value="75"/>
<telerik:Percent Value="100"/>
<telerik:Percent Value="150"/>
<telerik:Percent Value="200"/>
<telerik:Percent Value="500"/>
<telerik:Percent Value="1000"/>
<telerik:Percent Value="2000"/>
</telerik:PercentComboBox.PercentValues>
</telerik:PercentComboBox>
<telerik:RadToolBarSeparator />
<telerik:RadToggleButton x:Name="fitToWidthButton"
Command="{Binding FitToWidthFixedDocumentPagesPresenterCommandDescriptor.Command}"
IsEnabled="{Binding FitToWidthFixedDocumentPagesPresenterCommandDescriptor.IsEnabled, Converter={StaticResource InvertedBooleanConverter}, Mode=TwoWay}"
IsChecked="{Binding FitToWidthFixedDocumentPagesPresenterCommandDescriptor.IsEnabled, Mode=TwoWay}"
Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
<ToolTipService.ToolTip>
<TextBlock Text="Fit to window width and enable scrolling." />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=document-fit-width.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadToggleButton>
<telerik:RadToggleButton x:Name="fitToPageButton"
Command="{Binding FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.Command}"
IsEnabled="{Binding FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.IsEnabled, Converter={StaticResource InvertedBooleanConverter}, Mode=TwoWay}"
IsChecked="{Binding FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.IsEnabled, Mode=TwoWay}"
Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
<ToolTipService.ToolTip>
<TextBlock Text="Fit one full page to window." />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=document-fit-page.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadToggleButton>
<telerik:RadToolBarSeparator />
<telerik:RadToggleButton IsChecked="{Binding FixedDocumentViewer.Mode, Mode=TwoWay, Converter={StaticResource ModeConverter}, ConverterParameter=Pan}" Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
<ToolTipService.ToolTip>
<TextBlock Text="Pan" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=hand-free.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadToggleButton>
<telerik:RadToggleButton IsChecked="{Binding FixedDocumentViewer.Mode, Mode=TwoWay, Converter={StaticResource ModeConverter}, ConverterParameter=TextSelection}" Margin="2" Padding="0" IsBackgroundVisible="False" HorizontalAlignment="Left" VerticalAlignment="Stretch">
<ToolTipService.ToolTip>
<TextBlock Text="Text Selection" />
</ToolTipService.ToolTip>
<Image Source="{telerik:IconResource IconRelativePath=text-selection.png, IconSources={StaticResource IconPaths}}" Stretch="None" />
</telerik:RadToggleButton>
</telerik:RadToolBar>
<telerik:RadPdfViewer Grid.Row="1" x:Name="pdfViewer" DocumentSource="/PdfViewer;component/SampleData/Sample.pdf" DataContext="{Binding ElementName=pdfViewer, Path=CommandDescriptors}">
<telerik:RadContextMenu.ContextMenu>
<telerik:RadContextMenu x:Name="menu">
<telerik:RadMenuItem Header="Copy" Command="{Binding CopyCommandDescriptor.Command}"
Visibility="{Binding CopyCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
<telerik:RadMenuItem Header="Select All" Command="{Binding SelectAllCommandDescriptor.Command}"
Visibility="{Binding SelectAllCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
<telerik:RadMenuItem IsSeparator="True"
Visibility="{Binding TextSelectionCommandDescriptorsGroup.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
<telerik:RadMenuItem IsCheckable="True" IsChecked="{Binding FixedDocumentViewer.Mode, Mode=TwoWay, Converter={StaticResource ModeConverter}, ConverterParameter=Pan}" Header="Pan" />
<telerik:RadMenuItem IsCheckable="True" IsChecked="{Binding FixedDocumentViewer.Mode, Mode=TwoWay, Converter={StaticResource ModeConverter}, ConverterParameter=TextSelection}" Header="Text Selection" />
<telerik:RadMenuItem IsSeparator="True"
Visibility="{Binding ViewCommandDescriptorsGroup.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
<telerik:RadMenuItem Header="Zoom In" Command="{Binding ZoomInCommandDescriptor.Command}"
Visibility="{Binding ZoomInCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
<telerik:RadMenuItem Header="Zoom Out" Command="{Binding ZoomOutCommandDescriptor.Command}"
Visibility="{Binding ZoomOutCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
<telerik:RadMenuItem IsSeparator="True" />
<telerik:RadMenuItem Header="Print" Command="{Binding PrintCommandDescriptor.Command}"
Visibility="{Binding PrintCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
<telerik:RadMenuItem Header="Find" Command="{Binding ShowFindDialogCommandDescriptor.Command}"
Visibility="{Binding ShowFindDialogCommandDescriptor.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"/>
</telerik:RadContextMenu>
</telerik:RadContextMenu.ContextMenu>
</telerik:RadPdfViewer>
</Grid>
@Md. Morshed, I checked the code you provided and couldn't find anything suspicious in it. As you said you tested the document in our demos and it is properly imported, I suppose that there is something related to the setup. However, I cannot say what it might be looking at the XAML.
You could download the source code of our examples from your account and check what is the difference in your project. The archive file containing the code is available on our website - just log in at www.telerik.com, go to Downloads and select UI for WPF. You will find a list of all the available for download files according to your license. The .zip file with the examples is called Telerik_UI_for_WPF_[version]_Demos.zip.
If you are still having issues with this, you could open a support ticket and send us the project so we can check what might cause the behavior you are experiencing.
@Bryand, at this point, we are unaware of an issue in RadPdfViewer that may cause an OutOfMemoryException in such a simple document. With our latest version (R2 2016 SP1), we introduced improvements in the memory usage of the control. Could you test the document with this version if you haven't yet? You could try if it opens in our online examples as well.
If you are still getting this exception, could you send us this document to test it locally? Please, note that the public forums allow you attaching only images and you may need to submit a support ticket where you can attach this document as a .zip file.
Regards,
Tanya
Telerik