Can I allow printing but block downloading and copying for Google Drive files?

Hey everyone, I’m stuck with a Google Drive issue

I want users to be able to print a file from my Google Drive, but I don’t want them to download or copy it. Is this even possible?

I tried using some code I found online, but it didn’t work out. It ended up disabling everything, including printing. Here’s a simplified version of what I tried:

function restrictFileAccess() {
  const fileId = 'abc123';
  const apiUrl = 'https://api.google.com/drive/v3/files/' + fileId;
  
  const response = UrlFetchApp.fetch(apiUrl, {
    method: 'patch',
    headers: {authorization: 'Bearer ' + ScriptApp.getOAuthToken()},
    contentType: 'application/json',
    payload: JSON.stringify({
      writersCanShare: false,
      copyRequiresWriterPermission: false
    }),
  });
  
  console.log(response.getContentText());
}

If this isn’t doable, is there maybe a way to use Google Apps Script to only allow printing the content of a PDF file in an iframe? Any help would be awesome!

Unfortunately, Google Drive doesn’t offer a native way to allow printing while blocking downloading and copying. It’s a common limitation many users face. One potential workaround is to create a Google Apps Script web app that displays the content in a controlled environment. You could use this to render the file contents and provide a custom print function. This method requires more advanced coding but gives you better control over user actions.

Another option is to use a third-party document viewer service that offers more granular permission settings. Some of these services allow you to disable downloads while still permitting printing. However, this would require moving your files off Google Drive.

Ultimately, there’s no perfect solution within Google Drive itself. The choice depends on your technical skills and willingness to use external services. Remember that determined users can always find ways to capture content, so consider if absolute prevention is necessary for your use case.

hey claire, ive been thru that too. google drive restrictions dont let u easily allow printing only. maybe try converting the file into images on a google site so users can print? still, ppl might find workarounds but it may help.

I’ve tackled this issue before, and unfortunately, there’s no perfect solution within Google Drive’s native capabilities. The restrictions you’re trying to implement are tricky because they’re often controlled at the browser level.

However, here’s a workaround that might help:

  1. Convert your document to a high-quality image or a series of images.
  2. Embed these images in a Google Site.
  3. Set the permissions on the Site to ‘Anyone can view.’

This approach allows viewers to see and print the content, but makes downloading and copying much more difficult. It’s not foolproof, as determined users could still screenshot, but it adds a layer of protection.

For PDFs, you could use Google Apps Script to create a custom UI that displays the PDF content page by page, with a print button that triggers a server-side print job. This gives you more control but requires more complex coding.

Remember, any solution will involve trade-offs between security and user experience. You might need to prioritize which aspect is more important for your specific use case.