Is it possible to shrink a grid's width so it will fit the paper size specified during an export?
Hello Kenneth,
Could you please give us more details about your scenario to export the grid in PDF file, because there are few different approaches.
Option 1: using ultraGridDocumentExporter1:
In this case you could set AutoSize = SizeColumnsandRowsToContent property
Option 2: using Documents.Report:
In this case you could modify the settings below :
report.Preferences.Printing.PaperSize = Infragistics.Documents.Reports.Report.Preferences.Printing.PaperSize.Auto;
report.Preferences.Printing.PaperOrientation = Infragistics.Documents.Reports.Report.Preferences.Printing.PaperOrientation.Auto;
report.Preferences.Printing.FitToMargins = true;
Infragistics.Documents.Reports.Report.Grid.IGridColumn column = grid.AddColumn();
column.Width =new Infragistics.Documents.Reports.Report.RelativeWidth(20);
column = grid.AddColumn();
column.Width =new Infragistics.Documents.Reports.Report.FixedWidth(100);
Option 3: using UltraGirdPrintDocument:
In this case you could try to set
ultraGridPrintDocument1.FitWidthToPages = 1;
Let me know if you have any questions.
This is a code snippet that does all the heavy lifting. As you can see I'm setting both the exporter AutoSize property and the report FitToMargins property and I continue to get the columns that do not fit on the page cut off. Please advise.
public void Export() { if (grid == null) throw new ArgumentNullException("grid"); if (pageSettings == null) throw new ArgumentNullException("pageSettings"); report = new Report(); report.Preferences.Printing.FitToMargins = true; SetupReportInfo(report); ISection section = SetupDefaultSection(report); SetupHeader(section); SetupFooter(section); using (var exporter = new UltraGridDocumentExporter()) { // Make sure we export the grid in the same orientation as the report if(pageSettings.Landscape) exporter.TargetPaperOrientation = PageOrientation.Landscape; else exporter.TargetPaperOrientation = PageOrientation.Portrait; exporter.TargetPaperSize = GetPageSize(pageSettings.PaperSize.Kind.ToString()); // This translates the MS PaperSize to the Infragistics PaperSize exporter.AutoSize = AutoSize.SizeColumnsAndRowsToContent; // this shrinks the grids and columns to the size of the content exporter.UseFileBuffer = true; exporter.Export(grid, section); } report.Publish(filename, FileFormat.PDF); OpenReport(filename); }
I made a test using all available option in Infragistics.Documents.Reports.Report.PageSizes. and for me everything seems to works properly. The PDF files has different size according settings in PageSize
- ultraGridDocumentExporter1.TargetPaperSize = Infragistics.Documents.Reports.Report.PageSizes.Letter;
- ultraGridDocumentExporter1.TargetPaperSize = Infragistics.Documents.Reports.Report.PageSizes. Tabloid;
- ultraGridDocumentExporter1.TargetPaperSize = Infragistics.Documents.Reports.Report.PageSizes.Quarto;
- ultraGridDocumentExporter1.TargetPaperSize = Infragistics.Documents.Reports.Report.PageSizes.A3;
The results are in attached screenshot. Let me know if you have any questions.
Thank you for that sample, however when I run it I find the page is much larger than the letter size than I specified.
I changed the following code in your example:
//ultraGridDocumentExporter1.TargetPaperSize = new Infragistics.Documents.Reports.Report.PageSize(ultraGridPrintDocument1.DefaultPageSettings.PaperSize.Width, ultraGridPrintDocument1.DefaultPageSettings.PaperSize.Height);
ultraGridDocumentExporter1.TargetPaperSize = Infragistics.Documents.Reports.Report.PageSizes.Letter;
It didn't make any difference when I exported to PDF. The page size reported by Adobe Reader was still 23.61 X 28.85 inches.
I have opened a help desk case CAS-131527-Q1W7G8 regarding this issue.
Here is the sample
Thanks for attached code. I try to reproduce the issue using your code, but without success. Could you please tell me what is your current version and do you have any installed service release and which exactly. Meanwhile I made small sample for you. Please take a look on attached sample and video file for more details and if you think that I didn`t reproduce your scenario, feel free to modify this sample to reproduce your issue and revert it back to me. I`ll be glad to research it for you.