How to check whether a pdf document is completely loaded?

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

How to check whether a pdf document is completely loaded?

Post by relapse »

Hello!

I have a new issue: opening a pdf document that includes many small graphical objects I'd like to know when the document in the viewer is completely loaded (assembled). The duration of that process can last few (!) seconds and I'd like to block some functions for that time. I suppose I could "influence" the behavior of the viewer with the use of the PXCVA_Sync parameter (opening a document with the OpenDocument method) but I don't know how literally to block the viewer (or to learn that it is blocked) until the document is loaded.



Thanks for your replies!



PS: Is there maybe an event that is fired as soon as the viewer has done with loading a pdf document?
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: How to check whether a pdf document is completely loaded

Post by Vasyl - PDF-XChange »

Hi, relapse.

Try to use the method:

Code: Select all

int g_nBlockedUI = 0;
...
yourveventhandler OnEvent(type, name..)
{
    if (type == PXCVA_OnNamedNotify)
    {
         if (name == "Global::BeginModal")
         {
              g_nBlockedUI++;
              if (g_nBlockedUI == 1)
              {
                    // disable your own UI
              }
         }
         else
         if (name == "Global::EndModal")
         {
              g_nBlockedUI--;
              if (g_nBlockedUI == 0)
              {
                   // enable your own UI
              }
         }
    }
}
HTH
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to check whether a pdf document is completely loaded

Post by relapse »

Hi, I tried your sample in my code but there were the cases as the name was "Global::BeginModal" or "Global::EndModal" only as the methods "SaveDocument" and "DoVerb" had been called. I found in the documentation in the chapter "2.2.4.1 Global" the table of the supported global named notifications and there are no notifications with those names but it functions somehow. In the case of the "DoVerb" method the event was raised calling the modal dialog "CropPages" (the UI access is anyway already blocked), in other cases ("SaveDocument") it has nothing to do with document loading process. Maybe there are some other events which I could use for my issue?


Thanks a lot!
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to check whether a pdf document is completely loaded

Post by relapse »

My statement was not correct: those two events are really fired by all relevant operations (the method "OpenDocument" is especially interesting for me). I blocked those events discarding them with the command pdfViewer.OnEvent -= PdfViewerEvents; (PdfViewerEvents is my event handler) 8) :oops: (sorry!)

I've corrected it but found out that the both events are fired almost immediately after each other (the time elapsed is too short).
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to check whether a pdf document is completely loaded

Post by relapse »

I've solved that problem in a different way from using viewer events: I've coded a method that freezes the active thread until the temp file is written:

Code: Select all

        private void WaitUntilWritten()
        {
            var oldSize = long.MinValue;
            long newSize = 0;
            IsDocWritten = false; // controls the activation of buttons
            
            while (newSize > oldSize)
            {
                Thread.Sleep(WaitTimeMilliseconds);
                oldSize = newSize;
                newSize = new FileInfo(_tempFile).Length;
            }

            IsDocWritten = true;
        }
... and I call it every time before I load a document after writing into it, so that it can't be loaded until it is completely written.
:shock:
Last edited by relapse on Thu Jun 21, 2012 7:47 am, edited 1 time in total.
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7371
Joined: Wed Mar 25, 2009 10:37 pm

Re: How to check whether a pdf document is completely loaded

Post by Paul - PDF-XChange »

Nice!

:D
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com