We are using WPF with Prism, MEF, and Telerik controls (PdfViewer and GridView, version 2017.2.503.45). Our application loads multiple tab views dynamically using the MVVM pattern. Each view contains multiple Telerik controls, and their data is bound from the ViewModel.
The issue we are facing is that when a tab is closed, the Telerik controls still hold references to the associated ViewModel, preventing the memory from being released.
We have tried the following approaches while closing the tab:
RadPdfViewer.DataContext = null;
RadPdfViewer = null;
RadGridView.DataContext = null;
RadGridView = null;
We also tried disposing of the Telerik controls, but the memory is still retained by them.
We have also defined the PdfViewer in XAML, but no PDF file was ever loaded into it from the UI. However, even in this case, the XAML view is not being disposed when the tab is closed, and the PdfViewer still holds a reference to the view.
Could you please help us identify how to properly release memory and ensure the controls?
Hi,
I have this code, thats not working like this.
Because of the DataContext, the DocumentSource wont work, because it needs obviously a different DataContext.
But I need this DataContext for the ContextMenu to work.
Is there a way I can have both? A working context menu and also bind the DocumentSource?
Greetings
Benedikt
<telerik:RadPdfViewerToolBar
Grid.Row="1"
x:Name="pdfViewerToolBarZeichnungen"
Margin="0 5 0 0"
RadPdfViewer="{Binding ElementName=pdfViewerZeichnungen}"
HasSaveButton="{DynamicResource SonderRechtPDFsSpeichernErlaubt}"
HasSignatureButton="False"
HasPercentComboBox="False"
HasPrintButton="{DynamicResource SonderRechtPDFsSpeichernErlaubt}"
/>
<telerik:RadPdfViewer
Grid.Row="2"
x:Name="pdfViewerZeichnungen"
DocumentSource="{Binding SelDatei.FilePath, Converter={StaticResource PdfDocumentSourceValueConverter}}"
DataContext="{Binding CommandDescriptors, ElementName=pdfViewerZeichnungen}"
telerik:RadPdfViewerAttachedComponents.RegisterFindDialog="True"
telerik:RadPdfViewerAttachedComponents.RegisterContextMenu="True"
Mode="TextSelection"
>
public static void Print(List<string> files)
{
using (MemoryStream stream = new MemoryStream())
{
using (PdfStreamWriter fileWriter = new PdfStreamWriter(stream, leaveStreamOpen: true))
{
foreach (string path in files)
{
using (PdfFileSource fileSource = new PdfFileSource(new MemoryStream(File.ReadAllBytes(path))))
{
for (int i = 0; i < fileSource.Pages.Length; i++)
{
PdfPageSource sourcePage = fileSource.Pages[i];
using (PdfPageStreamWriter resultPage = fileWriter.BeginPage(sourcePage.Size))
{
// set content
resultPage.WriteContent(sourcePage);
}
}
}
}
}
var pdfViewer = new RadPdfViewer();
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument document = provider.Import(stream);
pdfViewer.Document = document;
var printdlg = new PrintDialog();
printdlg.UserPageRangeEnabled = true;
printdlg.SelectedPagesEnabled = true;
if (printdlg.ShowDialog() == true)
{
var printSettings = new PrintSettings(Path.GetFileNameWithoutExtension("file"), false);
pdfViewer.Print(printdlg, printSettings);
}
}
}
I have a PDF file that's been imported into a MemoryStream object and now I need to display it using the Telerik UI for WPF pdfViewer control. The existing documentation says that you can create a PdfDocumentSource object and bind the pdfViewer.DocumentSource to that. However, either PdfDocumentSource no longer exists, or I can't figure out what the correct Namespace is.
I'm using TelerikUI for WPF v2024 Q2. However changelogs for 2020 (https://docs.telerik.com/devtools/wpf/controls/radpdfviewer/changes-and-backward-compatibility/backward-compatibility) say that:
Changed
Obsolete constructors of Telerik.Windows.Documents.Fixed.PdfDocumentSource:
PdfDocumentSource(Uri uri, FormatProviderSettings settings)
PdfDocumentSource(Stream stream, FormatProviderSettings settings)
What to do now
Use the overloads that accept Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.PdfImportSettings instead.
I've also read that there is some kind of merge going on trying to replace the previous PDF code with Telerik.Windows.Documents.Fixed . In any case, I can't seem to figure out how to go from a MemoryStream to something that the pdfViewer.DocumentSource likes.
Can anyone help with a very basic code sample to take a PDF as a memorystream and create something that pdfView.DocumentSource will accept? Thank you!
Hey,
as in the titel is there a event or workaround to know if a userer startet to type inside a pdf text field. I just need it to set a bool true to inform the user that there is a possibility to lose data.
Thanks
Dominik
As in the title it doesnt work so the movement on the document isnt great.
Thanks for the help
Dominik
As in the title some charactes are getting not displayed in some pdfs.
If I import this pdf: https://jmp.sh/s/mdWM2qNDL2Oi6Yd825s0
Im getting this result its right if you click inside the field but its not getting displayed correct when not inside the field
Maybe its something with the font, thats the only thing i could think of.
Thanks for the help
Dominik
Hey im using the telerik PercentComboBox and i want to change language of the FitToPage and FitToWidthto be displayed in german.
<telerik:PercentComboBox DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type local:DialogControl}}}"
Value="{Binding ScaleFactor,ElementName=pdfViewer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
RadPdfViewer="{Binding ElementName=pdfViewer}" ShowFitToWidth="True" ShowFitToPage="True"
telerik:Windows11ThemeSizeHelper.EnableDynamicAnimation="True" Language="de-DE">
<telerik:PercentComboBox.PercentValues>
<telerik:Percent Value="200"/>
<telerik:Percent Value="150"/>
<telerik:Percent Value="125"/>
<telerik:Percent Value="110"/>
<telerik:Percent Value="100"/>
<telerik:Percent Value="90"/>
<telerik:Percent Value="75"/>
<telerik:Percent Value="50"/>
<telerik:Percent Value="30"/>
</telerik:PercentComboBox.PercentValues>
</telerik:PercentComboBox>
Hope there is a way. Thanks
Dominik
Hey,
I have set my TextField to ReadOnly but the RadPdfViewer doesnt react to it. Im getting a pdf File that im importing using the telerik PdfFormatProvider after that im trying to set some of the fields to readOnly like this:
if (formField is TextBoxField textBox) { if (field is not null) { textBox.Value = field.ViewValue(viewMode); if (field.VarType != 0) formField.IsReadOnly = true; } }
Im sure its setting it because if i export it to a pdf the fields are set to ReadOnly but not in the Telerik PdfViewer
Thanks
Dominik