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

DocumentSource strange problem

7 Answers 490 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 03 Aug 2012, 03:18 PM

Hi,

we use Telerik V2012.1.326.35 with VS2008 and we have a strange problem :(

Actually in our solution, in one of our project we added a RadPdfViewer in a XAML file. In code behind, on a RadButton click event, we call the following method :

private void loadDoc()
{
    PdfDocumentSource newDoc = new PdfDocumentSource(new Uri(@"c:\MyDir\pdf2.pdf"));
    PdfDoc.DocumentSource = newDoc;

}

I don't know why but I always received the follwing error message (see attached file).

If I move our method in a brand new solution and project, it work!!! I checked all Telerik files and they are the same in both projects.

Any thought???
Thank's

7 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 06 Aug 2012, 05:15 PM
Hello Oliver,

Did you looked at the "View Detail" for details about this exception? Sometimes this reveals more info and can be useful. If there is a stack trace with telerik components involved, please copy it and send it to us.

Other than that the only thing that comes to mind is something in the assembly references or the project settings.

If you have added all required assembly references as listed here and the project settings in the two applications are the same, please open a support ticket and attach the project illustrating the issue, so that we can test it on our end and determine the cause of the incorrect behavior.

Greetings,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Oliver
Top achievements
Rank 1
answered on 06 Aug 2012, 05:27 PM
Hi Iva,

System.NullReferenceException was unhandled
  Message="La référence d'objet n'est pas définie à une instance d'un objet."
  Source="Telerik.Windows.Controls.FixedDocumentViewers"
  StackTrace:
       à Telerik.Windows.Documents.Fixed.FixedDocumentStreamSource.<>c__DisplayClass8.<LoadDocument>b__6() dans c:\TB\105\WPF_Scrum\Release_WPF\Sources\Development\Documents\Fixed\FixedDocumentViewers\Fixed\FixedDocumentStreamSource.cs:ligne 118
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.runTryCode(Object userData)
       à System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Thank's
0
Iva Toteva
Telerik team
answered on 10 Aug 2012, 07:49 AM
Hello Oliver,

Unfortunately, we are still not able to track the cause of the issue from the information you have provided.

Please, open a support ticket and attach your project, so that we can assist you further.

Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Filip
Top achievements
Rank 1
answered on 16 Aug 2012, 02:43 PM
Hello Support,

I do not know if it's the same problem but do notice that when using the pdfViewer from within a wpf project everything works fine.

But when I use a ElementHost to host the pdfViewer I can not load any pdf document.

Even using the UI of the component generates a crash. I think it's something to do with threads / dispatcher.

Error
{"Object reference not set to an instance of an object."}

"   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Utils.Helper.get_Dispatcher() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Fixed\Core\FormatProviders\Pdf\Utils\Helper.cs:line 147".

I have used the latest trial , and in production we have version 2011.3.1205.40. And also there I encounter the problem.

The Code

    public partial class Form1 : Form
    {
        private readonly RadPdfViewer _pdfViewer;

        private readonly WpfWrapper _pdfWpfWrapper;

        public Form1()
        {
            InitializeComponent();

            _pdfViewer = new RadPdfViewer { Name = "_pdfViewer" };

            var document = new PdfDocumentSource(new Uri("c:\\1.pdf")).Document;

            _pdfViewer.Document = document;

            //var textBox = new TextBox();

            _pdfWpfWrapper = new WpfWrapper(_pdfViewer)
            {   BackColor = Color.FloralWhite,
                Location = new Point(0, 0),
                Width = this.Width - 10,
                Name = @"_pdfWpfWrapper",
                TabStop = true,
                TabIndex = 0,
                Text = @"_pdfWpfWrapper",
                Dock = DockStyle.Fill
            };

            Controls.Add(_pdfWpfWrapper);
        }
    }

    public class WpfWrapper : System.Windows.Forms.Integration.ElementHost
    {
        public static Dispatcher Dispatcher { get; private set; }

        public WpfWrapper(FrameworkElement wrapped)
        {
            Location = new System.Drawing.Point(0, 0);

            Name = "elementHost";

            BackColorTransparent = true;

            TabStop = false; //artf53800

            Child = wrapped;

            if (Dispatcher == null)
            {
                Dispatcher = Child.Dispatcher;
            }
        }

        // Fix: Keyboard events are not transfered to the winforms host
        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message m, System.Windows.Forms.Keys keyData)
        {
            bool processed = base.ProcessCmdKey(ref m, keyData);

            if (!processed)
            {
                SendMessage(Parent.Handle, m.Msg, m.WParam, m.LParam);
            }

            return processed;
        }
    }






0
Kammen
Telerik team
answered on 20 Aug 2012, 08:40 AM
Hello Filip,

There is one additional thing to do in order to make RadPdfViewer work in a WinForms application: you should ensure that the Application.Current property is initialized before the user control is initialized, for example by adding this code in the constructor of the user control:

public PdfViewerControl()  
{  
   if (Application.Current == null)  
   {  
      new Application();  
   }  
   InitializeComponent();  
}

I hope this helps.
 
Regards,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Filip
Top achievements
Rank 1
answered on 21 Aug 2012, 07:35 AM
Kammen,

Yes this works perfectly !

Thanks.
0
Matthew
Top achievements
Rank 1
answered on 16 May 2013, 04:10 AM
I faced a similar problem with document sourcing and this thread helped me a lot. Thanks to all you guys.
__________________
Tags
PDFViewer
Asked by
Oliver
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Oliver
Top achievements
Rank 1
Filip
Top achievements
Rank 1
Kammen
Telerik team
Matthew
Top achievements
Rank 1
Share this question
or