Jump to content
We've recently updated our Privacy Statement, available here ×

zbigniew.nitecki

Members
  • Posts

    6
  • Joined

  • Last visited

zbigniew.nitecki's Achievements

  1. Hi, I have an JRXML file (not compiled) in my Java classpath. It worked perfectly, but I had to make some changes in the code, and I started using internal Jasper methods: DAY(Date)DAYSINMONTH(Date)MONTH(Date)[/code]When I am testing it in the Jasper Designer, everything is fine. But in the java app, when I am trying to compile the report and generate the PDF file I get errors: 1. The method DAY(Date) is undefined for the type invoice_sub_1557138584226_714026 value = String.format("%2s", DAY(((java.util.Date)parameter_ORDER_DATE.getValue()))).replace(" ", "0") + //$JR_EXPR_ID=9$ <->2. The method MONTH(Date) is undefined for the type invoice_sub_1557138584226_714026 String.format("%2s", MONTH(((java.util.Date)parameter_ORDER_DATE.getValue()))).replace(" ", "0") + //$JR_EXPR_ID=9$ <--->3. The method DAYSINMONTH(Date) is undefined for the type invoice_sub_1557138584226_714026 String.format("%2s", DAYSINMONTH(((java.util.Date)parameter_ORDER_DATE.getValue()))).replace(" ", "0") + //$JR_EXPR_ID=9$ <--------->[/code] What have I done wrong?
  2. Hi! I have a huge problem. I was coding an app which is using Jasperreports. Everything was perfectly fine when I was working locally. But then, when I have dockerized my app, when I run the method that should produce an PDF file, I get an error: Request processing failed; nested exception is net.sf.jasperreports.engine.JRRuntimeException: Error initializing graphic environment.[/code]I have found out that running my app with -DJava.awt.headless=true[/code]the problem would solve itself. But it is not. To be sure that I havent forgotten anything, here is the code of the method which is generating the PDF files, maybe there is something wrong there... The error is coming from this line: mainReport = JasperFillManager.fillReport(report, invoiceMap, new JREmptyDataSource());[/code]And here is the method: public byte[] generateInvoicePDF(Invoice invoice) { /* Map to fill in main JasperReport */ Map<String, Object> invoiceMap = new HashMap<String, Object>(); invoiceMap.put("FIRST_NAME", invoice.getFirstName()); invoiceMap.put("LAST_NAME", invoice.getLastName()); invoiceMap.put("REGON", invoice.getRegon()); invoiceMap.put("NIP", invoice.getNip()); invoiceMap.put("BUSINESS_NAME", invoice.getBusinessName()); invoiceMap.put("BUSINESS_LOCATION", invoice.getBusinessLocation()); invoiceMap.put("ORDER_DATE", invoice.getOrderDate()); invoiceMap.put("RECEPTION_DATE", invoice.getReceptionDate()); invoiceMap.put("CONTRACT_DATE", invoice.getContractDate()); invoiceMap.put("CONTRACTOR_COMMENT", invoice.getContractorComment()); invoiceMap.put("INVOICE_NUMBER", invoice.getInvoiceNumber()); invoiceMap.put("INVOICE_ISSUE_DATE", invoice.getInvoiceIssueDate()); JasperPrint mainReport; JasperPrint tableReport; try { InputStream invoiceJasper = InvoiceGeneratorServiceImpl.class.getResourceAsStream("/invoices/invoice.jrxml"); InputStream taskTableJasper = InvoiceGeneratorServiceImpl.class.getResourceAsStream("/invoices/invoice_sub.jrxml"); JasperDesign mainReportDesign = JRXmlLoader.load(invoiceJasper); JasperDesign tableReportDesign = JRXmlLoader.load(taskTableJasper); JasperReport report = JasperCompileManager.compileReport(mainReportDesign); JasperReport table = JasperCompileManager.compileReport(tableReportDesign); /* List to hold Items */ List<InvoiceTask> taskList = new ArrayList<>(); /* Add Items to List */ taskList.addAll(invoice.getInvoiceTasks()); /* Convert List to JRBeanCollectionDataSource */ JRBeanCollectionDataSource itemsJRBean = new JRBeanCollectionDataSource(taskList); /* Map to hold Jasper report Parameters */ Map<String, Object> taskListMap = new HashMap<String, Object>(); taskListMap.put("TasksDataSource", itemsJRBean); taskListMap.put("ADDITIONAL_COSTS", invoice.getAdditionalCosts()); mainReport = JasperFillManager.fillReport(report, invoiceMap, new JREmptyDataSource()); tableReport = JasperFillManager.fillReport(table, taskListMap, new JREmptyDataSource()); List<JasperPrint> printList = new ArrayList<>(); printList.add(mainReport); printList.add(tableReport); JRPdfExporter exporter = new JRPdfExporter(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); exporter.setExporterInput(SimpleExporterInput.getInstance(printList)); //Set as export input my list with JasperPrint s exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(byteArrayOutputStream)); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setCreatingBatchModeBookmarks(true); //add this so your bookmarks work, you may set other parameters exporter.setConfiguration(configuration); exporter.exportReport(); return byteArrayOutputStream.toByteArray(); } catch (JRException e) { e.printStackTrace(); } return new byte[0]; }[/code]
  3. Hi, I have a code like this: mainReport = JasperFillManager.fillReport(report, invoiceMap, new JREmptyDataSource());tableReport = JasperFillManager.fillReport(table, taskListMap, new JREmptyDataSource());List<JasperPrint> printList = new ArrayList<>();printList.add(mainReport);printList.add(tableReport);JRPdfExporter exporter = new JRPdfExporter();ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();exporter.setExporterInput(SimpleExporterInput.getInstance(printList)); //Set as export input my list with JasperPrint sexporter.setExporterOutput(new SimpleOutputStreamExporterOutput(System.getProperty("user.home") + "/output.pdf")); //or any other out streaamSimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();configuration.setCreatingBatchModeBookmarks(true); //add this so your bookmarks work, you may set other parametersexporter.setConfiguration(configuration);exporter.exportReport();[/code]But it is exporting the report to a file. I need to change this code so it is returning a byte[] so I can make an rest service endpoint to download the file... But I don't seem to find a method to do this...
  4. I have solved the problem with exporting from the Jaspersoft Studio by adding the font path in Window->Preferences->Fonts. The problem with Java-side was simple to solve, I have found out that I have to select used fonts from Window-Preferences-Fonts and export them as a Jar (as fonts.jar), and add them to my classpath. I am using Gradle so i have created a libs directory in the root folder of the project, and the configuration looks like this: build.gradle: dependencies { ... compile files('libs/fonts.jar') ...}[/code]
  5. Hi, I have a problem with my JRXML file created in Jaspersoft Studio. When I'm previewing the file in Studio, or when I'm using the Java class JasperViewer - everything looks PERFECT, exactly as in the Report Design view. But when I am trying to export it to the PDF file like this: InputStream invoiceJasper = MainJasper.class.getResourceAsStream("/invoices/invoice.jrxml");InputStream taskTableJasper = MainJasper.class.getResourceAsStream("/invoices/invoice_sub.jrxml");JasperDesign mainReportDesign = JRXmlLoader.load(invoiceJasper);JasperDesign tableReportDesign = JRXmlLoader.load(taskTableJasper);JasperReport report = JasperCompileManager.compileReport(mainReportDesign);JasperReport table = JasperCompileManager.compileReport(tableReportDesign);mainReport = JasperFillManager.fillReport(report, map, new JREmptyDataSource());tableReport = JasperFillManager.fillReport(table, map, new JREmptyDataSource());List<JasperPrint> printList = new ArrayList<>();printList.add(mainReport);printList.add(tableReport);JRPdfExporter exporter = new JRPdfExporter();exporter.setExporterInput(SimpleExporterInput.getInstance(printList)); //Set as export input my list with JasperPrint sexporter.setExporterOutput(new SimpleOutputStreamExporterOutput("/home/znitecki/output.pdf")); //or any other out streaamSimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();configuration.setCreatingBatchModeBookmarks(true); //add this so your bookmarks work, you may set other parametersexporter.setConfiguration(configuration);exporter.exportReport();[/code]Everything is falling apart. The main design remains intact, but the font setting is lost (In the designer I am using Times New Roman font), and almost all the polish characters used in text (ąłęćźż) are missing. They just dissapear, when I have a word: BĘDĄCYCH, all that remains in the PDF file is BDCYCH. It also looses any styling (i have a few places where I am using markup = html, and the bold text is no longer bold...) THE SAME THING happens when I am trying to export the PDF file FROM Jaspersoft Studio. A regular preview is 100% correct with correct fonts and polish characters, but the export function looses all the fonts and html styling too. I am working on UBUNTU 18.04, I have the ubuntu-restricted-extras package installed... Am I missing something in my operating system? or in the Jaspersoft Studio configuration? Or the JRXML file configuration? Or something in the JAVA code?
  6. Hi, I have an existing jrxml document in iReport Designer, which is horizontal, and I need to add another page, which has to be vertical, to this existing document. Is this possible? Can I do it in one document? Or is it somehow possible to make separate jrxml document and then join both documents using Java (I am generating the documents inside a Java application)?
×
×
  • Create New...