java - How to generate password protected pdf using birt report engine api -
i have used birt report engine api generate pdf using external oracle data source. generate design have used eclipse birt report designer. next task make pdf password protected . please guide in doing same. below code generate 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(); } } }
i using below version 4.2.0 of org.eclipse.birt.runtime screen shot of generated pdf
i got done through itext library . here 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 1 generated using birt . resource used here
Comments
Post a Comment