Set height and width dynamically for page/section in crystal report - crystal-reports

I am using crystal report for printing details. I have two issues while printing.
Set height/width dynamically for section details
I want to change the height and width for the section dynamically through code. This height and width will come from user settings so I need those to be dynamic. When I checked, there is a option to set the section height programmatically but its not working. I am using the below code to set the section height
ReportDocument rd = new ReportDocument();
Section section = rd.ReportDefinition.Sections["Section3"];
section.Height = 1;
When I use this code, it gives me error "System.Runtime.InteropServices.COMException: The section height is not valid."
I also want to set "Gap Between Details" dynamically. Is it possible?
Set page content height dynamically
I want to set the page content height dynamically. We can set the page height and width from Design -> Page setup -> Page options -> Set Horizontal and Vertical values.
What is happening in my case is, I am using crystal report tp print barcodes. When the page height is big, it prints empty barcodes which I dont want. I want to set the page content height based on the number of barcodes I am going to print. How can I do this?
Can anybody help me solve these two issues?

I was finding how to resolve this question. For me, this works:
ReportDocument rd = new ReportDocument();
rd.ReportDefinition.Sections["Section5"].Height = 1000;
Try this, ok?

I added a formula field called AutoHeight and a parameter field called Height then I put this code inside the formula:
Local StringVar height = "";
Local NumberVar i;
For i:=1 to {?#Margin} do (
height := height + Chr(10)+Chr(13)
);
height
The final step is to place my AutoHeight formula in the section I want to control with the property Can grow checked

Related

Eureka form, TextAreaRow auto height

Can I configure a TextAreaRow of an Eureka form to fill the available vertical space?
I will have just a few rows above and toolbar at the bottom.
You will have to play with textAreaHeight property values by setting up it initial height depending on device and available bottom space. Check out this pull request https://github.com/xmartlabs/Eureka/pull/416/files to see how it works.
You need to use textAreaHeight attribute to change the height dynamically
using .dynamic(with initial height value).
<<< TextAreaRow(){
$0.tag = tag
$0.placeholder = "PlaceHolder"
$0.textAreaHeight = .dynamic(initialTextViewHeight: 96)
}

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.

How to reduce space in crystal report detail section?

I have a crystal report. In that I need to reduce much more space in detail section. how to do that?
I tried suppress method.but again it showing same problem. how to solve this ?
Here is my crstal report design and output samples
Here is output sample
while taking print it is showing more space . after first report entry , it is showing more space. indicated using next report in red line.
Here are a few ways:
align the top edge of each item to the top edge of each section
make the height of each item in each section equal to the height of the shortest item in that section; if you need any field to grow, toggle its 'can grow' property to checked
set each section's height to match the height of its tallest field
delete or suppress PageHeaderSection4 and ReportFooterSection2
does the Supplier ID and associated field need to be in its own section?

Switching page orientation in ireport

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!

How to stretch a text field relative to data width in Jasper Reports

I have a text field followed by a static text field and I am trying to do 2 things with it:
Get the text field to stretch horizontally (not wrap) when text is longer then the field width and
Push the static text field right when the text field to the left of it stretches
Both of the fields are contained within a frame.
I have both fields set to positionType=float and the text field set to stretchWithOverflow=true, which enable text to wrap vertically but not stretch horizontally.
Is it possible to achieve 1 and 2 above? If so How?
Instead of having 2 text fields (dynamic and static), you can have 1 text field with value as $F{Field} + "statix text". This will probably fix your issue. Also, you can set the "width" and "stretch with overflow" properties, as per your requirements.
Well it's bad news!! According to Jaspersoft's documentation on stretching fields it is not possible to stretch the width of a field:
"Usually, the stretching process refers to the height adjustment only.
When stretching report elements, adjusting the width could affect also
the page width and raise unexpected errors at runtime (for instance,
truncated information could be printed out on pages). This is why
stretching an element let its width unchanged, while its height gets
definitely enlarged in order to make room for all information that
have to be displayed." (Jaspersoft documentation [v4.5.0], 2011)
However a solution to the original issue can be found here thanks to #mdahlman
Just select text field and from its textfield properties choose "stretch with overflow" and it will change its height dynamically according to text .enter image description here