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

Problems with loading data to PDF/HTML from XML


llokk2007
Go to solution Solved by abhimanyu.prasad,

Recommended Posts

Hello, I need some help:)
I try to make pdf/html file from XML file

in pdf I can see names of colomns, but in nodes: NULL NULL NULL NULL
what can I do?
p.s. sorry for my English)))

my code:

//so datasource is a way to XML file, xpath = "XPath", template is a way to .jrxml file, resultpath - name of report file(ends with .pdf or .html)

public static void printpdfhtml(String datasource, String xpath, String template, String resultpath)
        {
            try
            {
                
                
                JRXmlDataSource ds = new JRXmlDataSource(datasource);
                            
                JasperReport jasperReport = JasperCompileManager.compileReport(template);
               
                JasperPrint print = JasperFillManager.fillReport(jasperReport, new HashMap(), ds);
                if(resultpath.toLowerCase().endsWith("pdf"))
        
                    JasperExportManager.exportReportToPdfFile(print, resultpath);
          

                     else JasperExportManager.exportReportToHtmlFile(print, resultpath);
               
            }
            catch (JRException e)
            {
                log.info("Исключительная ситуация",e);
                e.printStackTrace();
            }
        }

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

Hi llokk2007,

Modify your code flow to something like below:

JasperDesign jasperDesign = JRXmlLoader.load(sourceFileName);JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);JRXmlDataSource xmlDataSource = new JRXmlDataSource(inputStream, jasperReport.getQuery().getText());JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, xmlDataSource);JasperExportManager.exportReportToPdfFile(jasperPrint, resultpath);[/code]

If you are good with your jrxml, then this will definitely do it for you. Let me know if you still face the same issue.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...