My boss is killing me with the 'awesome' idea to generate Jasper report. As long as I am still alive, I have to ask experts here about how to make it happen.
The original requirement is to generate a pdf report with text and form(tables) in one page. I did it.
But the new requirement ask for a new report which contains four pages and each one contains the previous one page content, with only one change(insert different text on every page).
I did some research and didn't find a easy way to do it. So hope everyone on SO can give me a hint. Thanks a lot !
Could you hide and show columns based on expression? For example, map fields over fields in your template to account for all 4 pages, and for a given field only show data when PAGE_NUMBER = x or COLUMN_NUMBER = x.
In your query, you could create a constant to identify the page where each row of data should be printed and group on that constant.
Or -- 4 detail bands, and each is set to print only on the appropriate page.
If its the same text, then add the Text in String objects,
then you can use the same report, with different data-objects, which store the Strings for the text
Related
Good day to all. I am currently building a program that covers the review of product warranty applications. I'm doing it in javaFX using Netbeans. The program has the following scenes:
a screen where the information of each guarantee request is entered. all the information is stored in a table in a database. The interaction between the program and the database is done, in effect, through JDBC.
a screen where you can see a table that shows all the requests that have been saved. if a row is selected, a button that carries the third scene all the data of the request that was selected is enabled.
a screen where all the data of the tests that are made to the selected guarantee application are entered. The results are also stored in another table in the database.
After the application is evaluated, a warranty review report must be generated. Currently this format is generated in pdf from excel. What I want to do is that from the data results of the tests stored in the database I can dynamically generate the pdf formats from the program in javaFX. Is there a plugin to write these documents automatically? I'm good at writing texts in LaTEX, so if there is a way to generate the latex format from the program and call the necessary information from the database, it would be perfect. Thanks in advance for the help. Any indication or idea is welcome.
It seems like you have two core requirements:
Fetch data from the database suitable for reporting
Generate the report(s) in PDF from JavaFX but can fall back to LaTEX
What you really need seems like a PDF library for Java. I can suggest iText and Docmosis as good options (please note I work for Docmosis) - both are commercial for commercial products so you would have to buy.
Assuming you are using one of these libraries, the process for each report is:
execute the query to fetch the appropriate data for the report
manipulate the data if required to make the reporting stage simple
generate the report
Using iText you would write the query, the manipulation code and then the code to layout the report including the data.
Using Docmosis you would write the query, possibly some manipulation code (Docmosis can also work directly with your ResultSet) and the code to execute the report. The layout is designed in the template (Word or Libre Office Writer).
When you mention writing "these documents automatically" I assume you mean creating the PDF file format, which iText and Docmosis can do. If you mean creating the report layout itself, then you always need to design/write something to make the report do what you require.
I hope that helps.
Thank you very much for your response Paul! I had found something related to the libraries you mentioned, and indeed something like what I'm looking for. I notice that you are more in the subject. then, you do not know bookstore, preferably free, that gives me the possibility of doing the following (pseudo code):
take the row from the database
Save the information of that row in the attributes of a created class.
create text1: "the guarantee with reference" + object.attribute1 + "was not approved in view of the physical revision test indicated that" + object.attribute2 + "
create text2: "..."
...
create the text n: "..."
take text 1 and place it in the header of the pdf document
Take text 2, put it in bold and place it in the subtitle
Generate a table and fill it with the content of text 3, 4 ...
compile all information as a pdf, (word file, xls or others if possible)
I am clear that with the libraries that you recommend you can easily make items from
1 to 8, but I do not know if it is possible to enter the texts within a template created, so that the library accommodates all the texts in the respective zones of the template file. I imagine that this can easily be done with Latex, since everything is written in plain text.
I found a library called Java LaTeX Report (JLR) that allows me to do what I want. This information may be useful to someone. Thank you again for your answer Paul, if you consider the libraries that you mention do the job more easily than JLR please let me know!
I am providing the scenario as an image, which I guess would help in better understandability.
Here I have to pass object from different Swing forms and accumulate it to create a new document which will consist the concatenated texts, tables etc.
My question, is it possible to do the same.
N.B :- I am able to do simple tasks in iText - reading tables from Swing forms, etc.
Thanks, suggestions are very much appreciated.
Yes it is possible to do the same with itext. May be you can do it this way
Create document
Get Form 1 Values. Create a Chunk using the Form 1 Text.
Add the Chunk into the Document
Get Form 2 Values. Create a Chunk using Form 2 text
Add the Chunk into the Document
Like this do for all the forms.
The above is solution for adding all the text from different forms into document.
Refer Link for itext references.
If in case all the texts has to concatenated do it well ahead and add it to the Chunk.
P.S: Am not familiar with Swing framework.
i need to create a static report of 3 pages and every page contains static text and fields retrieved with a database query.
My first approach, after reading similar questions, was to create 3 separated report files (page1.jrxml, page2.jrxml and page3.jrxml) and then merge the resulting reports into a single one.
It works fine but sometimes happens that a field contains a very long string and a single file report generetes 2 pages, leading to an horrible printing because the first page is full but
the second contains one or few lines.
Can you suggest me a better approach?
Thanks
We use jrxml templates and we have only one jrxml. You do not need to have multiple files just split the static text to many DETAILS (paragraphs) and if the first page will overlap with few lines it will be inmediatelly followed by next detail.
In our app we use jasper from java and we pass the params with JasperFillManager.
We create template:
compiledTemplate = JasperCompileManager.compileReport(...);
and then we fill the variables
jasperPrint = JasperFillManager.fillReport(compiledTemplate, map with params, dto implementing JRDataSource);
and then we export it to pdf:
ret = JasperExportManager.exportReportToPdf(jasperPrint);
and thats it.
I've needed to split a report over several sheets primarily for Excel-export. It seems to be working while previewing on JasperServer also:
add report property net.sf.jasperreports.export.xls.one.page.per.sheet set to true
add property net.sf.jasperreports.export.xls.break.after.row set to true the the textfield you need a page break after (there's a similar one to break before)
Also you may name your sheets. Please see here:
http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.export.xls.one.page.per.sheet
I got a word file and I want to count how many pages are in it.
The file has been created with Docx4Java.
Anyone did this before?
Thanks!
docx4j doesn't have a page layout model, so it can't tell you a page count.
You can get an approximate page count by using FOP's page layout model. docx4j's PDF output now supports a "2 pass" generation:
first pass calculates the page count(s)
second pass generates the pdf
See https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/convert/out/fo/AbstractPlaceholderLookup.java
and
https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/convert/out/fo/ApacheFORenderer.java
So doing the first pass would give you (approximately) what you want. This uses org.apache.fop.apps.FormattingResults which records the number of pages in a page sequence, or in the document as a whole.
An alternative approach might be to use LibreOffice/OpenOffice (or Microsoft Word, for that matter).
I have built a web application that can be seen as an overcomplicated application form. There are bunch of text areas with a given character limit. After the form submission various things happen and one of them is PDF generation.
The text is queried from the DB and inserted in the PDF template created in iReports. This works fine but the major pain is overflowing text.
The maximum number of characters is set based on 'average' text. But sometimes people prefer to write with CAPS or add plenty of linefeeds to format their text. These then cause user's text to overflow the space given in PDF. Unfortunately the PDF document must look like a real application form so I cannot allow unlimited space.
What kind of approaches you have used to tackle this?
Clean/restrict user input?
Calculate the space requirement of the text based on font metrics?
Provide preview of the PDF? (too bad users are not allowed to change their input after submission...)
Ideally, calculate the requirement based on metrics. I don't know how iReports handles text, but with iText, it lays everything out itself, you just present the data as a streaming document, so we don't worry about overflowing text.
However, iReport may not support that, or you may need to have the PDF layout fit within certain bounds. I'd try to clean the input (ie: if it's all caps, lowercase/sentence case/proper case it), strip extra whitespace. If cleaning the input can't be reliably done, or people are still getting past that, I'd also restrict it.
As a last resort, I'd present the PDF for the user to authorize. Really, users shouldn't be given more work to do, and they're not going to do it anyways.
Your own suggested solutions to your problem are all good. Probably the most important question to have answered is what should your PDF look like when the data to be displayed in a field won't fit? Do you ever need the "full answer" for anything else? When you know the answer to these, you'll have your options reduced.
For example if a field must be limited to 1/2 a page, and users sometimes enter more than 1/2 a page of text you can either
1) limit the user input - on submission calculate the size (using font-metrics as you said) and reject the submission until corrected. This assumes you can legitimately force the user to reduce their data entry.
2) accept the user input and truncate in the display of this report. Some systems use "..." to indicate data has been truncated, and can provide a hyperlink (even within the PDF) to get more information.
Providing a preview would work really well, but only if the users are good at checking and correcting and your system can handle the extra load this will generate.
Do you have control of the font that is used when generating the PDF? If so, I would look for a font in the Monospace family. This will give you consistent length for a given number of chars, regardless of puncuation, capitalization, etc.