• Onedrive and PDF read only files

    Author
    Topic
    #505900

    I created a PDF file (save as PDF in word) and saved it to my OneDrive storage.
    I then created a read only link for that file
    When the link is clicked, the file opens in Word Online
    and worse: the possibility is offered to edit the file (and convert it back to word)

    How can I prevent this from happening?

    Viewing 3 reply threads
    Author
    Replies
    • #1567518

      Are you accessing the link from the account which stored the file originally?

      --Joe

      • #1567540

        Yes I do. When the link is accessed from another account, the “edit in word” button is not there.
        I still find the behaviour strange, especially because the link was created as read-only.

    • #1567576

      Your account has different privileges on the document/file since you saved it originally. The “read only” is only for others.

      --Joe

      • #1567593

        I understand that but I’m still annoyed because the PDF file opens in Word (online) and not in Acrobat Reader. Even for the non-original account (but that account too has Office 365). I wonder what happens for a user that not even has Office. Is there a way to force opening as PDF?

    • #1567597

      What happens is effectively out of your hands as it depends on what software is present and any preferences set on the user’s PC.

    • #1567734

      It is hardly Microsoft’s fault that a user chooses to open PDF files in one of many applications capable of opening unprotected PDF files. PDF is a standard format.

      You can make it more difficult for the user to open the PDF by password protecting it against opening (or against editing) but you will need third party software to do that. I suggest PDF Creator v 1.7.3(rather than the latest rather more bloated version). Only install the core program and particularly watch out for switches that invite changes to your browser as you certainly won’t want those.

      You can then use the following function to create a protected PDF. The TestPrint macro saves the current document as Test.PDF in the named folder. With the settings shown it will open without a password in Adobe Reader/Acrobat but it will not open in Word 2013/2016, and users will not easily be able to copy, edit or print the PDF.

      Code:
      Option Explicit
      Sub TestPrint()
      PrintToPDFCreator “Test.pdf”, “C:Path”, ActiveDocument, “password”, , True, True, True
      End Sub
      
      
      Sub PrintToPDFCreator(sPDFName As String, _
                            sPDFPath As String, _
                            oDoc As Document, _
                            Optional sMasterPass As String, _
                            Optional sUserPass As String, _
                            Optional bNoCopy As Boolean, _
                            Optional bNoPrint As Boolean, _
                            Optional bNoEdit As Boolean)
      Dim pdfjob As Object
      Dim sPrinter As String
      Dim iCopy As Integer, iPrint As Integer, iEdit As Integer
      
          If bNoCopy Then iCopy = 1 Else iCopy = 0
          If bNoPrint Then iPrint = 1 Else iPrint = 0
          If bNoEdit Then iEdit = 1 Else iEdit = 0
      
          ‘Change active printer to PDFCreator
          With Dialogs(wdDialogFilePrintSetup)
              sPrinter = .Printer
              .Printer = “PDFCreator”
              .DoNotSetAsSysDefault = True
              .Execute
          End With
      
          Set pdfjob = CreateObject(“PDFCreator.clsPDFCreator”)
      
          With pdfjob
              If .cStart(“/NoProcessingAtStartup”) = False Then
                  GoTo err_handler
              End If
      
              .cStart “/NoProcessingAtStartup”
              .cOption(“UseAutosave”) = 1
              .cOption(“UseAutosaveDirectory”) = 1
              .cOption(“AutosaveDirectory”) = sPDFPath
              .cOption(“AutosaveFilename”) = sPDFName
              .cOption(“AutosaveFormat”) = 0        ‘ 0 = PDF
      
              If Not sMasterPass = vbNullString Then
      
                  ‘The following are required to set security of any kind
                  .cOption(“PDFUseSecurity”) = 1
                  .cOption(“PDFOwnerPass”) = 1
                  .cOption(“PDFOwnerPasswordString”) = sMasterPass
      
                  ‘To set individual security options
                  .cOption(“PDFDisallowCopy”) = iCopy
                  .cOption(“PDFDisallowModifyContents”) = iEdit
                  .cOption(“PDFDisallowPrinting”) = iPrint
      
                  ‘To force a user to enter a password before opening
                  .cOption(“PDFUserPass”) = 1
                  .cOption(“PDFUserPasswordString”) = sUserPass
                  ‘To change to High encryption
                  .cOption(“PDFHighEncryption”) = 1
              End If
      
              .cClearCache
          End With
      
          ‘Print the document to PDF
          oDoc.PrintOut
      
          ‘Wait until the print job has entered the print queue
          Do Until pdfjob.cCountOfPrintjobs = 1
              DoEvents
          Loop
          pdfjob.cPrinterStop = False
      
          ‘Wait until PDF creator is finished then release the objects
          Do Until pdfjob.cCountOfPrintjobs = 0
              DoEvents
          Loop
          pdfjob.cClose
          ‘Restore the original printer
          With Dialogs(wdDialogFilePrintSetup)
              .Printer = sPrinter
              .Execute
          End With
      lbl_Exit:
          Set pdfjob = Nothing
          Exit Sub
      err_handler:
          MsgBox “Unable to initialize PDFCreator.” & vbCr & vbCr & _
                 “This may be an indication that the PDF application has become corrupted, ” & _
                 “or its spooler blocked by AV software.” & vbCr & vbCr & _
                 “Re-installing PDF Creator may restore normal working.”
          Err.Clear
          GoTo lbl_Exit
      End Sub
      
      
      • #1571296

        You can then use the following function to create a protected PDF. The TestPrint macro saves the current document as Test.PDF in the named folder. With the settings shown it will open without a password in Adobe Reader/Acrobat but it will not open in Word 2013/2016, and users will not easily be able to copy, edit or print the PDF.

        Thanks for that! I am still running XP, and frustrated by my inability to print to pdf (for free). Any print utilities I have tried in the past were deficient in some way (well, what do I expect for free?). I was interested in the ability to protect files, so downloaded your code. I am rather embarrassed to admit that I was not sure what your code would run under: VBx, vba (which vn of office?) etc, and failed to properly interpret the significance of ‘ActiveDocument‘. However, I tried it in Word 2000 and it runs fine (after some tweaking), and probably works with later vns also.

        I was hit by a major problem: as soon as the print job was kicked off (oDoc.PrintOut), the PC would lock up (well, Word would). I experimented with all sorts of tweaks to the time delay code (waiting for the PDFCreator job to start) and things got better (I inserted Windows sleep() commands, after some googling), but not resolved. I admit I could not understand the full purpose of the ‘/NoProcessingAtStartup’ command, and managed to crash the PC a few times whilst experimenting. I totally failed to find any guidance on PDFforge or anywhere else on the use of the various PDFCreator code settings (I could find lists of them but nothing else). In the end my problem was solved by kicking off the print job in the foreground, with oDoc.PrintOut (False), as it seemed the default was background, and this just would not work (the pdf job count would never increment until I interrupted the code – at which point it was magically incremented) . This may be a kludge to fix an as-yet-unidentifed fault elsewhere in my modified code, but for now it works a treat!

        I will also note that your use of wdDialogFilePrintSetup to (temporarily) set the default printer seems to be unnecessary (now?), as the command ActivePrinter = “PDFCreator” seems to do the trick, and is easily reversed – I may yet find out its limitations.

        Thanks for the code and the kick-up-the-b*m it gave me. Martin

        PS You are right about using PDFCreator 1.7.3, but anyone trying this should be warned that its installation attempts to give one an updated vn, which requires dot-net 4 and a consequential big download if one is on XP as I am. I hate dot-net – it gives me nothing but update troubles.

        PPS v1.7.3 is now unsupported – shame!

    Viewing 3 reply threads
    Reply To: Onedrive and PDF read only files

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: