In particular, until the layouts happen, until the document bounds have been computed, and until the scrollbars have been updated, any document/viewport alignment that you do is premature.
The general thing to do is to implement an “InitialLayoutCompleted” DiagramEvent listener, which will be called after layouts have been performed and the document and viewport sizes have been determined.
But for what you want to do, you can just set Diagram.initialDocumentSpot and Diagram.initialViewportSpot ahead of time, and it will call Diagram.alignDocument after everything else has been determined, at about the time that the “InitialLayoutCompleted” DiagramEvent is raised.