I created a report page with A4 format in iReport4.5 and use in java application.
how to change A4 to A5 format on runtime in java application?
Before I show you how to do this, please note that just changing the Page Size is probably not going to give you what your want. It will make the page larger or smaller depending on what you want, put the positioning of elements will not change. IN your case the report may not even compile depending on where you have items laid out.
You do have a couple options though:
First you could create a second report for the A5 format, and then
at run time grab the appropriate report depending on what you want.
This is probably the easiest solution, but it does mean you end up
with almost 2 identical reports. Meaning any changes in the future
you would have to do in two places.
Second if it is a fairly straight forward report with a typical
layout you could use something like Dynamic Jasper to generate your
report in java code.
Lastly you could work directly against the Jasper Report's API to
generate your report at run time.
Now to answer your question. First load up the JRXml file into a JasperDesign object:
//Note JRXMLLoader could also take a File object or
//InputStream instead of a String as the parameter.
JasperDesign design = JRXmlLoader.load("report.jrxml");
Once you have the JasperDesign you can set the page size to what ever you want. A5 paper from what I can tell is 5.83" × 8.27". To convert this to a size that JasperReports understands multiply each by 72, getting you 420 x 596 (I rounded as we have to set Integers).
design.setPageHeight(596);
design.setPageWidth(420);
From there you cointinue on your exporting adventure as you normally would.
Related
Starting with an apology if I am breaking some process here.
I am aware that there is a question with exactly the same problem
PDFBox returns missing descendant font dictionary but the thread ends abruptly because the author wasn't able to give the details, unfortunately. Also due to low reputation wasn't able to continue that thread.
And it very well states the problem of missing composite font. I wanted to know if there is some way to fix it since the PDF opens fine in our browser but we are not able to deal with it programmatically.
Tried it on some variety of versions including the latest 2.0.21
I will share the PDF
Looking forward to you
#mkl, #Tilman Hausherr
Please let me know if you need more details.
My code trying to convert the PDF to images
PDDocument document = PDDocument.load(new File(pdfPath+"//"+fileName));
PDFRenderer pdfRenderer = new PDFRenderer(document);
for (int page = 0; page < document.getNumberOfPages(); ++page) {
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
}
Having downloaded the file when the link was available, I analyzed it.
Adobe Acrobat Reader shows error messages when opening the document. iText RUPS reports cross reference issues. First impression, therefore: That PDF is broken.
Nonetheless I looked closer but the result of that closer look was not better...
According to the cross references and trailers the PDF should contain 58 indirect objects with IDs 1 through 58. It turned out, though, that objects 32 through 49 are missing albeit most of them are referenced, some as descendant fonts. This explains why PDFBox reports missing descendant fonts.
Furthermore, objects 50 through 57 and 1 through 10 are not at the locations they should be according to the cross reference tables. Also the second cross reference table is at a wrong location and the file length is incorrect according to the linearization dictionary.
The way this is broken leaves the impression that the file is a mix of two slightly different versions of the same file; as if a download of the file was attempted but interrupted at some point and continued from a new version of the file; or as if some PDF processor somehow changed the file and tried to save the changed copy into the same file but was interrupted.
Summarized: The PDF is utterly broken.
If a PDF processor tries to repair it, you cannot be sure information from which version of the file you'll get, different PDF processors (if they can somehow make sense of it) are likely to interpret the file differently.
If possible, you should reject the file and request a non-broken version of it.
If not possible, copy the data from a viewer that appears to best repair it, manually check the copy for accuracy, and then check the whole extracted data for plausibility in regard to other information you have on the accounts in question. A little prayer won't hurt either.
I don't know if "cutting" is the right term...
I've got to finish doing a large and complex report based on an Applet legacy system, a fellow and I decided trying reuse all the logic in the applet to avoid the complexity of doing a lot of sub-reports. What we did was copy all the logic in the applet that include a lot of condictionals/SQL and make a huge and properly formated String, so that in our Jasper file it would just have a method called "myVo.getBody()" besides the header and footer stuff.
Unfortunately we found out a problem that some part of text get lost between pages. I think that as the text get bigger and reach Jasper page limit for some reason it keeps being writed in a "no visible area" and when the next page content starts some part was lost.
For example, there is a list of 19 items and what happens is:
End of 2nd page
1 - item
2 - item
beggining of 3rd page
18th - item
19th - item
Items from 3 to 17 are not being showed.
Is there any Jasper configuration for this situation?
We tried:
Position type: Fix Relative to the Top and Float
Stretch Type: Relative to the Tallers Object and Relative to Band Height
Stretch With Overflot: true or false
I don't think showing Java code would be useful as it just use a StringBuffer to build the String, put it on body property in a PreparedDocumentVO so that Jasper model can consumes it. It seems to be some Jasper setting, or the idea of creating a huge String is not so good as we thought.
I would consider breaking the result up.
Jasper formats information based on a relative page size. This means that at some point in time, when dealing with information that is not likely to fit on a page, Jasper will probably make an assumption that doesn't hold (and your data will likely not be formatted into the page).
If you have an exceptionally long string, consider splitting it up. Besides, people scroll web pages down, not the side, so a heavy side-scrolling document is likely to cause user issues unless every record scrolls to the side just as heavily.
I'm creating Web App using Java,And one of the tasks is to print a report to the customer.The problem is that the paper design is already made and putted in the actual printer and I must only fill the blank fields.The questions are :
1) how can I print the values exactly in the fields ?
2) Is there a way to simulate this process without having physical printer, like using virtual printer and upload the default page to it ?
I attached part of the paper that will be in the printer and I should fill the blank fields with data comes from JSF page.
I solved the problem like yours in the past. My company has a pre-designed printed invoice. My task is to put the data into the blanks in place. In my experience, you should:
Scan the paper into an image with the same size as the physical version.
Measure the distance from a blank to another.
Specify the location of the blanks to output the data based on your measurement.
You can use the digitalized version as the background of the output page and test on it.
Try to put the first blank in place.
Test and adjust your code.
Hope it helps.
If the things that are there in the page only in the soft copy you can do one thing. Design a A4 exactly the same way you have on the printed page. Then write down variables in the places where you would like to fill up from your java program. That docx file will act as the template. After that, replace those texts with the actual values from the Java program in that template. All these can be done with docx4j api.
A code block like this will be useful :
if (textElement.getValue().contains(placeholder)) {
String temp = textElement.getValue();
temp = temp.replace(placeholder, name);
textElement.setValue(temp);
return;
}
This is how we do it our project. If you need more help, let me know.
I have a PDF file, which contains a table of content, where each entry links to a page in the file.
How shall I program in Python or Java (or some other languages) to extract the table of content in the following form:
entry1 PageNumberEntry1LinkedTo
entry2 PageNumberEntry2LinkedTo
...
e.g.
Section 2.6. Argument Arrays 2
Section 2.7. Thread-Safe Functions 2
(If they can be extracted in some tree data structure according to the structure of table of content, that would be even better, but this can be skipped if not possible.)
I would like to get some help about what Python or Java modules and functions can be used to accomplish that? Such as PDFMiner or pypdf2 in Python, iText in IPython or Java, ...?
I have examined your file and it looks very strange.
See the following screenshot:
I used iText RUPS to take a look at the root of the page tree. You probably know that a page in PDF isn't aware of its page number. The page number of a page is determined by the position of the page in the page tree.
In the screen shot, you see part of the page dictionary (object 3) of Page 1 (it's page 1 because 3 0 R is the first element in the /Kids array).
I have opened the array with the annotations, and I see a link annotation with a /GoTo action. This action tells a PDF viewer to jump to the page of which the page dictionary is object number 58.
When we examine the page tree (which is actually nothing more than a single branch without any leaves), we see that 58 0 R refers to page 2 (the second item in the page tree).
However, this can't be right, can it? Page 2 just contains another part of the TOC, so I don't think the links are correct.
It looks as if you created your PDF based on a web page, because I see a /PA entry that refers to an HTML page.
Long story short:
You need to loop over all the annotations in each page and look for /Link annotations. You then have to examine the value of the action (/A). This will give you the object ID of the page you're looking for.
As for the text: obviously, the text is not stored in the annotation. For the link shown in the screen shot, you'll have to search for the text inside the rectangle [107.2 754.3 235.6 763.6]. That's not impossible, but it's not always trivial.
Your question is a project that requires a couple of days of work. If you want a working example, take into account that you're asking people to contribute more than just a couple of hours of their time.
In our project, report generation can take a very long time. Is there a way to obtain number of generated pages while the document is processed?
Simple progress bar is not enough, we need to show users that something is really happening.
XDocReport doesn't provide a kind of progress monitor. I think this idea could be interesting, please create an issue for that.
It should be interesting too to know where report generation can take a very long time. The report process is :
generate docx (or odt) from a docx (or odt) template. Is this step takes time? If it takes time, I think you don't use XDocReport cache (retrieve the report from the registry instead of loading very time the docx/odt template)
convert the generated docx to PDF. I think this step can takes time. For that, I'm afraid that you cannot improve performance.
The progress monitor could track step 1 and 2:
for step 1 you cannot know the page because docx doesn't contain information about page.
for step 2 I think we could track PDF page if you use our POI/iText converter that we will able to modify to support progress monitor.