I am using C# winform reportviewer 2010.
I changed the default option to view reports to Print Layout (Whole page) with SetDisplayMode(). However since Whole Page is the default zoom option for print layout, even if I set the ZoomMode to PageWidth in the designer,when the report loads, it resets to Whole page. Is it possible to programatically set the ZoomMode to Page width after setting the displayMode?
Thanks
reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
Nevermind, I figured zoomMode could be set this way:
this.reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
Maybe you can do like this:
Fill all report parameters
Then you refresh your report in order to show your data
myReport.RefreshReport();
Finally set this properties
myReport.ZoomMode = ZoomMode.Percent;
myReport.ZoomPercent = 100;
I hope it helps you.
After refresh your rdlc report write
my_Report.ZoomMode = ZoomMode.PageWidth;
my_Report.ZoomMode = ZoomMode.FullPage;
my_Report.ZoomMode = ZoomMode.Percent;
After
reportViewer1.RefreshReport();
you can add
reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
reportViewer1.ZoomMode=ZoomMode.PageWidth;
Related
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
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.
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!
I have Visual Studio 2010 Enterprise.
Here is my code that works perfectly for all other things but it does not change margins at runtime. Even if the value of objRpt.PrintOptions.PageMargins.leftMargin, rightmargin, etc. are being changed, it doesn't reflect in CrystalReportViewer nor in Hardcopy output.
Here is the code:
CrystalReport1 objRpt;
objRpt = new CrystalReport1();
adepter.Fill(Ds, "Customer");
objRpt.SetDataSource(Ds);
MessageBox.Show("Left margin:"+objRpt.PrintOptions.PageMargins.leftMargin.ToString()); //Here it shows 1440
objRpt.PrintOptions.PrinterName = "HP LaserJet 1020";
PageMargins margins = objRpt.PrintOptions.PageMargins;
margins.bottomMargin = 350;
margins.leftMargin = 350;
margins.rightMargin = 350;
margins.topMargin = 350;
objRpt.PrintOptions.ApplyPageMargins(margins);
MessageBox.Show("Left margin:"+objRpt.PrintOptions.PageMargins.leftMargin.ToString());
//Here it shows 350 BUT no use.
I managed to set the margins at design time by right clicking on Report>Design>Page Setup. If I set here, margins work perfectly and they reflect in both reportviewer and hardcopy. But this does not happen when I use above code.
From doing a bit of digging, it seems as though Crystal Reports margin settings are overwritten by the default printer settings when using the Crystal Reports Viewer (at least for the Crystal Reports Viewer in a windows form and clicking the Print button on the top of the report viewer). A possible workaround for this is to use your own print button and call PrintToPrinter, which respects your own margin settings. Other workarounds include:
- Editing the report with the necessary blank space to imitate a margin
- Intercept the printing call and adjust the margins then (I can't remember the name of the function call off the top of my head)
- Set the default printer for the report to "No Printer". When selecting a printer from the Report Viewer, it should then apply the default printer settings then.
I ran into this issue when working on an application to print out ID cards. Calling PrintToPrinter() would not force a margin in the cards, which what was wanted. Running it through the Report Viewer, and clicking the print button there would force it to use the printer's default settings - with a margin of 0.17" or so. The result was cards that wouldn't print properly.
I have a report in SSRS that contains 12 subreports. After each subreport, I need to insert a page break so that each subreport starts on a new page and doesn't share pages with the other subreports. Does anyone know how to do this? Thanks
I found an answer. Use a Rectangle at the bottom of each SubReport after all Tablixes and other rendering Objects. Then set its "PageBreak" property to "End". When the SubReport is finished with the Tablix and/or other data objects, the Rectangle forces a page break. Also, a cool feature, if the SubReport returns no rows of data, the page break is not rendered. Therefore, no extra page breaks
Another solution would be to have the subreports placed inside the rectangles. I would imagine this would help you to better control and organize the layout of the report.
I tried the other answer here but my master report is driven by a dataset so didn't quite work out. This is how I got it to work for me:
1) I put the subreports into different rows on top of same size rectangles inside a Tablix with all the rows belonging to the same row group.
2) I then selected properties of the group, then pagebreak and checked the property pagebreak on between each instance of group.
Just use the "Add page break after" on the General tab of Tablix Properties.
I came across the same kind of issue but I was able to overcome by below mentioned way.
I created a sub report and placed rectangle inside the sub report (page break option checked before) and placed all my sub report content inside the rectangle. This page break works only if the sub report renders any data if not they will be no page break.
I have made Many reports with a front Page Summary and Page 2 with the Detail.
Use the Tablix for the Page Break
Tablix > Properties > PageBreak > BreakLocation > Start / End / ......
Like other answers mention, I used the "Page break before" option on rectangles/tables, but for some reason it would only break the page if it wasn't at the very top of the (sub)report