PDF正在成功生成,但我想用密码保护它。 flying-saucer-pdf doc对我没有帮助。 我正在使用这个例子 Using thymeleaf+flying-saucer-pdf+Spring Boot
答案 0 :(得分:9)
使用PDFEncryption
PDF Creator使用PDFEncryption
课程设置PDF格式的密码。要为PDF设置密码,首先要创建setUserPassword()
的实例,然后使用其方法final File outputFile = File.createTempFile(fileName, ".pdf");
FileOutputStream os = new FileOutputStream(outputFile);
PDFEncryption pdfEncryption = new PDFEncryption();
String password= "password@123";
pdfEncryption.setUserPassword(password.getBytes());
ITextRenderer renderer = new ITextRenderer();
renderer.setPDFEncryption(pdfEncryption);
renderer.setDocumentFromString(htmlContent);
renderer.layout();
renderer.createPDF(os, false);
renderer.finishPDF();
,如下所示:
Private Sub Prepare_PDF_Click()
Dim MyFullName As String
Dim xlAppFTP As Object, xlWb As Object, xlWs As Object
Set xlAppFTP = CreateObject("Excel.Application")
Set xlWb = xlAppFTP.Workbooks.Open("X:\ANALYSIS\GHH.xlsm")
MyFullName = "X:\ANALYSIS\GHH" & format(Now(),"YYYYMMDD") & ".pdf"
xlWb.ExportAsFixedFormat Type:=0, FileName:=MyFullName, _
Quality:=1, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub