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
can I get the position of the current view for a PDF? e.g. middle of the page
Because I am loading a PDF into a memory stream and display the PDF from the memory stream which was opened before as a file and if the user has a high zoom factor and stands on the middle of the page I only can restore the zoom factor but the position always jumps to the beginning of the page.
I have found in the documentation the property RestoreLastView
Yes because your documents are loaded from memory streams - the Viewer treats them as different files.
You will need to store yourself the position at which a document was when it was closed using e.g.
Obtain the coordinates of the top left corner of the Pages View window (main rendering area) using Pages.ScreenX and Pages.ScreenY
Use TranslateScreenPoint - with the coordinates of the top left corner to figure out which point of the document was displayed in that corner of the pages View Windos and store this value.
Then the next time your customer opens the same file - use the MovePointToScreenPoint and the correct zoom level - and the document should open exactly at the same position. The coordinates in MovePointToScreenPoint are relative to the desktop - so don't forget to once again obtain the values of Pages.ScreenX and Pages.ScreenY - and adjust the coordinates accordingly.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs)
Dim oDataIn As Object
Dim oDataOut As Object
Dim dblScreenX As Integer
Dim dblScreenY As Integer
Dim dblPagePoints As Double()
Dim dblPagePointX As Integer
Dim dblPagePointY As Integer
oDataOut = Nothing
'#THK# 07.08.2013 Get Screen X
AxPDFXViewCtrl.GetDocumentProperty(iPDocCurrentID, "Pages.ScreenX", oDataOut, 0)
dblScreenX = DirectCast(oDataOut, Integer)
'#THK# 07.08.2013 Get Screen Y
AxPDFXViewCtrl.GetDocumentProperty(iPDocCurrentID, "Pages.ScreenY", oDataOut, 0)
dblScreenY = DirectCast(oDataOut, Integer)
'#THK# 07.08.2013 Get page point X and Y
oDataIn = New Object(1) {dblScreenX, dblScreenY}
AxPDFXViewCtrl.DoDocumentVerb(iPDocCurrentID, "Pages[" + iPDDocCurrentPage.ToString + "]", "TranslateScreenPoint", oDataIn, oDataOut, 0)
If oDataOut Is Nothing = True Then
'iSigFieldValues = New Integer() {0, 0, 0, 0}
dblPagePoints = New Double() {0, 0}
End IfIf oDataOut.GetType.Name <> "Double[]" Then
'iSigFieldValues = New Integer() {0, 0, 0, 0}
dblPagePoints = New Double() {0, 0}
End If
dblPagePoints = TryCast(oDataOut, Double())
dblPagePointX = Convert.ToInt32(dblPagePoints(0))
dblPagePointY = Convert.ToInt32(dblPagePoints(1))
'#THK# 07.08.2013 Load PDF into memory stream and show it
LoadPDAsStream(strPDocFile)
' MovePointToScreenPoint
' ------------------------------------------------------------------------
'1 Yes double Specifies x coordinate of the page point in points.
'2 Yes double Specifies y coordinate of the page point in points.
'3 Yes LONG Specifies x coordinate of screen point, relative to desktop.
' See also to the: Pages.ScreenX, Pages.ScreenY.
'4 Yes LONG Specifies y coordinate of screen point, relative to desktop.
oDataIn = New Object(3) {dblPagePointX, dblPagePointY, dblScreenX, dblScreenY}
AxPDFXViewCtrl.DoDocumentVerb(iPDocCurrentID, "Pages[" + iPDDocCurrentPage.ToString + "]", "MovePointToScreenPoint", oDataIn, Nothing, 0)
End Sub