Opening documents in read-only using Open dialog
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
-
- User
- Posts: 518
- Joined: Thu Dec 06, 2007 8:13 pm
Opening documents in read-only using Open dialog
Hello and happy Friday guys,
I'm wondering if there is a way to ensure that read-only mode is always effectively set on a document which should be opened in read-only. For instance, I know I can set a document to read-only if I am programmatically in control of opening of the document. However, if I'm using the Open dialog and the program is already running, what would be the most elegant way to ensure that the document opens in read-only if necessary? I know from the other read-only post that if a document is already open, you need to get the source of the document, then close and re-open the document with read-only parameters set.
For example, could I use the e.beforeOpenDoc event to this effect and be able to check the permissions of the document before opening it so that I don't have to go through the routine of closing and reopening the document? Any other ideas would be appreciated.
Thanks,
Doc.It Development
I'm wondering if there is a way to ensure that read-only mode is always effectively set on a document which should be opened in read-only. For instance, I know I can set a document to read-only if I am programmatically in control of opening of the document. However, if I'm using the Open dialog and the program is already running, what would be the most elegant way to ensure that the document opens in read-only if necessary? I know from the other read-only post that if a document is already open, you need to get the source of the document, then close and re-open the document with read-only parameters set.
For example, could I use the e.beforeOpenDoc event to this effect and be able to check the permissions of the document before opening it so that I don't have to go through the routine of closing and reopening the document? Any other ideas would be appreciated.
Thanks,
Doc.It Development
-
- User
- Posts: 518
- Joined: Thu Dec 06, 2007 8:13 pm
Re: Opening documents in read-only using Open dialog
Maybe I should rephrase the question.
How can I use e.beforeOpenDoc to catch the source of the document and check if the document should be opened with read-only parameters? Or, is this not possible.
Thanks,
Doc.It Development
How can I use e.beforeOpenDoc to catch the source of the document and check if the document should be opened with read-only parameters? Or, is this not possible.
Thanks,
Doc.It Development
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Opening documents in read-only using Open dialog
Hello docu-track99,
We are investigating this possibility though there is no solution at this point. We will try to reply shortly - there probably is a possibility that this could be done but this requires further analysis of our code. So please wait a little bit for our conclusion =)
Cheers,
Alex
We are investigating this possibility though there is no solution at this point. We will try to reply shortly - there probably is a possibility that this could be done but this requires further analysis of our code. So please wait a little bit for our conclusion =)
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 518
- Joined: Thu Dec 06, 2007 8:13 pm
Re: Opening documents in read-only using Open dialog
Hello Alex,
Thanks and please do keep me posted on this.
I do need a little bit of help with a workaround solution I've been attempting. To get the document to open in read-only (using the open dialog) I'm catching the e.document.initialized event and closing the document, then re-opening the document through my own subroutine which sets the control to read-only on the document. However, this causes an unspecified system error from the control as I suppose the control doesn't like it if you close the document while it's in the middle of opening. Here is my code:
Calling Doc.Close() while catching e.document.initialized is causing an error (from the control itself), please see the attached screencap.
My code works really well to accomplish what I need, but having this error pop-up won't do. I've also tried using different events such as e.beforeOpenDoc (which isn't implemented by the way), e.document.viewingStarted, e.documentView.ready. But I end up running into other problems, like you can't get the IPXV_Document object from the event handler if you use e.documentView.ready and you can't close a document when e.document.viewingStarted because you get another error.
Any suggestions here?
Thanks,
Doc.It Development
Thanks and please do keep me posted on this.
I do need a little bit of help with a workaround solution I've been attempting. To get the document to open in read-only (using the open dialog) I'm catching the e.document.initialized event and closing the document, then re-opening the document through my own subroutine which sets the control to read-only on the document. However, this causes an unspecified system error from the control as I suppose the control doesn't like it if you close the document while it's in the middle of opening. Here is my code:
Code: Select all
Case pdfCtrl.Inst.Str2ID("e.document.initialized")
Dim Doc As PDFXEdit.IPXV_Document = DirectCast(e.pFrom, PDFXEdit.IPXV_Document)
Dim DocSrcPath = Doc.CoreDoc.SrcInfo.ActualFileName
Dim fileInfo As New System.IO.FileInfo(DocSrcPath)
If fileInfo.IsReadOnly And Not ReadOnlyPermsAreSet(Doc.CoreDoc) Then
mWriteLog(15, "PdfCtrl_OnEvent(): Document does not have the correct read-only properties set. Closing document...")
Doc.Close()
LoadDocument(DocSrcPath)
End If
My code works really well to accomplish what I need, but having this error pop-up won't do. I've also tried using different events such as e.beforeOpenDoc (which isn't implemented by the way), e.document.viewingStarted, e.documentView.ready. But I end up running into other problems, like you can't get the IPXV_Document object from the event handler if you use e.documentView.ready and you can't close a document when e.document.viewingStarted because you get another error.
Any suggestions here?
Thanks,
Doc.It Development
- Attachments
-
- for_tracker3.zip
- (76.23 KiB) Downloaded 142 times
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Opening documents in read-only using Open dialog
Hello docu-track99,
I am wondering about one thing: do you need to open the file itself (i mean file on disk) with readonly flags or do you want to set PDF file security flags so that it would be read-only?
I am wondering about one thing: do you need to open the file itself (i mean file on disk) with readonly flags or do you want to set PDF file security flags so that it would be read-only?
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 518
- Joined: Thu Dec 06, 2007 8:13 pm
Re: Opening documents in read-only using Open dialog
I need to open the file with read-only flags so that the control automatically disables things like annotations. I already have a method which creates these flags. However, if I use your open dialog there doesn't appear to be away to enforce these flags on a read-only document.
Thanks,
Doc.It Development
Thanks,
Doc.It Development
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Opening documents in read-only using Open dialog
Hello docu-track99,
The solution can be achieved by reloading open command and putting your Open File Dialog there. And after you get the file name you can open the file with the security parameters.
Here's the updated gist how to do this:
https://gist.github.com/Polaringu/ad31ad433401c1c004d0
HTH,
Alex
The solution can be achieved by reloading open command and putting your Open File Dialog there. And after you get the file name you can open the file with the security parameters.
Here's the updated gist how to do this:
https://gist.github.com/Polaringu/ad31ad433401c1c004d0
HTH,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 518
- Joined: Thu Dec 06, 2007 8:13 pm
Re: Opening documents in read-only using Open dialog
Thanks, this is really cool. I'll give it a shot and report back with the vb.net code.
In the meantime, just because I have to tell my boss how my project is progressing, I have a few to-dos that are waiting on build 317. You mentioned it would be out this week, would you have a more accurate estimate at this time?
Regards,
Doc.It Development
In the meantime, just because I have to tell my boss how my project is progressing, I have a few to-dos that are waiting on build 317. You mentioned it would be out this week, would you have a more accurate estimate at this time?
Regards,
Doc.It Development
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Opening documents in read-only using Open dialog
Hello docu-track99,
The estimated time is Monday 21st (if all goes well of course).
Cheers,
Alex
The estimated time is Monday 21st (if all goes well of course).
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 518
- Joined: Thu Dec 06, 2007 8:13 pm
Re: Opening documents in read-only using Open dialog
Hello Alex,
Thanks for the update.
Regarding the read-only open dialog, in case there are any VB.Net developers out there, first I call a subroutine to add a command handler to the cmd.open:
The subroutine is as follows:
Finally, I add the block below to my OnNotify in the CmdHandler class:
Regards,
Doc.It Development
Thanks for the update.
Regarding the read-only open dialog, in case there are any VB.Net developers out there, first I call a subroutine to add a command handler to the cmd.open:
Code: Select all
AddHandlerToMenuCommand(pdfCtrl, "cmd.open", m_oCmdHandler)
Code: Select all
Public Sub AddHandlerToMenuCommand(oPDFCtrl As AxPXV_Control, CmdName As String, cmdHandler As cCmdHandler)
Try
Dim cmdId = oPDFCtrl.Inst.Str2ID(CmdName)
Dim cmd = uiInst.CmdManager.Cmds.Find2(cmdId)
cmd.Handler = cmdHandler
Catch ex As Exception
'Catch exception here
End Try
End Sub
Code: Select all
Dim nOpenID As Integer = frmMain.pdfCtrl.Inst.Str2ID("cmd.open")
If pCmd.ID = nOpenID Then
If nCode = CInt(PDFXEdit.UIX_CmdNotifyCodes.UIX_CmdNotify_Exec) Then
Dim ofd As New OpenFileDialog()
ofd.Filter = "PDF Files (*.pdf)|*.pdf|All files (*.*)|*.*"
ofd.FilterIndex = 1
ofd.RestoreDirectory = True
ofd.CheckFileExists = True
If ofd.ShowDialog() = DialogResult.OK Then
Dim openParams As PDFXEdit.ICab = frmMain.pdfCtrl.Inst.CreateOpenDocParams()
Dim openParamsRoot As PDFXEdit.ICabNode = openParams.Root
Dim secPerms As Integer = CInt(PDFXEdit.PXC_PermsFlags.PermF_All) And Not (CInt(PDFXEdit.PXC_SecurityPermissions.Permit_Copying_And_TextGraphicsExtractions) Or CInt(PDFXEdit.PXC_SecurityPermissions.Permit_Printing) Or CInt(PDFXEdit.PXC_SecurityPermissions.Permit_HighQualityPrinting))
openParamsRoot.SetInt("SecPermMask", secPerms)
Dim fileInfo As New System.IO.FileInfo(ofd.FileName)
If fileInfo.IsReadOnly Then
frmMain.pdfCtrl.Inst.ActiveMainFrm.OpenDocFromPath(ofd.FileName, openParams)
Else
frmMain.pdfCtrl.Inst.ActiveMainFrm.OpenDocFromPath(ofd.FileName)
End If
End If
End If
End If
Doc.It Development
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Opening documents in read-only using Open dialog
Hello docu-track99,
Thanks for the Vb.Net translation
Thanks for the Vb.Net translation
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 130
- Joined: Tue May 03, 2016 1:11 pm
Re: Opening documents in read-only using Open dialog
Hi,
We also open document via some other OpenDialog (HyarchisOpenDialog).
The HyarchisOpenDialog will return a filename (including path).
We use the path with the OpenDocFromPath method.
Is there cmd for this method?
If so what is it and how do I pass the path to it?
I do understand that I have to write a new part for the OnNotify method
Regards
Eric
We also open document via some other OpenDialog (HyarchisOpenDialog).
The HyarchisOpenDialog will return a filename (including path).
We use the path with the OpenDocFromPath method.
Is there cmd for this method?
If so what is it and how do I pass the path to it?
I do understand that I have to write a new part for the OnNotify method
Regards
Eric
-
- User
- Posts: 130
- Joined: Tue May 03, 2016 1:11 pm
Re: Opening documents in read-only using Open dialog
Hi
Forget about the previous question. As I have the filename I can use the FileInfo and determine if the file is readonly.
If so then I can set the PermsFlags accordingly the above example.
Regards
Eric
Forget about the previous question. As I have the filename I can use the FileInfo and determine if the file is readonly.
If so then I can set the PermsFlags accordingly the above example.
Regards
Eric
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Opening documents in read-only using Open dialog
Hello Eric,
Glad you had your problem solved
Glad you had your problem solved
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ