WPF/Silverlight: Printing of Visuals - Drawbacks -


i read once or twice printing visuals wpf/silverlight has drawbacks people tend use flowdocument or fixeddocument printing.

i want print graphically intense dashboards , printing visual directly seems easiest way go. don't have care pagination since every dashboard want print supposed fit on 1 page.

are there still drawbacks must consider before choosing way of printing?

you can print visual objects hosting them in frameworkelement , adding frameworkelement fixeddocument content of fixedpage. visual host looks this:

/// <summary> /// implements frameworkelement host visual /// </summary> public class visualhost : frameworkelement {     visual _visual;       /// <summary>     /// gets number of visual children (always 1)     /// </summary>     protected override int visualchildrencount     {         { return 1; }     }       /// <summary>     /// constructor     /// </summary>     /// <param name="visual">the visual host</param>     public visualhost(visual visual)     {         _visual = visual;          addvisualchild(_visual);         addlogicalchild(_visual);     }       /// <summary>     /// specified visual child (always     /// </summary>     /// <param name="index">index of visual (should 0)</param>     /// <returns>the visual</returns>     protected override visual getvisualchild(int index)     {         if (index != 0)             throw new argumentoutofrangeexception("index out of range");         return _visual;     } } 

then can add them , print them this:

        // start fixed document         fixeddocument fixeddoc = new fixeddocument();         point margin = new point(96/2, 96/2);      // half inch margins          // add visuals         foreach (visual nextvisual in visualcollection)         {             // host visual             visualhost host = new visualhost(nextvisual);             canvas canvas = new canvas();             canvas.setleft(host, margin.x);             canvas.settop(host, margin.y);             canvas.children.add(host);              // make fixedpage out of canvas , add document             pagecontent pagecontent = new pagecontent();             fixedpage fixedpage = new fixedpage();             fixedpage.children.add(canvas);             ((system.windows.markup.iaddchild)pagecontent).addchild(fixedpage);             fixeddoc.pages.add(pagecontent);         }          // write finished fixeddocument print queue         xpsdocumentwriter xpsdocumentwriter = printqueue.createxpsdocumentwriter(queue);         xpsdocumentwriter.write(fixeddoc); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -