本文整理匯總了Java中net.sf.jasperreports.engine.export.JRPdfExporter.setParameter方法的典型用法代碼示例。如果您正苦於以下問題:Java JRPdfExporter.setParameter方法的具體用法?Java JRPdfExporter.setParameter怎麽用?Java JRPdfExporter.setParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.sf.jasperreports.engine.export.JRPdfExporter
的用法示例。
在下文中一共展示了JRPdfExporter.setParameter方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: export
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
String fileName=this.getExportFileName(req);
fileName+=".pdf";
res.setContentType("application/octet-stream");
res.setHeader("Connection", "close");
res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\"");
JRPdfExporter exporter = new JRPdfExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例2: exportToPdf
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
@Override
public byte[] exportToPdf(final JasperPrint jasperPrint)
{
final JRPdfExporter exporter = new JRPdfExporter();
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF8");
try
{
exporter.exportReport();
}
catch (JRException e)
{
throw new AdempiereException("Cannot create PDF from " + jasperPrint, e);
}
return outputStream.toByteArray();
}
示例3: generatePdfReport
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
/**
* generate a ByteArrayOutputStream from given JasperPrint object for the PDF report
*
* @param jasperPrint transform to pdf report
* @return reporting ByteArrayOutputStream
* @throws ReportingException when the JasperPrint null
* @throws JRException
* @throws IOException
*/
public ByteArrayOutputStream generatePdfReport(JasperPrint jasperPrint) throws JRException, ReportingException {
ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();
if (jasperPrint == null) {
throw new ReportingException("jasperPrint null, can't convert to PDF report");
}
try {
JRPdfExporter jrPdfExporter = new JRPdfExporter();
jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, pdfOutputStream);
jrPdfExporter.exportReport();
} catch (JRException e) {
throw new JRException("Error occurred exporting PDF report ", e);
}
return pdfOutputStream;
}
示例4: exportPdf
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
private void exportPdf(JasperPrint jp, ByteArrayOutputStream baos, Map params) {
// Create a JRPdfExporter instance
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
try {
exporter.exportReport();
} catch (JRException e) {
}
}
示例5: genPDF
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
/**
* Метод генерации PDF-отчетов через файл. Вынесен в отдельный метод для синхронизации.
*
* @param jasperPrint этот готовый отчет и экспортим в PDF
* @return возвращает готовый отчет в виде массива байт
*/
synchronized private static byte[] genPDF(JasperPrint jasperPrint)
throws JRException, FileNotFoundException, IOException {
// сгенерим отчет во временный файл
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
Uses.TEMP_FOLDER + File.separator + "temppdf.pdf");
exporter.exportReport();
// отправим данные из файла и удалим его
final File pdf = new File(Uses.TEMP_FOLDER + File.separator + "temppdf.pdf");
final FileInputStream inStream = new FileInputStream(pdf);
pdf.delete();
return Uses.readInputStream(inStream);
}
示例6: exportPDF
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
private static void exportPDF(JasperPrint jasperPrint) throws Exception
{
File file = new File("D:/test.pdf");
System.out.println("Exporting PDF to " + file);
{
JRPdfExporter exporter = new JRPdfExporter();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF8");
// JRProperties.setProperty(JRFont.DEFAULT_PDF_FONT_NAME, "arial.ttf");
exporter.exportReport();
writeBytes(file, outputStream.toByteArray());
}
}
示例7: logExportedFiles
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
/**
* @param pdfBytes
* @param xmlBytes
* @param pdfName
* @param xmlName
* @throws JazzOMRException
* @throws FileNotFoundException
* @throws IOException
*/
protected void logExportedFiles(byte[] pdfBytes, byte[] xmlBytes, String pdfName, String xmlName) {
if(!log.isDebugEnabled())
return;
byte[] pdfFromXML;
try {
ByteArrayInputStream bais = new ByteArrayInputStream(xmlBytes);
JasperPrint jasperPrint = JRPrintXmlLoader.load(bais);
JRPdfExporter pdfExporter = new JRPdfExporter();
ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baosPDF);
pdfExporter.exportReport();
pdfFromXML = baosPDF.toByteArray();
} catch (JRException e) {
throw new JazzRuntimeException("erro ao tentar montar relatorio resultado do XML!", e);
}
writeToFile(pdfFromXML, "fromXML_"+pdfName);
writeToFile(pdfBytes, pdfName);
writeToFile(xmlBytes, xmlName);
}
示例8: exportToDataHandlerPDF
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
/**
*
* @param jp
* @return
*/
private DataHandler exportToDataHandlerPDF(JasperPrint jp) {
ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baosPDF);
try {
exporter.exportReport();
} catch (JRException e1) {
throw new JazzOMRRuntimeException("Erro ao tentar exportar relatorio", e1);
}
byte[] xmlBytes = null;
try {
baosPDF.flush();
xmlBytes = baosPDF.toByteArray();
baosPDF.close();
} catch (IOException e) {
throw new JazzOMRRuntimeException("Erro ao tentar exportar relatorio", e);
}
DataSource source = new ByteArrayDataSource(xmlBytes, "application/pdf");
DataHandler dataHandler = new DataHandler(source);
return dataHandler;
}
示例9: exportToDataHandlerPDF
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
/**
*
* @param jp
* @return
*/
private DataHandler exportToDataHandlerPDF(JasperPrint jp) {
ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baosPDF);
try {
exporter.exportReport();
} catch (JRException e1) {
throw new JazzRuntimeException("Erro ao tentar exportar relatorio", e1);
}
byte[] xmlBytes = null;
try {
baosPDF.flush();
xmlBytes = baosPDF.toByteArray();
baosPDF.close();
} catch (IOException e) {
throw new JazzRuntimeException("Erro ao tentar exportar relatorio", e);
}
DataSource source = new ByteArrayDataSource(xmlBytes, "application/pdf");
DataHandler dataHandler = new DataHandler(source);
return dataHandler;
}
示例10: getData
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
public static byte[] getData(JasperPrint print) {
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
ByteArrayOutputStream os = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os);
try {
exporter.exportReport();
} catch (JRException e) {
e.printStackTrace();
}
return os.toByteArray();
}
示例11: createPDF
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
public static void createPDF() throws FileNotFoundException, JRException, IOException {
// TODO Auto-generated method stub
InputStream jrxmlStream = new FileInputStream("/home/darcio/workspace/modules/JazzAV/bsn/src/main/resources/modeloAdes1.jrxml");
JasperReport compiled = JasperCompileManager.compileReport(jrxmlStream);
Map rootMap = new HashMap();
JasperPrint jasperPrint = JasperFillManager.fillReport(compiled, rootMap, new JREmptyDataSource());
int pageIndex = 0;
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPdfExporterParameter.OUTPUT_FILE, new File("/home/darcio/workspace/modules/JazzAV/bsn/src/main/resources/modeloAdes1.pdf"));
exporter.exportReport();
}
示例12: logExportedFiles
import net.sf.jasperreports.engine.export.JRPdfExporter; //導入方法依賴的package包/類
/**
* @param pdfBytes
* @param xmlBytes
* @param pdfName
* @param xmlName
* @throws JazzOMRException
* @throws FileNotFoundException
* @throws IOException
*/
protected void logExportedFiles(byte[] pdfBytes, byte[] xmlBytes, String pdfName, String xmlName) throws JazzOMRException {
byte[] pdfFromXML;
try {
ByteArrayInputStream bais = new ByteArrayInputStream(xmlBytes);
JasperPrint jasperPrint = JRPrintXmlLoader.load(bais);
JRPdfExporter pdfExporter = new JRPdfExporter();
ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baosPDF);
pdfExporter.exportReport();
pdfFromXML = baosPDF.toByteArray();
} catch (JRException e) {
throw new JazzOMRException("erro ao tentar montar relatorio resultado do XML!", e);
}
writeToFile(pdfFromXML, "fromXML_"+pdfName);
writeToFile(pdfBytes, pdfName);
writeToFile(xmlBytes, xmlName);
}