OpenBuffer v.2.0

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Viewer (v1)  /  OpenBuffer v.2.0

DynamicPDF Viewer (v1) Forum

 Nov 19 2009 8:52 AM
Hello,

It seems that DynamicPDFViewer.OpenBuffer method doesn't work in DynamicPDF Viewer 2.0.

[C#]
byte[] contents = File.ReadAllBytes(@"C:\MyDoc.pdf");
//using System.Runtime.InteropServices;
GCHandle gch = GCHandle.Alloc(contents, GCHandleType.Pinned);
IntPtr contentsIntPtr = gch.AddrOfPinnedObject();
pdfViewer.OpenBuffer(contentsIntPtr, contents.Length, "");


This code (taken from help) doesn't work (code has no effect to PDF viewer) with DynamicPDF Viewer 2.0 but worked with DynamicPDF Viewer 1.1. Any ideas? Thank you.

Note:
DynamicPDFViewer.OpenFile method works perfectly though.
 Nov 19 2009 12:27 PM
Posted by a ceTe Software moderator
Hello,

We are able to use both v 1.1 and 2.0 with the given code for opening the file from buffer data in help documentation.

Please make sure that you are using the controls correctly. Please remove all the old version dlls from your project's bin folder and delete the control from the project's tool box. Remove the references also to the control dlls. Then try adding the v2.0 control to the project and this should work for you. Also please double check your code in the application if any other part of code is causing any problem.

Thanks,
ceTe Software Support Team.
 Nov 20 2009 12:03 PM
Thank you for the quick reply but what I'm really doing is the following.

I created a very simple WinForms application with only one reference to ceTe.DynamicPDF.AxViewer.Control assembly (ceTe.DynamicPDF.AxViewer.dll is copied as a dependant one). I'm sure that the version of ceTe.DynamicPDF.AxViewer.Control.dll is 2.0 as well as of the ceTe.DynamicPDF.AxViewer.dll.

The code of the application is dead simple. It is the Form with DynamicPDFViewer control and one button. On button click the PDF file should be opened.

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            byte[] content = File.ReadAllBytes(@"ScrumInANutshell.pdf");

            int documentLength = content.Length;
            GCHandle handle = GCHandle.Alloc(content, GCHandleType.Pinned);
            IntPtr contentsIntPtr = handle.AddrOfPinnedObject();


            dynamicPDFViewerControl1.OpenBuffer(contentsIntPtr, documentLength, "");
        }
    }

I also tried to execute this code on the computer where neither the 1.1 version nor the 2.0 version of DynamicPDF viewer was not installed before(only DynamicPDFViewer.ocx 2.0 is registered before running the application). And this code doesn't work either there.

Am I missing something? Any thoughts are greatly appreciated.
 Nov 20 2009 1:33 PM
Posted by a ceTe Software moderator
Hello,

Can you please verify that you have the following import statements added in your code:

using System.Runtime.InteropServices;
using System.Configuration;
using System.Runtime.InteropServices.ComTypes;

Also please make sure you add the following lines before the button1_Click event:

[DllImport("ole32.dll")]
static extern int CreateStreamOnHGlobal(IntPtr hGlobal, bool fDeleteOnRelease, out IStream ppstm);

These should likely solve the problem for you.

Thanks,
ceTe Software Support Team
 Nov 23 2009 12:20 PM
It is not rather clear how it can resolve the problem. Just adding this code to application causes no change.

Could you please post a working sample that is corrected according to your suggestions based on my code from previous post? Thank you!
 Nov 23 2009 12:56 PM
Posted by a ceTe Software moderator
Hello,

We will do further testing with this code and we will get back to you as soon as we have our full test results.

Thanks,
ceTe Software Support Team.
 Nov 24 2009 5:22 AM
Based on your comments above the code should look like this:

using System;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Configuration; 

namespace TestViewer2_0
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        [DllImport("ole32.dll")]
        static extern int CreateStreamOnHGlobal(IntPtr hGlobal, bool fDeleteOnRelease, out IStream ppstm);
        private void button1_Click(object sender, EventArgs e)
        {
            byte[] content = File.ReadAllBytes(@"ScrumInANutshell.pdf");

            int documentLength = content.Length;
            GCHandle handle = GCHandle.Alloc(content, GCHandleType.Pinned);
            IntPtr contentsIntPtr = handle.AddrOfPinnedObject();


            dynamicPDFViewerControl1.OpenBuffer(contentsIntPtr, documentLength, "");

           
        }
    }
}

But this code doesn't invoke CreateStreamOnHGlobal function and it doesn't use any code from using System.Configuration;

Could you please provide some comments based on your solution. It seems like there is a misunderstanding here because this code doesn't work.

This issue with dynamicPDFViewerControl1.OpenBuffer function blocks one of the critical features of our application. Please help.
 Nov 24 2009 9:59 AM
Posted by a ceTe Software moderator
Hello,

We will forward this issue over to the developers to look into it further. We will post the updates with exact details about this issue as soon as we hear something from them.

Thanks,
ceTe Software Support Team.
 Dec 15 2009 9:24 AM
Posted by a ceTe Software moderator
Hello,

We did fix the issue with the OpenBuffer method. There is a small change in the code to use this method. Below is the sample code to use and it should work for you.

        byte[] contents = File.ReadAllBytes(@"C:\Temp\AllPageElements.pdf");
        dynamicPDFViewerControl1.OpenBuffer(contents, contents.Length, "");

Thanks,
ceTe Software Support Team.
 Dec 21 2009 5:15 AM
Thank you. It works now.

All times are US Eastern Standard time. The time now is 8:37 PM.