This is a migrated thread and some comments may be shown as answers.

InvalidCastException when opening file

1 Answer 236 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Vladimir
Top achievements
Rank 1
Veteran
Vladimir asked on 14 Oct 2020, 01:07 PM

Hello!

 

I get exceptions when open some files using method Import() in PdfFormatProvider.

I prepared 1 such file to you for tests: http://u.pc.cd/3TlctalK

Version of libraries which I use is 2020.3.915

 

 

I noticed, that exceptions appears for files with outlines.

There is DestinationConverter object and its method ConvertFromArray where that exception appears.

 

Here is exception message:

Unable to cast object of type "Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfReal" to type "Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfName".

Here is a StackTrace:

   in Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.ExceptionHandling.ExceptionHandler.TryHandle(Exception exception)
   in Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider.ImportOverride(Stream input)
   in PdfViewer.States.AppStateExtensions.ReadDocumentForTelerik(String filePath)

 

My method:

internal static RadFixedDocument ReadDocumentForTelerik(string filePath)
{
    if (filePath == null)
        throw new ArgumentNullException(nameof(filePath));
 
    using (Stream stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
    {
        var provider = new PdfFormatProvider();
        provider.ImportSettings = PdfImportSettings.ReadOnDemand;
        return provider.Import(stream);
    }
}

 

Using:

var doc = ReadDocumentForTelerik(@"C:\Outline_Down.pdf");

 

n/a
Top achievements
Rank 1
commented on 07 Dec 2022, 08:58 AM

I found another exception 

Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfReal' to type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfInt'.

Here is StackTrace:

   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.Stack`1.Peek()
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.Parser.PostScriptReader.PushToken(IPdfPrimitive primitive)
   at Telerik.Windows.Documents.Data.StateMachine.State`1.ExecuteActionIfNotNull(Action`1 action, TArgs arguments)
   at Telerik.Windows.Documents.Data.StateMachine.StateMachine`1.GoToState(State`1 state, TArgs arguments)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.Parser.PostScriptReader.ReadAllPrimitivesToToken(IPdfImportContext context, PdfElementType tokenType)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.Parser.PostScriptReader.Read[T](IPdfImportContext context, PdfElementType tokenType)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.BaseImportContext.ReadUsedIndirectObject(CrossReferenceEntry entry)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.BaseImportContext.ReadIndirectObject(IndirectReference reference)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Converters.PrimitiveWrapperConverter.Convert(Type type, PostScriptReader reader, IPdfImportContext context, IPdfPrimitive value)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Data.PdfPropertyBase`1.PrepareValue(PostScriptReader reader, IPdfImportContext context, IPdfPrimitive value)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Data.LoadOnDemandPropertyBase`1.GetValueFromSource()
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Data.LoadOnDemandPropertyBase`1.GetValue()
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Utilities.PdfObjectsExtensions.GetInheritableProperty[T,V](ITreeNode`1 node, Func`2 getPropertyFromNodeValue, V defautValue)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Forms.FieldPropertiesImporter.InitializeSignatureFieldProperties(SignatureField signatureField)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.<>c__DisplayClass53_0.<CopyFormFieldsTo>b__0()
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.ExceptionHandling.ExecutionHandler.TryHandleExecution[E](Action operation)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPropertiesTo(PostScriptReader reader, IRadFixedDocumentImportContext context)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.ExceptionHandling.ExecutionHandler.TryHandleExecution[E](Action operation)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider.ImportOverride(Stream input)

Document has several digital signatures inside.

But with
pdfFormatProvider.ImportSettings.UseOldRendering = false 

is working. 

 

 

 

Martin
Telerik team
commented on 08 Dec 2022, 07:30 AM

Hi Janez, 

The stack trace is not sufficient to determine the reason for this exception, so in order to investigate the case we will need to examine the document causing the exception. Could you open a private ticket thread and send it to us?

I must assure you we treat all client files in a strictly confidential manner and for testing purposes only.

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 15 Oct 2020, 12:49 PM

Hi Vladimir,

Thank you for the provided feedback and document.

It seems this behavior is caused because the document contains an invalid outline (a.k.a. bookmark) destination. I logged a feature request on your behalf in our backlog to handle this import: PdfProcessing: Handle import of documents containing outlines with an invalid destination set. You can cast your vote for the implementation as well as subscribe to the task by clicking the Follow button so you can receive updates when its status changes.

In appreciation for bringing this to our attention, I updated your Telerik points.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
PDFViewer
Asked by
Vladimir
Top achievements
Rank 1
Veteran
Answers by
Martin
Telerik team
Share this question
or