When we render any PDF file with 'x' number of page count and try to enter page 'x+1' in telerik:CurrentPageTextBox and hit enter, it will enable the Previous Page RadButton and if we click Previous Page then it will freeze the application.
System.ArgumentOutOfRangeException: 'pageNo should be greater or equal than 1 and less or equal than 4. (Parameter 'pageNo')'
Workaround: A possible approach could be to attach to the CurrentPageTextBox` KeyDown event in order to restrict the input.
XAML:
<telerik:CurrentPageTextBox x:Name="PART_CurrentPageNumberTextBox"
KeyDown="PART_CurrentPageNumberTextBox_KeyDown"
Text="{Binding FixedDocumentViewer.CurrentPageNumber, Mode=TwoWay}"/>
private void PART_CurrentPageNumberTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
TextBox textBox = sender as TextBox;
if (textBox != null)
{
if (e.Key == System.Windows.Input.Key.Enter)
{
int pagesCount = this.pdfViewer.PagesCount;
int currentPageNumber = this.pdfViewer.CurrentPageNumber;
if (this.pdfViewer.Document != null && (currentPageNumber < 1 || currentPageNumber > pagesCount))
{
RadFixedPage currentPage = this.pdfViewer.CurrentPage;
int pageNum = this.pdfViewer.Document.Pages.IndexOf(currentPage) + 1;
this.pdfViewer.CurrentPageNumber = pageNum;
}
}
}
}
When importing a PDF document, opening the stream in using statement, and using the default constructor of the PdfDocumentSource class, an exception is thrown:
using (Stream stream = ofd.OpenFile())
{
this.pdfViewer.DocumentSource = new PdfDocumentSource(stream);
}
using (Stream stream = ofd.OpenFile())
{
PdfImportSettings importSettings = new PdfImportSettings
{
CopyStream = true
};
this.pdfViewer.DocumentSource = new PdfDocumentSource(stream, importSettings);
}
When extracting text from a composite font the ToUnicode mapping should be used but when this mapping is missing the char codes must be mapped by constructing a secondary map from fonts ordering and registry.
A possible workaround could be to register a TrueType font using the FontsRepository.RegisterFont() method:
FontsRepository.RegisterFont(new FontFamily(fontName), FontStyles.Normal, FontWeights.Normal, File.ReadAllBytes(pathToFont));
FontsRepository.TryCreateFont(new FontFamily(fontName), FontStyles.Normal, FontWeights.Normal, out FontBase font);
foreach (RadFixedPage page in document.Pages)
{
foreach (ContentElementBase contentElement in page.Content)
{
if (contentElement is TextFragment textFragment)
{
if (textFragment.Font.Name == fontName)
{
textFragment.Font = font;
}
}
}
}
According to the PDF specification (Adobe® Portable Document Format Version 1.7):
Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions width and height in user space.
The operation:
x y width height re
An invalid case:
0 - 595 -842 re
This leads to an exception thrown: System.NullReferenceException: 'Object reference not set to an instance of an object.'
The object definitions are split into several lines:
There are missing characters when importing documents containing Standard fonts with a Differences array defined in the Encoding, which contains characters that do not fit in the first 255 glyph definitions in the font. Most of these characters are the ones with an accent such as "ccaron" (č).
When the first symbol in the text string array is empty the text translation is not taken into account.
/f-0-1 1 Tf
[<>-3775<0006>15<000700080002>15<0009>]TJ
This leads to a letter misplacement (too far from each other or overlapping each other).
When importing a document with a missing state separator (e.g. linefeed) in the object stream (ObjStm) an exception is thrown: System.InvalidCastException: 'Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfDictionary' to type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfInt'.'
А possible workaround could be handling the exceptions: Handling Exceptions.
The rendering of the image is not fully parsed and the next attribute cannot be properly read.
System.InvalidCastException: 'Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfArray' to type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfInt'.'
While all the pages and components of the control are rendered on the image, the content is completely missing from it. The issue is a regression caused by the migration of the model and its async rendering introduced in R3 2020.
Workaround: Fallback to the old rendering engine:
this.pdfViewer.DefaultImportSettings.UseOldRendering = true;
PdfImportSettings settings = PdfImportSettings.ReadOnDemand;
settings.UseOldRendering = true;