我已成功使用BIRT报告引擎api使用外部oracle数据源生成pdf。为了生成设计,我使用了eclipse BIRT报表设计器。我的下一个任务是将此pdf设为密码保护。 请指导一下这样做。 以下是生成pdf的代码
package com.birt.Main;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
import org.eclipse.birt.report.engine.api.ReportEngine;
public class MainPdf {
public static void main(String[] args){
try {
EngineConfig config = new EngineConfig();
Platform.startup(config);
ReportEngine engine = new ReportEngine(config);
String reportDesign = "new_report.rptdesign";
IReportRunnable reportRunnable = engine.openReportDesign(reportDesign);
IRunAndRenderTask runAndRender = engine.createRunAndRenderTask(reportRunnable);
PDFRenderOption option = new PDFRenderOption();
option.setOutputFileName("output/resample/mypdf.pdf");
option.setOutputFormat("pdf");
runAndRender.setRenderOption(option);
runAndRender.run();
runAndRender.close();
engine.destroy();
Platform.shutdown();
} catch (EngineException e) {
e.printStackTrace();
} catch (BirtException e) {
e.printStackTrace();
}
}
}
我使用的是org.eclipse.birt.runtime版本4.2.0以下版本 生成的pdf的屏幕截图
答案 0 :(得分:0)
I got it done through itext library . Here is the added code
PdfReader reader = new PdfReader("output/resample/temp.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("output/resample/mypdf.pdf"));
stamper.setEncryption(USER_PASS.getBytes(), OWNER_PASS.getBytes(),
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);
stamper.close();
reader.close();
System.out.println("Done");
temp.pdf是使用BIRT生成的。 使用的资源是here