![限制libreoffice命令列工具轉換的pdf文件的列印、編輯和轉換](https://rvso.com/image/1414665/%E9%99%90%E5%88%B6libreoffice%E5%91%BD%E4%BB%A4%E5%88%97%E5%B7%A5%E5%85%B7%E8%BD%89%E6%8F%9B%E7%9A%84pdf%E6%96%87%E4%BB%B6%E7%9A%84%E5%88%97%E5%8D%B0%E3%80%81%E7%B7%A8%E8%BC%AF%E5%92%8C%E8%BD%89%E6%8F%9B.png)
我正在嘗試使用 libreoffice 命令列工具將文件轉換為 pdf,如下所示 -
libreoffice --headless --convert-to pdf filename
現在我想限制轉換後的文件的列印、編輯和轉換,如何在命令列上實現這一點。
答案1
只需使用一個命令列工具,如 pdftk 或 PDFbox java 庫對 pdf 進行後處理。
1.pdf
這是使用加密檔案的範例pdftk,允許使用者列印文件(從pdftk 伺服器範例):
pdftk 1.pdf output 1.128.pdf owner_pw foo user_pw baz allow printing
這Apache PDFBox 庫附帶一些命令列工具。這是一個範例,說明如何在命令列上使用 PDFBox 加密文件:
java -jar pdfbox-app-x.y.z.jar Encrypt [OPTIONS] <password> <inputfile>
其中選項可能是:
-O The owner password to the PDF, ignored if -certFile is specified.
-U The user password to the PDF, ignored if -certFile is specified.
-certFile Path to X.509 cert file.
-canAssemble true Set the assemble permission.
-canExtractContent true Set the extraction permission.
-canExtractForAccessibility true Set the extraction permission.
-canFillInForm true Set the fill in form permission.
-canModify true Set the modify permission.
-canModifyAnnotations true Set the modify annots permission.
-canPrint true Set the print permission.
-canPrintDegraded true Set the print degraded permission.
-keyLength 40 The number of bits for the encryption key.
inputfile The PDF file to encrypt.
outputfile The file to save the encrypted document to. If left blank then it will be the same as the input file.
注意:恕我直言,40 位元的金鑰長度會太短 - 建議使用更長的金鑰。