在xdocreport中为pdf设置加密密码 [英] Set encryption password for pdf in xdocreport

查看:268
本文介绍了在xdocreport中为pdf设置加密密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在xdocreport中将odt文件转换为pdf时如何设置加密密码?

我在这里指的是iText中的PDFWriter.setEncryption方法.

解决方案

XDocReport 1.0.4(即将发布)提供fr.opensagres.xdocreport.itext.extension. IPdfWriterConfiguration ,可为您提供自定义iText PDFWriter的功能.这里是设置加密的示例:

org.odftoolkit.odfdom.converter.pdf.PdfOptions options = new PdfOptions();
options.setConfiguration( new IPdfWriterConfiguration()
{

  public void configure( PdfWriter writer )
  {
    writer.setEncryption(...);
  }
});
PdfConverter.getInstance().convert( document, out, options );

如果您希望将转换器与report.convert方法一起使用,则必须这样做:

org.odftoolkit.odfdom.converter.pdf.PdfOptions pdfOptions = ...
Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.ODFDOM).subOptions(pdfOptions);

IXDocReport report = ...
report.convert(context, options, out);

您可以在 XDocReport Wiki 中找到这些信息.. >

How to set encryption password while converting odt file to pdf in xdocreport?

I am referring to PDFWriter.setEncryption method in iText here.

解决方案

XDocReport 1.0.4 (which will soon released) provides fr.opensagres.xdocreport.itext.extension.IPdfWriterConfiguration which gives you the capability to customize the iText PDFWriter. Here a sample which set encryption :

org.odftoolkit.odfdom.converter.pdf.PdfOptions options = new PdfOptions();
options.setConfiguration( new IPdfWriterConfiguration()
{

  public void configure( PdfWriter writer )
  {
    writer.setEncryption(...);
  }
});
PdfConverter.getInstance().convert( document, out, options );

If you wish to use the converter with the report.convert method, you must do like this :

org.odftoolkit.odfdom.converter.pdf.PdfOptions pdfOptions = ...
Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.ODFDOM).subOptions(pdfOptions);

IXDocReport report = ...
report.convert(context, options, out);

You can find those info in the XDocReport wiki.

这篇关于在xdocreport中为pdf设置加密密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆