Question

I need to print very large and complicated object - virtualizet in two dimension matrix what have two tables at left and top side and at the middle represent the intersections of tables. Each table can have more than 5000 records. So i made a control for all this things. It's work pretty good. But customer wants to print it. When matrix too big for one page i should devide into peaces and print each part.

I can devide matrix by paper size and build flowdocument for each part. But it's smells with a lot of problems. Especially that's tables has custom count of the columns, so all of the columns cannot be placed at one document.

So, i hope that's exists any easiest way to implement this. (except print from excel)

Was it helpful?

Solution

The "easy" way to do this is to create a bitmap the size of your document, draw every control in your document to this bitmap with RenderTargetBitmap, divide the bitmap into tiles the width and height of your page rectangle, and draw each tile to the printer.

Don't do that.

You will soon find that what looks good on screen does not look good on paper; fonts are pixelated, gradients are dithered, text gets cut off, blank areas in your document cause text to be printed at crazy locations. WPF controls are only available from the UI thread, and drawing them a lot can cause your UI to block.

Instead; take advantage of printer features. You have three tables? Print each table separately. Instead of trying to draw your UI, create a DrawingVisual for each cell or graphic. Lay out each cell on the page, testing to see if it goes outside the margin. If it does, add it to a horizontal (if it goes off the right margin) or vertical (if it goes off the bottom margin) slop list. After you have drawn the first page, draw all the visuals on the horizontal slop. Keep doing that until the horizontal slop is empty, then do it all again with the vertical slop. Then again for the next table. DrawingVisuals don't need the UI thread so you can do this in the background.

DocumentPaginator may have support for this; I haven't tried it. Good luck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top