I have been trying to make the grid export to PDF in a WYSIWYG manner
I have been "almost" successful with very less code
void ultraGridDocumentExporter1_ExportStarted(object sender, Infragistics.Win.UltraWinGrid.DocumentExport.ExportStartedEventArgs e){e.Section.PageSize = PageSizes.A4;e.Section.PageMargins = new Infragistics.Documents.Reports.Report.Margins(PageMargins.Narrow.Left, PageMargins.Narrow.Right,PageMargins.Narrow.Top, PageMargins.Narrow.Bottom);e.Section.PagePaddings = new Paddings(0);e.Section.PageOrientation = Infragistics.Documents.Reports.Report.PageOrientation.Landscape;e.Section.PageAlignment = Infragistics.Documents.Reports.Report.ContentAlignment.Center;}
I get the fonts, column widths, row height correctly as seen in the grid inside of windows forms container
But the grid layout inside of PDF document does not occupy (stretch or shrink) the entire whitespace available on the PDF document (see red blocks in the attached PDF screenshot) - what am I not doing right?
Thanks!
Screenshot: https://doc-0s-44-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/8p6fggpi7eli97l0n6cojs6v6nrda7je/1423749600000/12612333493395018583/*/0B42CvR3rv2CxUjJZRGJwd25aSzA
Hi Ameya,
Thank you for posting in our forums.
After looking into this and doing some research, “Fitting the grid to one page in PDF” has been determined to be a new product idea. You can suggest new product ideas for future versions (or vote for existing ones) at <http://ideas.infragistics.com>.
There are many benefits to submitting a product idea:
- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you. You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.
Steps to create your idea:
1. Log into the Infragistics Product Idea site at http://ideas.infragistics.com (creating a new login if needed).
2. Navigate to the product / platform channel of your choice (e.g. WPF, Windows Forms, ASP.NET, HTML5 / Ignite UI, iOS / NucliOS, etc.)
3. Add your product idea and be sure to be specific and provide as much detail as possible.
The Product Idea site puts you in the driver’s seat and allows you to track the progress of your ideas at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Thank you for contacting Infragistics.
Hi Dimitar
Actually, I am able to fit the grid to 1 page wide and n pages in height - that works and does not need any new feature development
My problem is slightly different
While my grid layout inside the PDF has fit to 1 page wide, its not wide enough to fill the entire A4 page size in landscape - the grid in the PDF has about 200 floating points margins on left and right (blank space) - even though I have explicitly set the page + section margins to ZERO
Link to the screenshot image: https://drive.google.com/open?id=0B42CvR3rv2CxUjJZRGJwd25aSzA&authuser=0
Thank you!
-
The way the DocumentExporter works is that it clones the DisplayLayout of the grid and then, depending on the AutoSize property of the exporter, auto-sizes the grid column to their contents. It will then export the grid to the PDF document at that size. If the grid fits on the standard page size, then that's fine. If the grid is too big, the exporter will increase the page width of the section so that the grid fits within one page horizontally.
It seems like in your case, the grid doesn't need the full width of a standard A4 page. So there is extra space. But I thought the extra space is always on the right and for some reason, the extra space here appears on the left. Is there an equal space on the right side of the page? If so, then maybe the grid is centered within the page and that would explain it.
In any case, there is no easy way to make the grid fit to the width of a page in the case where the grid doesn't need the entire width. Those calculations would be pretty tricky, but if you could determine the width you need, you could, in theory, increase the width of each column in the grid before exporting. The ExportedStarting or ExportStarted events would be a good place to do this, because you could change the widths of the columns in the export layout without affecting the on-screen grid.
Thank you Mike - Yes my grid is centered, hence the equal white spacing on right and left
I actually did exactly what you were suggesting - manually adjusted / expanded the widths of the columns and saw the DocumentExporter clone it and fit it into the PDF - but guess what, it still uses the same "canvas" width and keeps the same spacing on right and left - ideally my expectation would be just as what Excel does => recompute font size (float) to take the full available width of A4 page size
My guess is that the document exporter already has a canvas created for the grid layout, which programmatically, I cannot modify. There is no API in ExportArgs to do that - if you look at my image again, and see the page footer, notice how I am able to control the "new canvas" that I added for textual content of the footer - it spans right from the left edge of the page to the right - I just would like the grid layout to also do that
I also think I am missing something, if I can get an handle to the canvas object inside of which the grid layout is cloned/painted - I should be able to play with it a little, I just can find that how..
I'm not sure I follow you. What do you mean by "Canvas?" Our documents engine has a canvas object, but the WinGridDocumentExporter doesn't use it. It's for custom drawing.
The only thing that matters here is the size of the columns and bands in the export layout (which is passed in to the ExportStarting / ExportStarted events) and the PageSize on the section.
From what you write here, it sounds like you might be changing the column widths too early. Which event did you use? I think the exporter auto-sizes the columns after ExportStarting, but before ExportStarted. So you probably need to use ExportStarted - or turn off AutoSizing.
Hi Mike
In order to add any custom object to the PDF document - the only way that seemed to work for me was to do
e.Section.AddCanvas - which returns ICanvas object
I am able to set position, and dimensions on this ICanvas object (notice the footer in my image attached earlier)
This led me to believe that the grid layout inside of the PDF also has some kind of a container / canvas - which I cannot obtain the handle to
After your response, I tried setting the column width in either of the events but there is no change in the output
Just to go over my problem again
- the total width of the grid inside the PDF is much less than the total width offered by the A4 sized PDF in landscape mode
- the width of the columns changes as controlled in the code and it reflects in the PDF, but the total width of the grid inside of the PDF remains unchanged
..and hence the title of my post "How do I make the grid layout occupy entire whitespace available on exported PDF document"
Thanks, u help me...
Thanks Mike - I see what you mean - I can live with this, I now adjust the last column width, in a manner that it tries to fully occupy the width of the page
Okay... the UltraGridDocumentExporter does not use a Canvas. It adds a Tree to the section and populates the nodes of that tree with various objects like grids and tables in order to duplicate the structure of the on-screen grid. So that's cleared up. :)
Since your latest response says that sizing the columns doesn't have any effect, I looked at the source code for the exporter to determine exactly when the autosizing of the columns takes place. And it turns out that this happens BEFORE the ExportStarted event fires. So the Autosizing should not interfere with any changes you make inside either the ExportStarted event.
So, just to be extra sure, I tried it out. I am attaching my sample here so you can try it and see if you get the same results.
The sample has a simple grid with 3 columns. Click the Export button and the grid exports to PDF in landscape mode and the columns are pretty small. The entire grid takes up maybe 1/5th the width of the page.
Close the PDF document, click the checkbox, and click Export again and now the grid takes up most of the page because the columns are made larger.