Search code examples
silverlightprintingpdf-generationtabcontrolprintdocument

How to print all elements or generate PDF from TabControl?


I have a silverlight application which consists of a few tabs, which I would like to print or to generate PDF containing these tabs.
I tried to use StackPanel to add each tab and then use PrintDocument to print what I see, but there is a problem because there are too many tabs, so they don't fit in the size of A4 document.
And more, when I resize the browser to a smaller size, only the visible part of the content gets printed.

Is there a different method to print all the content in one document or PDF?


Solution

  • The PrintPageEventArgs in the PrintPage handler contains the size of the paper so you can calculate how much can be printed on a single page.

    Printing (a part of) the visual tree has its disadvantages; what looks good on screen might not be good for paper, especially if scrolling and sizing are involved.

    A solutions is to design one or multiple Views for printing and simply bind the same ViewModel to the PrintView. A bit like the special CSS for creating a print version of a web page.

    If the content doesn't fit you should use more pages.

    This article by Charles Petzold is worth reading too