Implementing Autosave functionality.

Q: I was testing my autosave functionality when I discovered the
following
problem: I lose my security settings!

This is my code for the autosave function (more or less):

// In C++
PDFDoc new_doc;
if( thisdoc->GetSecurityHandler() ) {
  new_doc.SetSecurityHandler(thisdoc->GetSecurityHandler()->Clone() );
}

SDF::Doc* new_cos_doc = new_doc.GetSDFDoc();
Obj* new_root = new_cos_doc->ImportObj(thisdoc->GetTrailer()-

Get("Root")->second, true);

new_cos_doc->GetTrailer()->Put("Root", new_root);
new_doc.Save((char*)ansifname, 0, NULL);

Basically, what I want is an exact clone of the document I'm holding
in
memory. I can't just save thisdoc to another filename because PDFNet
than uses that file instead of the original file. This is a problem
because I can't delete my autosave file if I want to. Also, thisdoc
gets
flagged as unchanged so my application won't ask to save it at exit.

I know I can detect if thisdoc's securityhandler is our custom handler
by calling GetHandlerDocName() but I also need to copy paswords and
permissions from the original handler. I would have thought Clone()
would handle this, but that's not the case.

I'm probably doing something stupid here, because of my lack of
understanding this security stuff. Could you help me out please?
------
A: I believe that the problem is that you are not copying the ID entry
from the source document which is used to uniquely identify the
document and is used by the security handler. But it could also be
something else.

Please keep in mind that using the above approach you will also loose
PDF info dictionary as well as any other data stored in the trailer.
You could go around it, but a possibly cleaner approach is to
serialize the document in memory (as illustrated in PDFDocMemory
sample project - www.pdftron.com/net/samplecode.html#PDFDocMemory).
Using PDFDoc constructor that accepts a memory buffer, you can then
open any number of document instances.