Creating read only pdf file using Python

2.3k views Asked by At

Is there any python module using that we can create a new pdf file or modify the existing pdf file which have only read permission. I want to disable the "Save as" and "Save as to other formats" for the pdf file.(DRM things.)

2

There are 2 answers

1
kaipatel On

I'm not sure this is portable, but you could use os.chmod:

import os
from stat import S_IREAD, S_IRGRP, S_IROTH

filename = "yourfile.pdf"
# Open the file and write your stuff to the file etc...

os.chmod(filename, S_IREAD|S_IRGRP|S_IROTH)

Thanks to: Change file to read-only mode in Python

0
K J On

Adobe wrote PDF as an editable Printer Port Page Device Document Descriptive File Format (PDF for short.)

It allows for altering the document input to match a device output capabilities.

The reader can edit the source vector fonts into pixels or laser beams for printing, using font replacement as required. So the whole concept of any computer file is it can be adapted as required to suite the user needs or desires.

Under commercial pressure Adobe added encryption so that Authors wishes could be conveyed to the user (if they wish to consider them). This is the basis of DRM it is a desire on the part of the human creator that does not need to be respected by the mechanical user.

So in short once a PDF is decrypted to view it is also decrypted to edit and no amount of flagging can stop the necessary or desired user modifications.

Adobe products of course will respect their flag-ellation, and those commercially close to Adobe may too.