コード例 #1
0
ファイル: PDFSecurity.cs プロジェクト: jehan2898/root
 public void SecurePDF(PDFDocument sourcePDF, string outputFile)
 {
     PDFHelper.DisplayTrialPopupIfNecessary();
     try
     {
         AccessPermission accessPermission = new AccessPermission();
         accessPermission.setCanAssembleDocument(this.Permission.AllowAssembly);
         accessPermission.setCanExtractContent(this.Permission.AllowExtractContents);
         accessPermission.setCanExtractForAccessibility(this.Permission.AllowExtractForAccessibility);
         accessPermission.setCanFillInForm(this.Permission.AllowFillInForm);
         accessPermission.setCanModify(this.Permission.AllowModifyContents);
         accessPermission.setCanModifyAnnotations(this.Permission.AllowModifyAnnotations);
         accessPermission.setCanPrint(this.Permission.AllowPrinting);
         accessPermission.setCanPrintDegraded(this.Permission.AllowDegradedPrinting);
         StandardProtectionPolicy standardProtectionPolicy = new StandardProtectionPolicy(this.OwnerPassword, this.UserPassword, accessPermission);
         if (!PDFHelper.AddStamp)
         {
             sourcePDF.PDFBoxDocument.protect(standardProtectionPolicy);
             sourcePDF.PDFBoxDocument.save(outputFile);
             sourcePDF.PDFBoxDocument.close();
         }
         else
         {
             PDDocument pDFBoxDocument = sourcePDF.PDFBoxDocument;
             pDFBoxDocument = PDFHelper.AddTrialStampIfNecessary(pDFBoxDocument);
             pDFBoxDocument.protect(standardProtectionPolicy);
             pDFBoxDocument.save(outputFile);
             pDFBoxDocument.close();
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         throw new PDFToolkitException(exception.Message, exception);
     }
 }