Switching page orientation in ireport - jasper-reports

I've read there's no way to handle mixed orientations natively using iReport, however reading the documentation I wonder if by using JRDefaultScriptlet's beforePageInit() it could be accomplished somehow. In my case there's a portrait front page, as many landscape pages as there's data to populate them, and a last frontal page.
On the other hand does anybody know:
If this is a feature to be supported in the near futureIf there's an alternative that does as requested and generates a jasper-compliant xml file
Thanks in advance.

So I decided to play around with iReport and see what options there where for this. Turns out it is sort of possible to pull off, with some effort and imagination. This is assuming your first page is in the Title Section, and your Last Page is in the summary section.
Create your report in landscape mode.
Under Report Properties in iReport set Title on New Page and Summary on New Page to true.
Assuming you are using a standard 8.5" X 11" Letter sized page with all the margins set to 20, set the height of the Title and Summary sections to 572.
Add your static text fields into the appropriate section.
Now for each static text field you need to set the Rotate property to Left (well it could actually be Right, the point is they all need to be the same.
Of course add the all the other fields you want into the appropriate bands for page header, data, etc.
Export your report.
Note: if you have any images that need to go into the Title or Summary Section your will need to rotate them appropriately outside of iReport and save it. Then set the rotated image as the image in the report. Unfortunately the image tag does not seem to have a rotate property, as that would make life to easy.
Also if you do not set the properties listed in step 2 you will not be able to set the height of the Title and Summary bands to the appropriate width. If you are using a different size paper and/or
margins the easy way to figure out the max size (which is what you will need) is to set the height of the band to a very large number. It will then popup and tell you it is to large, and what the max size actually is.

There is no support to mixed landscape and portrait subreport, in the future they will add an object call JasperBook or something like that where you can add different subreports of different orientations without problems, but for the moment you have simulate that by doing different reports and join them just before showing them.
I.E.
//Create the reports separately
InputStream report1 = (InputStream) getClass().getResourceAsStream("/com/app/jasper/reportPortrait.jasper");
InputStream report2 = (InputStream) getClass().getResourceAsStream("/com/app/jasper/reportLandscape.jasper");
InputStream report3 = (InputStream) getClass().getResourceAsStream("/com/app/jasper/reportPortrait.jasper");
JasperPrint jasperPrint = JasperFillManager.fillReport(report, map, conn);
JasperPrint jasperPrint2 = JasperFillManager.fillReport(report2, map, conn);
JasperPrint jasperPrint3 = JasperFillManager.fillReport(report3, map, conn);
JRPdfExporter exp = new JRPdfExporter();
//Add the JasperPrint objects to an ArrayList
List list = new ArrayList();
list.add(jasperPrint);
list.add( jasperPrint2 );
list.add(jasperPrint3);
//And say to the exporter to join the list of reports.
exp.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, list);
exp.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
exp.exportReport();
I'm doing that in my reports and it works. Good luck!

Related

how to set width of the report dynamically in ireport based on number of columns

Can i set the jrxml report width according to the data it contains. That means is there any option to shrink or expand the report size according to the data.
i have created maximum of 15 columns for report and hiding/showing needed columns based on the input. reports columns getting hide but the page width remains the same,.
Anyone shed some light,. thanks in advance.
Finally i got the solution,..
We can set the jrxml page width to maximum (say 1500) for 15 columns while design.
And we can show/print the needed colums alone (say 10) based on user reports.
We can set the page width at the run time using jasperprint.setPageWidth()
I have achieved this way,...
InputStream stream = ReportServlet.class.getResourceAsStream(file_location);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(data);
jasperReport = JasperCompileManager.compileReport(stream);
jasperPrint = JasperFillManager.fillReport(jasperReport, hashMap,ds);
int noOfColumns = 10;
jasperPrint.setPageWidth(noOfColumns * 100);
I never set up this feature, but i would have try to to look at the Print When Expression property.
A good start is to look at the documentation iReport Ultimate Guide : http://community.jaspersoft.com/documentation, page 60.

JasperReports: Multiple sub-reports inside a master-report

I would desperately need some help to achieve the following:
Create a master-report.jrxml, which includes a table of content and the corresponding sub-reports
These sub-reports all contain a different chart with different data query, which can be bigger than one page
Every page which includes a sub-report must show some static frame with dynamic content like the current sub-report's name and page X of Y
My approach so far was, to create a sub-report.jrxml for each of my required charts (I put chart in the sub-report's summary band). Then I created a MasterReport.jrxml with my static frame which included the sub-reports in the summary band. I expected/hoped that JasperReport would render a the according sub-report after each other, but it just overdraws on the same page.
How can I configure my report, to display the sub-reports after each other on new pages?
Any help with this, would be highly appreciated.
Try with subReports in a detail band and subRepport element has "Run to bottom" property which, if set to true, will make subReport take the whole page and push next item on a new page. There is also a page break element in JasperReports if "Run to bottom" doesn't work for you . For static content on each page use page header/footer bands.

Text not fitting into form fields (iTextSharp)

I created a .PDF file using Adobe Acrobat Pro. The file has several text fields. Using iTextSharp, I'm able to populate all the fields and mail out the .PDF.
One thing is bugging me - some of the next will not "fit" in the textbox. In Adobe, if I type more that the allocated height, the scroll bar kicks in - this happens when font size is NOT set to auto and multi-line is allowed.
However, when I attempt to set the following properties:
//qSize is float and set to 15;
//auto size of font is not being set here.
pdfFormFields.SetFieldProperty("notification_desc", "textsize", qSize, null);
// set multiline
pdfFormFields.SetFieldProperty("notification_desc", "setfflags", PdfFormField.FF_MULTILINE, null);
//fill the field
pdfFormFields.SetField("notification_desc", complaintinfo.OWNER_DESC);
However upon compilation and after stamping, the scroll bar does not appear in the final .PDF.
I'm not sure if this is the right thing to do. I'm thinking that perhaps I should create a table and flood it with the the text but the documentation makes little or no reference to scroll bars....
When you flatten a document, you remove all interactivity. Expecting working scroll bars on a flattened form, is similar to expecting working scroll bars on printed paper. That's why you don't get a lot of response to your question: it's kind of absurd.
When you fill out a rectangle with text, all text that doesn't fit will be omitted. That's why some people set the font size to 0. In this case, the font size will be adapted to make the text fit. I don't know if that's an option for you as you clearly state that the font size must be 15 pt.
If you can't change the font size, you shouldn't expect the AcroForm form field to adapt itself to the content. ISO-32000-1 is clear about that: the coordinates of a text field are fixed.
Your only alternative is to take control over how iText should fill the field. I made an example showing how to do this in the context of my book: MovieAds.java/MovieAds.cs. In this example, I ask the field for its coordinates:
AcroFields.FieldPosition f = form.GetFieldPositions(TEXT)[0];
This object gives you the page number f.page and a Rectangle f.position. You can use these variables in combination with ColumnText to add the content exactly the way you want to (and to check if all content has been added).
I hope you understand that:
it's only normal that there are no scroll bars on a flattened form,
the standard way of filling out fields clips content that doesn't fit,
you need to do more programming if you want a custom result.
For more info: please consult "iText in Action - Second Edition".

Is it possible to "shrink" a PdfPtable?

I am currently working with Itextsharp and I have some trouble with PDfPtables.
Sometimes they get too big for a page and, when added to a document, are broken up on multiple pages.
Sadly ths rational behviour is not acceptable for some of my superiors - they keep insisting that the table shall be "shrunk" to a page. Is there a way to achieve this? There are some tantalizing hints that i could be possible - but hints are all that i have.
What is the alternative? Perhaps I could delete the fat table from the document and build the table again with smaller Fonts and Cells, but that would be very cumberosme - I would prefer to "zoom out", in lack of a better word.
My current code:
Dim test As PdfContentByte = mywriter.DirectContent
Dim templ = test.CreateTemplate(mywriter.PageSize.Width, mywriter.PageSize.Height)
Table.WriteSelectedRows(0, Table.Rows.Count - 1, 0.0F, mywriter.PageSize.Height, templ)
Dim myimage = Image.GetInstance(templ)
' myimage.ScaleAbsolute(mywriter.PageSize.Width, mywriter.PageSize.Height)
would scaleabsolute be necessary?
myimage.SetAbsolutePosition(0, 0)
test.AddImage(myimage)
This code puts something one the page, but it has the height of the page and the width is about a quarter of the page - wi will try to find the bug...
Create the table and define a 'total width'. As soon as iText knows the width of the table, you can calculate the height of all the rows. Once you know the height, you can check:
Does the table fit the page? Just add it as is. Maybe using WriteSelectedRows if you don't want to take any page margins into account.
Isn't there enough space on the page? Add the table to a PdfTemplate (there's more than one way to do this), wrap the PdfTemplate inside an Image. Scale the image, and add it to the document.

How to create single PDF document with both portrait and landscape page using iTextSharp

I have been able to create portrait pages, and landscape pages in separate documents, but now require to do this in one document. I am using ITextSharp library and the document.setpagesize seems to apply to all pages. Is this correct?
I was using PDFLib and changing page orientation was not a problem in that library.
Any suggestions?
Paul.
It should only apply to pages rendered after that call.
Document doc = new Document(PageSize.WHAT_EVER);
PdfWriter writer = new PdfWriter( doc, outputStream );
doc.open();
// so long as you set the page size before add()ing anything, it should ignore the
// page sized used in the constructor.
doc.setPageSize(PageSize.LETTER); // 8.5" x 11"
// actually, I think you need to call newPage or actually add enough stuff to start a new page
// for setPageSize to take effect. setPageSize by itself won't do the trick.
doc.add(stuffToFillALetterPageButNotStartANewOne);
doc.setPageSize(new Rectangle(792f, 612f)); // 11" x 8.5"
doc.add(moreStuffToFillALandscapePageThusStartingANewPage);
doc.close();
The resulting PDF should have two pages. The will be 8.5x11, the other 11x8.5. Note that iText[sharp] won't generate rotated pages (8.5"x11" # 90 degrees (or 270... shudder)). It's... sharper than that.
Dealing with rotated pages is Not Fun. At least I've never run into one that was 8.5x11 at 180 rotation in my TOO_MANY_YEARS of experience with PDF. I'd just have to fly into a murderous rage at that point. Or maybe I should generate some PDFs that way just to see who I could catch with their pants down.
[insert fiendish cackle here]