question

NazHim-9882 avatar image
0 Votes"
NazHim-9882 asked Castorix31 commented

issues axAcroPDF. when closing form in c#

hi all.

issues axAcroPDF. when closing form in c#

i am used axAcroPDF for show pdf files on a form. in C# windows form application.
it's working perfectly good. but when closing the form. getting error. like image at below.

141152-untitled-01.png
141008-untitled-02.png
141153-untitled-03.png
141019-untitled-04.png
141146-untitled-05.png

how can solve this?
can give me?. some code snippet.?.

with best regards
NazHim

dotnet-csharpwindows-forms
untitled-01.png (121.8 KiB)
untitled-02.png (90.1 KiB)
untitled-03.png (128.3 KiB)
untitled-04.png (9.0 KiB)
untitled-05.png (38.4 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Does it work if you remove the axAcroPDF1 = null line?

0 Votes 0 ·

@NazHim-9882 , Since your problem is related to Adobe, It is a 3rd party product. I recommend that you could ask your question in Adobe Support Community.


0 Votes 0 ·

thanks for your response.
sure. it's 3rd party software. but
it's i want to using in c#. how can do?

0 Votes 0 ·
Paul-5034 avatar image
0 Votes"
Paul-5034 answered

Just as a test if you add this to your Form1 class does the issue persist?:

protected override void OnClosed(EventArgs e) {
    axAcroPDF1.LoadFile("Empty");
}
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered

I cannot reproduce your problem (Windows 10 1909, VS 2019, any .NET version)

Maybe you can test with ATL as host (no need to add the reference for Adobe):

At beginning :

 using System.Runtime.InteropServices;

then :
(remove the space at S leep, it is a bug in this editor...)

 public partial class Form1 : Form
 {
     [DllImport("Atl.dll", SetLastError = true)]
     public static extern bool AtlAxWinInit();
    
     [DllImport("Atl.dll", SetLastError = true)]
     public static extern int AtlAxGetControl(IntPtr h, [MarshalAs(UnmanagedType.IUnknown)] out object pp);
    
     public const int WS_OVERLAPPED = 0x0;
     public const int WS_BORDER = 0x00800000;
     public const int WS_POPUP = unchecked((int)0x80000000L);
     public const int WS_CHILD = 0x40000000;
     public const int WS_MINIMIZE = 0x20000000;
     public const int WS_VISIBLE = 0x10000000;
     public const int WS_DISABLED = 0x8000000;
    
     [DllImport("User32.dll", SetLastError = true)]
     public static extern IntPtr CreateWindowEx(int dwExStyle, string lpClassName, string lpWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
    
     public Form1()
     {
         //InitializeComponent();
         this.Load += new System.EventHandler(this.Form1_Load);
     }
    
     private IntPtr hWndContainer = IntPtr.Zero;
    
     private void Form1_Load(object sender, EventArgs e)
     {
         string sFile = @"E:\Sources\AcroPDF\Welcome.pdf";
         this.ClientSize = new System.Drawing.Size(800, 600);
         if (AtlAxWinInit())
         {
             hWndContainer = CreateWindowEx(0, "AtlAxWin", sFile, WS_VISIBLE | WS_CHILD | WS_BORDER, 10, 10, ClientSize.Width -20, ClientSize.Height -20, this.Handle, (IntPtr)10, IntPtr.Zero, IntPtr.Zero);
         }
         System.Threading.Thread.S leep(500);
         CenterToScreen();
     }
 }



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

harborsiem-2671 avatar image
0 Votes"
harborsiem-2671 answered

Do a similar solution in the Form closing event. pdf is your axAcroPDF1 in the following sample.

         private void PdfHelp_FormClosing(object sender, FormClosingEventArgs e) {
             if (e.CloseReason == CloseReason.UserClosing) {
                 this.dialog.Hide();
                 e.Cancel = true;
             } else if (e.CloseReason == CloseReason.FormOwnerClosing) {

                 if (pdf != null) {
                     this.dialog.Controls.Remove(pdf);
                     pdf.Dispose();
                 }
                 ReleaseComObject();
                 this.dialog.Close();
             }
         }
    
         private void ReleaseComObject() {
             object o = null;
             if (pdf != null) {
                 o = pdf.GetOcx();
             }
             if (o != null) {
                 Marshal.FinalReleaseComObject(o);
             }
         }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NazHim-9882 avatar image
0 Votes"
NazHim-9882 answered Castorix31 commented

hi harborsiem-2671

thanks for your fast response
but bad luck

with best regards
NazHim

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Did you test the method with ATL ?
ATL usually always works when applications are correctly registered

0 Votes 0 ·

hi laurentcutey-3677
ATL means?
How..?
best regards
NazHim

0 Votes 0 ·

With the code I posted 4 days ago...

0 Votes 0 ·