
Я пытаюсь конвертировать файлы в PDF с помощью инструмента командной строки LibreOffice, как показано ниже:
libreoffice --headless --convert-to pdf filename
Теперь я хочу ограничить печать, редактирование и конвертацию преобразованного файла. Как это сделать в командной строке?
решение1
Просто используйтеинструмент командной строки, такой как pdftk или библиотека Java PDFboxдля постобработки PDF-файла.
Вот пример шифрования файла 1.pdf
с помощьюpdftk, что позволяет пользователю распечатать файл (изПримеры сервера pdftk):
pdftk 1.pdf output 1.128.pdf owner_pw foo user_pw baz allow printing
TheБиблиотека 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 бит, на мой взгляд, слишком коротка. Рекомендуется использовать более длинный ключ.